You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by am...@apache.org on 2006/12/01 12:05:07 UTC
svn commit: r481222 - in /xerces/c/trunk/src/xercesc/util:
XMLUCSTranscoder.cpp regx/RegxUtil.hpp
Author: amassari
Date: Fri Dec 1 03:05:03 2006
New Revision: 481222
URL: http://svn.apache.org/viewvc?view=rev&rev=481222
Log:
Use the algorithm from http://unicode.org/unicode/faq/utf_bom.html#35 to encode/decode surrogate pairs (bug#1654)
Modified:
xerces/c/trunk/src/xercesc/util/XMLUCSTranscoder.cpp
xerces/c/trunk/src/xercesc/util/regx/RegxUtil.hpp
Modified: xerces/c/trunk/src/xercesc/util/XMLUCSTranscoder.cpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/XMLUCSTranscoder.cpp?view=diff&rev=481222&r1=481221&r2=481222
==============================================================================
--- xerces/c/trunk/src/xercesc/util/XMLUCSTranscoder.cpp (original)
+++ xerces/c/trunk/src/xercesc/util/XMLUCSTranscoder.cpp Fri Dec 1 03:05:03 2006
@@ -108,8 +108,9 @@
if (outPtr + 1 == outEnd)
break;
- const XMLCh ch1 = XMLCh(((nextVal - 0x10000) >> 10) + 0xD800);
- const XMLCh ch2 = XMLCh(((nextVal - 0x10000) & 0x3FF) + 0xDC00);
+ const XMLInt32 LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
+ const XMLCh ch1 = XMLCh(LEAD_OFFSET + (nextVal >> 10));
+ const XMLCh ch2 = XMLCh(0xDC00 + (nextVal & 0x3FF));
//
// We have room so store them both. But note that the
@@ -211,8 +212,8 @@
ThrowXMLwithMemMgr(TranscodingException, XMLExcepts::Trans_BadTrailingSurrogate, getMemoryManager());
// And now combine the two into a single output char
- *outPtr++ = ((curCh - 0xD800) << 10)
- + (trailCh - 0xDC00) + 0x10000;
+ const XMLInt32 SURROGATE_OFFSET = 0x10000 - (0xD800 << 10) - 0xDC00;
+ *outPtr++ = (curCh << 10) + trailCh + SURROGATE_OFFSET;
}
else
{
Modified: xerces/c/trunk/src/xercesc/util/regx/RegxUtil.hpp
URL: http://svn.apache.org/viewvc/xerces/c/trunk/src/xercesc/util/regx/RegxUtil.hpp?view=diff&rev=481222&r1=481221&r2=481222
==============================================================================
--- xerces/c/trunk/src/xercesc/util/regx/RegxUtil.hpp (original)
+++ xerces/c/trunk/src/xercesc/util/regx/RegxUtil.hpp Fri Dec 1 03:05:03 2006
@@ -67,8 +67,9 @@
}
inline XMLInt32 RegxUtil::composeFromSurrogate(const XMLCh high, const XMLCh low) {
-
- return 0x10000 + ((high - 0xD800) << 10) + (low - 0xDC00);
+ // see http://unicode.org/unicode/faq/utf_bom.html#35
+ const XMLInt32 SURROGATE_OFFSET = 0x10000 - (0xD800 << 10) - 0xDC00;
+ return (high << 10) + low + SURROGATE_OFFSET;
}
inline bool RegxUtil::isLowSurrogate(const XMLCh ch) {
@@ -82,10 +83,10 @@
}
inline void RegxUtil::decomposeToSurrogates(XMLInt32 ch, XMLCh& high, XMLCh& low) {
-
- ch -= 0x10000;
- high = XMLCh((ch >> 10) + 0xD800);
- low = XMLCh((ch & 0x03FF) + 0xDC00);
+ // see http://unicode.org/unicode/faq/utf_bom.html#35
+ const XMLInt32 LEAD_OFFSET = 0xD800 - (0x10000 >> 10);
+ high = XMLCh(LEAD_OFFSET + (ch >> 10));
+ low = XMLCh(0xDC00 + (ch & 0x3FF));
}
inline bool RegxUtil::isWordChar(const XMLCh ch) {
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xerces.apache.org
For additional commands, e-mail: commits-help@xerces.apache.org