projects/aports·blob master · refs

38 lines · 1.2 KiB

1Patch from 'Spoon' to fix issues with writing certain unicode characters
2--- a/ChangeLog
3+++ b/ChangeLog
4@@ -1,3 +1,8 @@
5+2006-02-17 Jerome Couderc
6+
7+ * Patch from Spoon to fix UTF-16 writing bug
8+ http://sourceforge.net/tracker/index.php?func=detail&aid=1016290&group_id=979&atid=300979
9+
10 2003-03-02 Sunday 17:38 Thijmen Klok <[email protected]>
11
12 * THANKS (1.20): added more people
13--- a/src/io_helpers.cpp
14+++ b/src/io_helpers.cpp
15@@ -363,11 +363,22 @@
16 // Write the BOM: 0xFEFF
17 unicode_t BOM = 0xFEFF;
18 writer.writeChars((const unsigned char*) &BOM, 2);
19+ // Patch from Spoon : 2004-08-25 14:17
20+ // http://sourceforge.net/tracker/index.php?func=detail&aid=1016290&group_id=979&atid=300979
21+ // Wrong code
22+ //for (size_t i = 0; i < size; i += 2)
23+ //{
24+ // unicode_t ch = (data[i] << 8) | data[i+1];
25+ // writer.writeChars((const unsigned char*) &ch, 2);
26+ //}
27+ // Right code
28+ unsigned char *pdata = (unsigned char *) data.c_str();
29 for (size_t i = 0; i < size; i += 2)
30 {
31- unicode_t ch = (data[i] << 8) | data[i+1];
32+ unicode_t ch = (pdata[i] << 8) | pdata[i+1];
33 writer.writeChars((const unsigned char*) &ch, 2);
34 }
35+ // End patch
36 }
37 return writer.getCur() - beg;
38 }