# HG changeset patch # User Chris Cannam # Date 1307440768 -3600 # Node ID 4f5414a7edb4432755e414d78cbbf1f07c5c4195 # Parent 69fb864a39724e0e582979dd758f437c76b01847 Handle escaped backslash (\\u) for cases where Unicode escape is not intended diff -r 69fb864a3972 -r 4f5414a7edb4 src/common.cpp --- a/src/common.cpp Mon Jun 06 21:33:25 2011 +0100 +++ b/src/common.cpp Tue Jun 07 10:59:28 2011 +0100 @@ -262,14 +262,24 @@ { QString d; for (int i = 0; i < s.length(); ++i) { + // backslash-u escaped with another backslash: replace with a + // single backslash and skip on + if (i+2 < s.length() && s[i] == '\\' && s[i+1] == '\\' && s[i+2] == 'u') { + d += "\\u"; + i += 2; + continue; + } + // unescaped backslash followed by u and at least four more + // chars: replace with Unicode character if (i+5 < s.length() && s[i] == '\\' && s[i+1] == 'u') { QString uni = s.mid(i+2, 4); QByteArray ba = QByteArray::fromHex(uni.toAscii()); d += QChar(ba[1], ba[0]); i += 5; - } else { - d += s[i]; + continue; } + // default case: leave alone + d += s[i]; } return d; }