Mercurial > hg > easyhg
comparison src/common.cpp @ 410:4f5414a7edb4
Handle escaped backslash (\\u) for cases where Unicode escape is not intended
author | Chris Cannam |
---|---|
date | Tue, 07 Jun 2011 10:59:28 +0100 |
parents | 005633eed862 |
children | d0ebd797c5a1 |
comparison
equal
deleted
inserted
replaced
409:69fb864a3972 | 410:4f5414a7edb4 |
---|---|
260 | 260 |
261 QString uniDecode(QString s) | 261 QString uniDecode(QString s) |
262 { | 262 { |
263 QString d; | 263 QString d; |
264 for (int i = 0; i < s.length(); ++i) { | 264 for (int i = 0; i < s.length(); ++i) { |
265 // backslash-u escaped with another backslash: replace with a | |
266 // single backslash and skip on | |
267 if (i+2 < s.length() && s[i] == '\\' && s[i+1] == '\\' && s[i+2] == 'u') { | |
268 d += "\\u"; | |
269 i += 2; | |
270 continue; | |
271 } | |
272 // unescaped backslash followed by u and at least four more | |
273 // chars: replace with Unicode character | |
265 if (i+5 < s.length() && s[i] == '\\' && s[i+1] == 'u') { | 274 if (i+5 < s.length() && s[i] == '\\' && s[i+1] == 'u') { |
266 QString uni = s.mid(i+2, 4); | 275 QString uni = s.mid(i+2, 4); |
267 QByteArray ba = QByteArray::fromHex(uni.toAscii()); | 276 QByteArray ba = QByteArray::fromHex(uni.toAscii()); |
268 d += QChar(ba[1], ba[0]); | 277 d += QChar(ba[1], ba[0]); |
269 i += 5; | 278 i += 5; |
270 } else { | 279 continue; |
271 d += s[i]; | 280 } |
272 } | 281 // default case: leave alone |
282 d += s[i]; | |
273 } | 283 } |
274 return d; | 284 return d; |
275 } | 285 } |