version 1.6.4.5, 2009/10/23 13:25:07
|
version 1.9, 2011/08/08 13:29:00
|
|
|
}; | }; |
| |
// If _isSpecialChar7[ch] is true, then ch is a special character, which must | // If _isSpecialChar7[ch] is true, then ch is a special character, which must |
// have a special encoding in XML. But only use 7-bit ASCII characters to |
// have a special encoding in XML. |
// index this array. |
// Remaining 128 values are automatically initialised to 0 by compiler. |
static const int _isSpecialChar7[] = |
static const int _isSpecialChar7[256] = |
{ | { |
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0, | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,1,0,0, |
0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0, | 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0, |
|
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1, |
}; | }; |
| |
|
// If _isSpecialChar7[ch] is true, then ch is a special character, which must |
|
// have a special encoding in XML. |
|
static const int _isNormalChar7[] = |
|
{ |
|
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1, |
|
1,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,1,0,1,1,1,1,1,1,1,1,1,1,1, |
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0, |
|
// remaining 128 values are used on multi-byte UTF-8 and should not be escaped |
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, |
|
1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1 |
|
}; |
|
|
|
|
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
| |
Buffer& operator<<(Buffer& out, const Char16& x) | Buffer& operator<<(Buffer& out, const Char16& x) |
|
|
} | } |
} | } |
| |
|
// str has to be UTF-8 encoded |
|
// that means the characters used cannot be larger than 7bit ASCII in value |
|
// range |
void XmlGenerator::appendSpecial(Buffer& out, const char* str, Uint32 size) | void XmlGenerator::appendSpecial(Buffer& out, const char* str, Uint32 size) |
{ | { |
// employ loop unrolling and a less checking optimized Buffer access | // employ loop unrolling and a less checking optimized Buffer access |
|
|
out.reserveCapacity(out.capacity() + newMaxSize); | out.reserveCapacity(out.capacity() + newMaxSize); |
} | } |
| |
|
// Before using a loop unrolled algorithm to pick out the special chars |
|
// we are going to assume there is no special char as this is the case most |
|
// of the time anyway |
|
Uint32 sizeStart=size; |
|
const Uint8* p= (const Uint8*) str; |
|
|
|
while (size >= 4 && |
|
(_isNormalChar7[p[0]] & |
|
_isNormalChar7[p[1]] & |
|
_isNormalChar7[p[2]] & |
|
_isNormalChar7[p[3]])) |
|
{ |
|
size -= 4; |
|
p += 4; |
|
} |
|
out.append_unchecked(str,sizeStart-size); |
|
str=(const char*)p; |
|
|
while (size>=8) | while (size>=8) |
{ | { |
register int c; |
register Uint8 c; |
c = str[0]; | c = str[0]; |
if (_isSpecialChar7[c]) | if (_isSpecialChar7[c]) |
{ | { |
|
|
| |
while (size>=4) | while (size>=4) |
{ | { |
register int c; |
register Uint8 c; |
c = str[0]; | c = str[0]; |
if (_isSpecialChar7[c]) | if (_isSpecialChar7[c]) |
{ | { |
|
|
| |
while (size--) | while (size--) |
{ | { |
register int c; |
register Uint8 c; |
c=*str; | c=*str; |
if (_isSpecialChar7[c]) | if (_isSpecialChar7[c]) |
{ | { |