From: Joe Neeman Date: Sun, 25 Nov 2007 01:50:25 +0000 (+1100) Subject: Fix the fix of 499. X-Git-Tag: release/2.11.36-1~65^2~6 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=e296eda26bad5f2d30c762b3426550186a9cf98b;p=lilypond.git Fix the fix of 499. Make the whitespace-replacing function utf8-aware. --- diff --git a/lily/text-interface.cc b/lily/text-interface.cc index 96444e10ab..4b2f6c4445 100644 --- a/lily/text-interface.cc +++ b/lily/text-interface.cc @@ -22,9 +22,27 @@ 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);