]> git.donarmstrong.com Git - lilypond.git/commitdiff
Fix the fix of 499.
authorJoe Neeman <joeneeman@gmail.com>
Sun, 25 Nov 2007 01:50:25 +0000 (12:50 +1100)
committerJoe Neeman <joeneeman@gmail.com>
Mon, 26 Nov 2007 23:22:55 +0000 (10:22 +1100)
Make the whitespace-replacing function utf8-aware.

lily/text-interface.cc

index 96444e10ab6537319b2471009988fe0eb57998a4..4b2f6c444539ddd8fbfe79173ccdbb4500d84f80 100644 (file)
 static void
 replace_whitespace (string *str)
 {
-  for (vsize i = 0; i < str->size (); i++)
-    if (isspace ((*str)[i]))
-      (*str)[i] = ' ';
+  vsize i = 0;
+  vsize n = str->size ();
+
+  while (i < n)
+    {
+      vsize char_len = 1;
+      char cur = (*str)[i];
+      
+      if ((cur & 0x11100000) == 0x11100000)
+       char_len = 3;
+      else if ((cur & 0x11000000) == 0x11000000)
+       char_len = 2;
+      else if (cur & 0x10000000)
+       programming_error ("invalid utf-8 string");
+
+      /* avoid the locale-dependent isspace */
+      if (cur == '\n' || cur == '\t' || cur == '\v')
+       (*str)[i] = ' ';
+
+      i += char_len;
+    }
 }
 
 MAKE_SCHEME_CALLBACK (Text_interface, interpret_string, 3);