+#include "output-def.hh"
+#include "pango-font.hh"
+#include "program-option.hh"
+#include "international.hh"
+#include "warn.hh"
+#include "lily-imports.hh"
+
+static void
+replace_special_characters (string &str, SCM props)
+{
+ SCM replacement_alist = ly_chain_assoc_get (ly_symbol2scm ("replacement-alist"),
+ props,
+ SCM_EOL);
+
+ int max_length = 0;
+ for (SCM s = replacement_alist; scm_is_pair (s); s = scm_cdr (s))
+ {
+ max_length = max (max_length, scm_to_int
+ (scm_string_length (scm_caar (s))));
+ }
+
+ for (vsize i = 0; i < str.size (); i++)
+ {
+ /* Don't match in mid-UTF-8 */
+ if ((str[i] & 0xc0) == 0x80)
+ continue;
+ for (vsize j = max_length + 1; j--;)
+ {
+ if (j > str.size () - i)
+ continue;
+ string dummy = str.substr (i, j);
+ SCM ligature = ly_assoc_get (ly_string2scm (dummy),
+ replacement_alist, SCM_BOOL_F);
+ if (scm_is_true (ligature))
+ str.replace (i, j, robust_scm2string (ligature, ""));
+ }
+ }
+}