NVDA with Japanese branch
Revision | 430b7ee1f2637a28ce1891f52d7a9aa49a150079 (tree) |
---|---|
Zeit | 2009-10-07 13:24:15 |
Autor | James Teh <jamie@jant...> |
Commiter | James Teh |
NVDAHelper: VBufBase storage: When generating XML attribute values, replace invalid XML characters so that we don't end up with invalid XML. We already did this for text. Also, unify the code that normalises XML characters for both text nodes and attribute values.
@@ -20,6 +20,33 @@ | ||
20 | 20 | |
21 | 21 | using namespace std; |
22 | 22 | |
23 | +inline void appendCharToXML(const wchar_t c, wstring& xml) { | |
24 | + switch(c) { | |
25 | + case L'"': | |
26 | + xml+=L"""; | |
27 | + break; | |
28 | + case L'<': | |
29 | + xml+=L"<"; | |
30 | + break; | |
31 | + case L'>': | |
32 | + xml+=L">"; | |
33 | + break; | |
34 | + case L'&': | |
35 | + xml+=L"&"; | |
36 | + break; | |
37 | + default: | |
38 | + if (c == 0x9 || c == 0xA || c == 0xD | |
39 | + || (c >= 0x20 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFD) | |
40 | + ) { | |
41 | + // Valid XML character. | |
42 | + xml+=c; | |
43 | + } else { | |
44 | + // Invalid XML character. | |
45 | + xml += 0xfffd; // Unicode replacement character | |
46 | + } | |
47 | + } | |
48 | +} | |
49 | + | |
23 | 50 | VBufStorage_textContainer_t::VBufStorage_textContainer_t(wstring str): wstring(str) {} |
24 | 51 | |
25 | 52 | VBufStorage_textContainer_t::~VBufStorage_textContainer_t() {} |
@@ -215,22 +242,7 @@ void VBufStorage_fieldNode_t::generateAttributesForMarkupOpeningTag(std::wstring | ||
215 | 242 | text+=i->first; |
216 | 243 | text+=L"=\""; |
217 | 244 | for(std::wstring::iterator j=i->second.begin();j!=i->second.end();j++) { |
218 | - switch(*j) { | |
219 | - case L'"': | |
220 | - text+=L"""; | |
221 | - break; | |
222 | - case L'<': | |
223 | - text+=L"<"; | |
224 | - break; | |
225 | - case L'>': | |
226 | - text+=L">"; | |
227 | - break; | |
228 | - case L'&': | |
229 | - text+=L"&"; | |
230 | - break; | |
231 | - default: | |
232 | - text+=*j; | |
233 | - } | |
245 | + appendCharToXML(*j,text); | |
234 | 246 | } |
235 | 247 | text+=L"\" "; |
236 | 248 | } |
@@ -414,30 +426,7 @@ void VBufStorage_textFieldNode_t::getTextInRange(int startOffset, int endOffset, | ||
414 | 426 | wchar_t c; |
415 | 427 | for(int offset=startOffset;offset<endOffset;offset++) { |
416 | 428 | c=this->text[offset]; |
417 | - switch(c) { | |
418 | - case L'"': | |
419 | - text+=L"""; | |
420 | - break; | |
421 | - case L'<': | |
422 | - text+=L"<"; | |
423 | - break; | |
424 | - case L'>': | |
425 | - text+=L">"; | |
426 | - break; | |
427 | - case L'&': | |
428 | - text+=L"&"; | |
429 | - break; | |
430 | - default: | |
431 | - if (c == 0x9 || c == 0xA || c == 0xD | |
432 | - || (c >= 0x20 && c <= 0xD7FF) || (c >= 0xE000 && c <= 0xFFFD) | |
433 | - ) { | |
434 | - // Valid XML character. | |
435 | - text+=c; | |
436 | - } else { | |
437 | - // Invalid XML character. | |
438 | - text += 0xfffd; // Unicode replacement character | |
439 | - } | |
440 | - } | |
429 | + appendCharToXML(c,text); | |
441 | 430 | } |
442 | 431 | } else { |
443 | 432 | text.append(this->text,startOffset,endOffset-startOffset); |