From e296eda26bad5f2d30c762b3426550186a9cf98b Mon Sep 17 00:00:00 2001 From: Joe Neeman Date: Sun, 25 Nov 2007 12:50:25 +1100 Subject: [PATCH] Fix the fix of 499. Make the whitespace-replacing function utf8-aware. --- lily/text-interface.cc | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) 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); -- 2.39.5