inline void doXercesTranscode( const SourceType* theSourceString, XalanDOMString::size_type theSourceStringLength, bool theSourceStringIsNullTerminated, XalanVector<TargetType>& theTargetVector, bool terminate, char theSubstitutionChar) { assert( theSourceStringIsNullTerminated == false || theSourceStringLength == XalanDOMString::length(theSourceString)); const SourceType* theRealSourceString = theSourceString; XalanVector<SourceType> theCopiedSource(theTargetVector.getMemoryManager()); if (theSourceStringIsNullTerminated == false) { theCopiedSource.reserve(theSourceStringLength + 1); theCopiedSource.assign( theSourceString, theSourceString + theSourceStringLength); theCopiedSource.push_back(static_cast<SourceType>(0)); theRealSourceString = &*theCopiedSource.begin(); } // Initially, let's guess the the transcoded string will be the same // length as the source string. theTargetVector.resize(theSourceStringLength + 1); assert(theRealSourceString != 0); bool fSuccess = false; XALAN_USING_XERCES(XMLString) fSuccess = XMLString::transcode( theRealSourceString, &*theTargetVector.begin(), theTargetVector.size() - 1, &theTargetVector.getMemoryManager()); if (fSuccess == false) { // Do the "manual" transcoding. But first, clean up from the // previous phase theTargetVector.clear(); // See if there are any unrepresentable characters for the // local code page. SourceType oneCharArray[2]; oneCharArray[1] = SourceType(0); TargetType theOneTranslatedWbChar[theOneTranslatedWbCharLen]; for (XalanDOMString::size_type i = 0; i < theSourceStringLength; ++i) { oneCharArray[0] = theRealSourceString[i]; theOneTranslatedWbChar[0] = TargetType(0); fSuccess = XMLString::transcode( oneCharArray, theOneTranslatedWbChar, theOneTranslatedWbCharLen - 1, &theTargetVector.getMemoryManager()); if (fSuccess == false) { theTargetVector.push_back(theSubstitutionChar); } else { XalanDOMString::size_type theRealCharLength = XalanDOMString::length(theOneTranslatedWbChar); // When we transcode the character '\0', that looks like "\0\0", // XalanDOMString::length returns a size of 0. In this case, the // real size should be 1 if (theRealCharLength == 0) { theRealCharLength = 1; } // append the translated set of characters theTargetVector.insert( theTargetVector.end(), theOneTranslatedWbChar, theOneTranslatedWbChar + theRealCharLength); } } } while(theTargetVector.back() == static_cast<TargetType>(0)) { theTargetVector.pop_back(); } if (terminate == true) { theTargetVector.push_back(static_cast<TargetType>(0)); } }
inline bool doXercesTranscode( const SourceType* theSourceString, XalanDOMString::size_type theSourceStringLength, bool theSourceStringIsNullTerminated, XalanVector<TargetType>& theTargetVector, bool terminate) { assert( theSourceStringIsNullTerminated == false || theSourceStringLength == XalanDOMString::length(theSourceString)); const SourceType* theRealSourceString = theSourceString; XalanVector<SourceType> theCopiedSource(theTargetVector.getMemoryManager()); if (theSourceStringIsNullTerminated == false) { theCopiedSource.reserve(theSourceStringLength + 1); theCopiedSource.assign( theSourceString, theSourceString + theSourceStringLength); theCopiedSource.push_back(static_cast<SourceType>(0)); theRealSourceString = &*theCopiedSource.begin(); } // Initially, let's guess the the transcoded string will be the same // length as the source string. theTargetVector.resize(theSourceStringLength + 1); assert(theRealSourceString != 0); bool fSuccess = false; do { XALAN_USING_XERCES(XMLString) fSuccess = XMLString::transcode( theRealSourceString, &*theTargetVector.begin(), theTargetVector.size() - 1, &theTargetVector.getMemoryManager()); if (fSuccess == false) { // We're going to assume that the maximum storage for // a transcoded string is 4 times the source string // length. This will only occur in edge cases. if (theTargetVector.size() >= theSourceStringLength * 4) { break; } else { theTargetVector.resize(theTargetVector.size() + 10); } } } while (fSuccess == false); if (fSuccess == false) { theTargetVector.clear(); } else { while(theTargetVector.back() == static_cast<TargetType>(0)) { theTargetVector.pop_back(); } if (terminate == true) { theTargetVector.push_back(static_cast<TargetType>(0)); } } return fSuccess; }
void f(void) { XalanVector tempVector; tempVector.push_back(); }