00001 /* 00002 * Copyright 1999-2004 The Apache Software Foundation. 00003 * 00004 * Licensed under the Apache License, Version 2.0 (the "License"); 00005 * you may not use this file except in compliance with the License. 00006 * You may obtain a copy of the License at 00007 * 00008 * http://www.apache.org/licenses/LICENSE-2.0 00009 * 00010 * Unless required by applicable law or agreed to in writing, software 00011 * distributed under the License is distributed on an "AS IS" BASIS, 00012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00013 * See the License for the specific language governing permissions and 00014 * limitations under the License. 00015 */ 00016 #if !defined(DOMSTRINGHELPER_HEADER_GUARD_1357924680) 00017 #define DOMSTRINGHELPER_HEADER_GUARD_1357924680 00018 00019 00020 00021 // Base include file. Must be first. 00022 #include <xalanc/PlatformSupport/PlatformSupportDefinitions.hpp> 00023 00024 00025 00026 #include <algorithm> 00027 #include <cassert> 00028 #include <functional> 00029 #if defined(XALAN_CLASSIC_IOSTREAMS) 00030 class ostream; 00031 #else 00032 #include <iosfwd> 00033 #endif 00034 00035 00036 00037 #include <xalanc/Include/XalanVector.hpp> 00038 #include <xalanc/Include/XalanMap.hpp> 00039 #include <xalanc/Include/STLHelper.hpp> 00040 00041 00042 00043 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00044 00045 00046 00047 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00048 #include <xalanc/PlatformSupport/XalanUnicode.hpp> 00049 #include <xalanc/PlatformSupport/XalanXMLChar.hpp> 00050 00051 00052 00053 XALAN_CPP_NAMESPACE_BEGIN 00054 00055 00056 00057 class XalanOutputStream; 00058 00059 00060 00061 // This macro has been defined to deal with certain C++ compilers which 00062 // do not create Unicode strings when the "L" string constant prefix is 00063 // used. It is meant _only_ for use with static strings. 00064 #if defined(XALAN_LSTRSUPPORT) && !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH) 00065 00066 #define XALAN_STATIC_UCODE_STRING(str) L##str 00067 00068 #if !defined (XALAN_DEVELOPMENT) 00069 inline const XalanDOMString 00070 StaticStringToDOMString(const XalanDOMChar* theString) 00071 { 00072 return XalanDOMString(theString); 00073 } 00074 #endif 00075 00076 #else 00077 00078 #define XALAN_STATIC_UCODE_STRING(str) str 00079 00080 #if !defined (XALAN_DEVELOPMENT) 00081 inline const XalanDOMString& 00082 StaticStringToDOMString(const XalanDOMString& theString) 00083 { 00084 return theString; 00085 } 00086 #endif 00087 00088 #endif 00089 00090 00091 00092 #if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS) 00093 00094 template<class InputIteratorType, class OutputIteratorType> 00095 inline OutputIteratorType 00096 XalanCopy( 00097 InputIteratorType begin, 00098 InputIteratorType end, 00099 OutputIteratorType iterator) 00100 { 00101 for(; begin != end; ++iterator, ++begin) 00102 { 00103 *iterator = *begin; 00104 } 00105 00106 return iterator; 00107 } 00108 00109 00110 00111 template<class InputIteratorType, class OutputIteratorType, class UnaryFunction> 00112 inline OutputIteratorType 00113 XalanTransform( 00114 InputIteratorType begin, 00115 InputIteratorType end, 00116 OutputIteratorType iterator, 00117 UnaryFunction function) 00118 { 00119 for(; begin != end; ++iterator, ++begin) 00120 { 00121 *iterator = function(*begin); 00122 } 00123 00124 return iterator; 00125 } 00126 00127 #else 00128 00129 template<class InputIteratorType, class OutputIteratorType> 00130 inline OutputIteratorType 00131 XalanCopy( 00132 InputIteratorType begin, 00133 InputIteratorType end, 00134 OutputIteratorType iterator) 00135 { 00136 return XALAN_STD_QUALIFIER copy(begin, end, iterator); 00137 } 00138 00139 00140 00141 template<class InputIteratorType, class OutputIteratorType, class UnaryFunction> 00142 inline OutputIteratorType 00143 XalanTransform( 00144 InputIteratorType begin, 00145 InputIteratorType end, 00146 OutputIteratorType iterator, 00147 UnaryFunction function) 00148 { 00149 return XALAN_STD_QUALIFIER transform(begin, end, iterator); 00150 } 00151 00152 #endif 00153 00154 00155 00163 inline const XalanDOMChar* 00164 c_wstr(const XalanDOMString& theString) 00165 { 00166 return theString.c_str(); 00167 } 00168 00169 00170 00178 inline const char* 00179 c_str(const CharVectorType& theString) 00180 { 00181 if (theString.empty() == true) 00182 { 00183 return 0; 00184 } 00185 else 00186 { 00187 const char* const ptr = &theString[0]; 00188 00189 assert(ptr[theString.size() - 1] == '\0'); 00190 00191 return ptr; 00192 } 00193 } 00194 00195 00196 00212 inline const XalanDOMChar* 00213 c_wstr(const XalanDOMChar* theString) 00214 { 00215 return theString; 00216 } 00217 00218 00219 00227 inline const XalanDOMChar* 00228 toCharArray(const XalanDOMString& theString) 00229 { 00230 return theString.c_str(); 00231 } 00232 00233 00234 00241 inline const XalanDOMChar* 00242 toCharArray(const XalanDOMChar* theString) 00243 { 00244 return theString; 00245 } 00246 00247 00248 00256 inline const char* 00257 toCharArray(const CharVectorType& theString) 00258 { 00259 return theString.empty() == true ? 0 : &theString[0]; 00260 } 00261 00262 00263 00271 inline void 00272 reserve( 00273 XalanDOMString& theString, 00274 XalanDOMString::size_type theCount) 00275 { 00276 theString.reserve(theCount); 00277 } 00278 00279 00280 00287 inline XalanDOMString::size_type 00288 length(const XalanDOMString& theString) 00289 { 00290 return theString.length(); 00291 } 00292 00293 00294 00302 inline XalanDOMString::size_type 00303 length(const XalanDOMChar* theString) 00304 { 00305 assert(theString != 0); 00306 00307 const XalanDOMChar* theBufferPointer = theString; 00308 00309 while(*theBufferPointer != 0) 00310 { 00311 theBufferPointer++; 00312 } 00313 00314 return XalanDOMString::size_type(theBufferPointer - theString); 00315 } 00316 00317 00318 00325 inline XalanDOMString::size_type 00326 length(const char* theString) 00327 { 00328 assert(theString != 0); 00329 00330 return XalanDOMString::length(theString); 00331 } 00332 00333 00334 00341 inline bool 00342 isEmpty(const XalanDOMString& str) 00343 { 00344 return str.empty(); 00345 } 00346 00347 00348 00358 inline XalanDOMString::size_type 00359 indexOf( 00360 const XalanDOMChar* theString, 00361 XalanDOMChar theChar) 00362 { 00363 assert(theString != 0); 00364 00365 const XalanDOMChar* thePointer = theString; 00366 00367 while(*thePointer != theChar && *thePointer != 0) 00368 { 00369 ++thePointer; 00370 } 00371 00372 return XalanDOMString::size_type(thePointer - theString); 00373 } 00374 00375 00376 00387 inline XalanDOMString::size_type 00388 indexOf( 00389 const XalanDOMChar* theString, 00390 XalanDOMString::size_type theStringLength, 00391 XalanDOMChar theChar) 00392 { 00393 assert(theString != 0); 00394 00395 const XalanDOMChar* thePointer = theString; 00396 const XalanDOMChar* const theEndPointer = theString + theStringLength; 00397 00398 while(*thePointer != theChar && thePointer != theEndPointer) 00399 { 00400 ++thePointer; 00401 } 00402 00403 return XalanDOMString::size_type(thePointer - theString); 00404 } 00405 00406 00407 00417 inline XalanDOMString::size_type 00418 indexOf( 00419 const XalanDOMString& theString, 00420 XalanDOMChar theChar) 00421 { 00422 return length(theString) == 0 ? 0 : indexOf(c_wstr(theString), theChar); 00423 } 00424 00425 00426 00438 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00439 indexOf( 00440 const XalanDOMChar* theString, 00441 XalanDOMString::size_type theStringLength, 00442 const XalanDOMChar* theSubstring, 00443 XalanDOMString::size_type theSubstringLength); 00444 00445 00446 00456 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00457 indexOf( 00458 const XalanDOMChar* theString, 00459 const XalanDOMChar* theSubstring); 00460 00461 00462 00472 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00473 indexOf( 00474 const XalanDOMString& theString, 00475 const XalanDOMString& theSubstring); 00476 00477 00478 00489 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00490 lastIndexOf( 00491 const XalanDOMChar* theString, 00492 XalanDOMChar theChar); 00493 00494 00495 00505 inline XalanDOMString::size_type 00506 lastIndexOf( 00507 const XalanDOMString& theString, 00508 XalanDOMChar theChar) 00509 { 00510 return lastIndexOf(c_wstr(theString), theChar); 00511 } 00512 00513 00514 00524 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 00525 startsWith( 00526 const XalanDOMChar* theString, 00527 XalanDOMString::size_type theStringLength, 00528 const XalanDOMChar* theSubstring, 00529 XalanDOMString::size_type theSubstringLength); 00530 00531 00532 00540 inline bool 00541 startsWith( 00542 const XalanDOMChar* theString, 00543 const XalanDOMChar* theSubstring) 00544 { 00545 assert(theString != 0 && theSubstring != 0); 00546 00547 return startsWith(theString, length(theString), theSubstring, length(theSubstring)); 00548 } 00549 00550 00551 00559 inline bool 00560 startsWith( 00561 const XalanDOMChar* theString, 00562 const XalanDOMString& theSubstring) 00563 { 00564 assert(theString != 0); 00565 00566 return startsWith(theString, length(theString), c_wstr(theSubstring), length(theSubstring)); 00567 } 00568 00569 00570 00578 inline bool 00579 startsWith( 00580 const XalanDOMString& theString, 00581 const XalanDOMChar* theSubstring) 00582 { 00583 assert(theSubstring != 0); 00584 00585 return startsWith(c_wstr(theString), length(theString), theSubstring, length(theSubstring)); 00586 } 00587 00588 00589 00598 inline bool 00599 startsWith( 00600 const XalanDOMString& theString, 00601 const XalanDOMChar* theSubstring, 00602 XalanDOMString::size_type theSubstringLength) 00603 { 00604 assert(theSubstring != 0); 00605 00606 return startsWith(c_wstr(theString), length(theString), theSubstring, theSubstringLength); 00607 } 00608 00609 00610 00618 inline bool 00619 startsWith( 00620 const XalanDOMString& theString, 00621 const XalanDOMString& theSubstring) 00622 { 00623 return startsWith(c_wstr(theString), length(theString), c_wstr(theSubstring), length(theSubstring)); 00624 } 00625 00626 00627 00628 00629 00630 00631 00639 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 00640 endsWith( 00641 const XalanDOMChar* theString, 00642 XalanDOMString::size_type theStringLength, 00643 const XalanDOMChar* theSubstring, 00644 XalanDOMString::size_type theSubstringLength); 00645 00646 00647 00655 inline bool 00656 endsWith( 00657 const XalanDOMChar* theString, 00658 const XalanDOMChar* theSubstring) 00659 { 00660 assert(theString != 0 && theSubstring != 0); 00661 00662 return endsWith(theString, length(theString), theSubstring, length(theSubstring)); 00663 } 00664 00665 00666 00674 inline bool 00675 endsWith( 00676 const XalanDOMString& theString, 00677 const XalanDOMString& theSubstring) 00678 { 00679 return endsWith(c_wstr(theString), length(theString), c_wstr(theSubstring), length(theSubstring)); 00680 } 00681 00682 00683 00691 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00692 PointerToDOMString( 00693 const void* theValue, 00694 XalanDOMString& theResult); 00695 00696 00697 00698 00699 00707 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00708 DoubleToDOMString( 00709 double theValue, 00710 XalanDOMString& theResult); 00711 00712 00713 00714 00715 class XALAN_PLATFORMSUPPORT_EXPORT DOMStringHelper 00716 { 00717 public: 00718 00719 typedef void (FormatterListener::*MemberFunctionPtr)(const XMLCh* const, const unsigned int); 00720 00721 static void 00722 DoubleToCharacters( 00723 double theDouble, 00724 FormatterListener& formatterListener, 00725 MemberFunctionPtr function); 00726 00727 static void 00728 LongToCharacters( 00729 long theLong, 00730 FormatterListener& formatterListener, 00731 MemberFunctionPtr function); 00732 }; 00733 00734 00735 00744 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00745 LongToHexDOMString( 00746 long theValue, 00747 XalanDOMString& theResult); 00748 00749 00750 00751 00752 00753 00762 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00763 UnsignedLongToHexDOMString( 00764 unsigned long theValue, 00765 XalanDOMString& theResult); 00766 00767 00768 00776 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00777 LongToDOMString( 00778 long theValue, 00779 XalanDOMString& theResult); 00780 00781 00782 00783 00792 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00793 UnsignedLongToDOMString( 00794 unsigned long theValue, 00795 XalanDOMString& theResult); 00796 00797 00798 00799 00800 00807 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 00808 WideStringToInt(const XalanDOMChar* theString); 00809 00810 00811 00818 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(long) 00819 WideStringToLong(const XalanDOMChar* theString); 00820 00821 00822 00829 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(unsigned long) 00830 WideStringToUnsignedLong(const XalanDOMChar* theString); 00831 00832 00833 00840 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(double) 00841 WideStringToDouble(const XalanDOMChar* theString, MemoryManagerType& theManager); 00842 00843 00844 00851 inline int 00852 DOMStringToInt(const XalanDOMString& theString) 00853 { 00854 return WideStringToInt(c_wstr(theString)); 00855 } 00856 00857 00858 00865 inline long 00866 DOMStringToLong(const XalanDOMString& theString) 00867 { 00868 return WideStringToLong(c_wstr(theString)); 00869 } 00870 00871 00872 00879 inline unsigned long 00880 DOMStringToUnsignedLong(const XalanDOMString& theString) 00881 { 00882 return WideStringToUnsignedLong(c_wstr(theString)); 00883 } 00884 00885 00886 00893 inline double 00894 DOMStringToDouble(const XalanDOMString& theString, 00895 MemoryManagerType& theManager) 00896 { 00897 return WideStringToDouble(c_wstr(theString), theManager); 00898 } 00899 00900 00901 00909 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00910 OutputString( 00911 XalanOutputStream& theStream, 00912 const CharVectorType& theString); 00913 00914 00915 00923 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00924 OutputString( 00925 #if defined(XALAN_NO_STD_NAMESPACE) 00926 ostream& theStream, 00927 #else 00928 std::ostream& theStream, 00929 #endif 00930 const CharVectorType& theString); 00931 00932 00933 00941 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00942 OutputString( 00943 XalanOutputStream& theStream, 00944 const XalanDOMChar* theString); 00945 00946 00947 00955 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00956 OutputString( 00957 #if defined(XALAN_NO_STD_NAMESPACE) 00958 ostream& theStream, 00959 #else 00960 std::ostream& theStream, 00961 #endif 00962 const XalanDOMChar* theString); 00963 00964 00965 00973 inline void 00974 OutputString( 00975 XalanOutputStream& theStream, 00976 const XalanDOMString& theString) 00977 { 00978 if (isEmpty(theString) == false) 00979 { 00980 OutputString(theStream, c_wstr(theString)); 00981 } 00982 } 00983 00984 00985 00993 inline void 00994 OutputString( 00995 #if defined(XALAN_NO_STD_NAMESPACE) 00996 ostream& theStream, 00997 #else 00998 std::ostream& theStream, 00999 #endif 01000 const XalanDOMString& theString) 01001 { 01002 OutputString(theStream, c_wstr(theString)); 01003 } 01004 01005 01006 01014 inline XalanOutputStream& 01015 operator<<( 01016 XalanOutputStream& theStream, 01017 const CharVectorType& theString) 01018 { 01019 OutputString(theStream, theString); 01020 01021 return theStream; 01022 } 01023 01024 01025 01033 #if defined(XALAN_NO_STD_NAMESPACE) 01034 inline ostream& 01035 operator<<( 01036 ostream& theStream, 01037 #else 01038 inline std::ostream& 01039 operator<<( 01040 std::ostream& theStream, 01041 #endif 01042 const CharVectorType& theString) 01043 { 01044 OutputString(theStream, theString); 01045 01046 return theStream; 01047 } 01048 01049 01050 01058 inline XalanOutputStream& 01059 operator<<( 01060 XalanOutputStream& theStream, 01061 const XalanDOMChar* theString) 01062 { 01063 OutputString(theStream, 01064 theString); 01065 01066 return theStream; 01067 } 01068 01069 01070 01078 #if defined(XALAN_NO_STD_NAMESPACE) 01079 inline ostream& 01080 operator<<( 01081 ostream& theStream, 01082 #else 01083 inline std::ostream& 01084 operator<<( 01085 std::ostream& theStream, 01086 #endif 01087 const XalanDOMChar* theString) 01088 { 01089 OutputString(theStream, 01090 theString); 01091 01092 return theStream; 01093 } 01094 01095 01096 01104 inline XalanOutputStream& 01105 operator<<( 01106 XalanOutputStream& theStream, 01107 const XalanDOMString& theString) 01108 { 01109 OutputString(theStream, 01110 theString); 01111 01112 return theStream; 01113 } 01114 01115 01116 01124 #if defined(XALAN_NO_STD_NAMESPACE) 01125 inline ostream& 01126 operator<<( 01127 ostream& theStream, 01128 #else 01129 inline std::ostream& 01130 operator<<( 01131 std::ostream& theStream, 01132 #endif 01133 const XalanDOMString& theString) 01134 { 01135 OutputString(theStream, 01136 theString); 01137 01138 return theStream; 01139 } 01140 01141 01142 01150 inline XalanDOMChar 01151 charAt( 01152 const XalanDOMString& theString, 01153 XalanDOMString::size_type theIndex) 01154 { 01155 return theString[theIndex]; 01156 } 01157 01158 01159 01166 inline bool 01167 isXMLWhitespace(XalanDOMChar theChar) 01168 { 01169 return XalanXMLChar::isWhitespace(theChar); 01170 } 01171 01172 01173 01180 inline bool 01181 isXMLDigit(XalanDOMChar theChar) 01182 { 01183 return XalanXMLChar::isDigit(theChar); 01184 } 01185 01186 01187 01194 inline bool 01195 isXMLLetterOrDigit(XalanDOMChar theChar) 01196 { 01197 return XalanXMLChar::isDigit(theChar) || 01198 XalanXMLChar::isLetter(theChar); 01199 } 01200 01201 01202 01203 01204 01205 01218 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01219 substring( 01220 const XalanDOMChar* theString, 01221 XalanDOMString& theSubstring, 01222 XalanDOMString::size_type theStartIndex, 01223 XalanDOMString::size_type theEndIndex = XalanDOMString::npos); 01224 01225 01226 01238 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 01239 substring( 01240 const XalanDOMString& theString, 01241 XalanDOMString& theSubstring, 01242 XalanDOMString::size_type theStartIndex, 01243 XalanDOMString::size_type theEndIndex = XalanDOMString::npos); 01244 01245 01246 01258 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01259 substring( 01260 const XalanDOMString& theString, 01261 XalanDOMString::size_type theStartIndex, 01262 XalanDOMString& theResult, 01263 XalanDOMString::size_type theEndIndex = XalanDOMString::npos); 01264 01265 01266 01275 inline XalanDOMChar 01276 toLowerASCII(XalanDOMChar theChar) 01277 { 01278 if (theChar >= XalanUnicode::charLetter_A && theChar <= XalanUnicode::charLetter_Z) 01279 { 01280 return XalanDOMChar(theChar - (XalanUnicode::charLetter_A - XalanUnicode::charLetter_a)); 01281 } 01282 else 01283 { 01284 return theChar; 01285 } 01286 } 01287 01288 01289 01298 inline XalanDOMChar 01299 toUpperASCII(XalanDOMChar theChar) 01300 { 01301 if (theChar >= XalanUnicode::charLetter_a && theChar <= XalanUnicode::charLetter_z) 01302 { 01303 return XalanDOMChar(theChar + (XalanUnicode::charLetter_A - XalanUnicode::charLetter_a)); 01304 } 01305 else 01306 { 01307 return theChar; 01308 } 01309 } 01310 01311 01312 01321 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01322 toLowerCaseASCII(const XalanDOMChar* theString, XalanDOMString& theResult); 01323 01324 01325 01334 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01335 toLowerCaseASCII(const XalanDOMString& theString, XalanDOMString& theResult); 01336 01337 01338 01347 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01348 toUpperCaseASCII(const XalanDOMChar* theString, XalanDOMString& theResult); 01349 01350 01351 01360 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01361 toUpperCaseASCII(const XalanDOMString& theString, XalanDOMString& theResult); 01362 01363 01364 01377 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01378 compare( 01379 const CharVectorType& theLHS, 01380 const CharVectorType& theRHS); 01381 01382 01383 01397 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01398 compare( 01399 const XalanDOMChar* theLHS, 01400 XalanDOMString::size_type theLHSLength, 01401 const XalanDOMChar* theRHS, 01402 XalanDOMString::size_type theRHSLength); 01403 01404 01405 01417 inline int 01418 compare( 01419 const XalanDOMChar* theLHS, 01420 const XalanDOMChar* theRHS) 01421 { 01422 return compare(theLHS, length(theLHS), theRHS, length(theRHS)); 01423 } 01424 01425 01426 01440 inline int 01441 compare( 01442 const XalanDOMString& theLHS, 01443 const XalanDOMString& theRHS) 01444 { 01445 return compare(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS)); 01446 } 01447 01448 01449 01461 inline int 01462 compare( 01463 const XalanDOMChar* theLHS, 01464 const XalanDOMString& theRHS) 01465 { 01466 return compare(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS)); 01467 } 01468 01469 01470 01482 inline int 01483 compare( 01484 const XalanDOMString& theLHS, 01485 const XalanDOMChar* theRHS) 01486 { 01487 return compare(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS)); 01488 } 01489 01490 01491 01507 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01508 compareIgnoreCaseASCII( 01509 const XalanDOMChar* theLHS, 01510 XalanDOMString::size_type theLHSLength, 01511 const XalanDOMChar* theRHS, 01512 XalanDOMString::size_type theRHSLength); 01513 01514 01515 01529 inline int 01530 compareIgnoreCaseASCII( 01531 const XalanDOMChar* theLHS, 01532 const XalanDOMChar* theRHS) 01533 { 01534 return compareIgnoreCaseASCII(theLHS, length(theLHS), theRHS, length(theRHS)); 01535 } 01536 01537 01538 01554 inline int 01555 compareIgnoreCaseASCII( 01556 const XalanDOMString& theLHS, 01557 const XalanDOMString& theRHS) 01558 { 01559 return compareIgnoreCaseASCII(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS)); 01560 } 01561 01562 01563 01577 inline int 01578 compareIgnoreCaseASCII( 01579 const XalanDOMString& theLHS, 01580 const XalanDOMChar* theRHS) 01581 { 01582 return compareIgnoreCaseASCII(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS)); 01583 } 01584 01585 01586 01600 inline int 01601 compareIgnoreCaseASCII( 01602 const XalanDOMChar* theLHS, 01603 const XalanDOMString& theRHS) 01604 { 01605 return compareIgnoreCaseASCII(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS)); 01606 } 01607 01608 01609 01620 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01621 collationCompare( 01622 const XalanDOMChar* theLHS, 01623 XalanDOMString::size_type theLHSLength, 01624 const XalanDOMChar* theRHS, 01625 XalanDOMString::size_type theRHSLength); 01626 01627 01628 01639 inline int 01640 collationCompare( 01641 const XalanDOMChar* theLHS, 01642 const XalanDOMChar* theRHS) 01643 { 01644 return collationCompare(theLHS, length(theLHS), theRHS, length(theRHS)); 01645 } 01646 01647 01648 01659 inline int 01660 collationCompare( 01661 const XalanDOMString& theLHS, 01662 const XalanDOMString& theRHS) 01663 { 01664 return collationCompare(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS)); 01665 } 01666 01667 01668 01677 inline int 01678 collationCompare( 01679 const XalanDOMChar* theLHS, 01680 const XalanDOMString& theRHS) 01681 { 01682 return collationCompare(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS)); 01683 } 01684 01685 01686 01695 inline int 01696 collationCompare( 01697 const XalanDOMString& theLHS, 01698 const XalanDOMChar* theRHS) 01699 { 01700 return collationCompare(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS)); 01701 } 01702 01703 01704 01713 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 01714 equals( 01715 const XalanDOMChar* theLHS, 01716 const XalanDOMChar* theRHS, 01717 XalanDOMString::size_type theLength); 01718 01719 01720 01730 inline bool 01731 equals( 01732 const XalanDOMChar* theLHS, 01733 XalanDOMString::size_type theLHSLength, 01734 const XalanDOMChar* theRHS, 01735 XalanDOMString::size_type theRHSLength) 01736 { 01737 return theLHSLength != theRHSLength ? false : equals(theLHS, theRHS, theLHSLength); 01738 } 01739 01740 01741 01749 inline bool 01750 equals( 01751 const XalanDOMChar* theLHS, 01752 const XalanDOMChar* theRHS) 01753 { 01754 const XalanDOMString::size_type theLHSLength = length(theLHS); 01755 01756 return theLHSLength != length(theRHS) ? false : equals(theLHS, theRHS, theLHSLength); 01757 } 01758 01759 01760 01768 inline bool 01769 equals( 01770 const XalanDOMString& theLHS, 01771 const XalanDOMString& theRHS) 01772 { 01773 return theLHS == theRHS; 01774 } 01775 01776 01777 01785 inline bool 01786 equals( 01787 const XalanDOMChar* theLHS, 01788 const XalanDOMString& theRHS) 01789 { 01790 assert(theLHS != 0); 01791 01792 // Swap them... 01793 return theRHS == theLHS; 01794 } 01795 01796 01797 01805 inline bool 01806 equals(const XalanDOMString& theLHS, 01807 const XalanDOMChar* theRHS) 01808 { 01809 return equals(theRHS, theLHS); 01810 } 01811 01812 01813 01822 inline bool 01823 equals( 01824 const XalanDOMString& theLHS, 01825 const XalanDOMChar* theRHS, 01826 XalanDOMString::size_type theRHSLength) 01827 { 01828 return theRHSLength != length(theLHS) ? false : equals(c_wstr(theLHS), theRHSLength, theRHS, theRHSLength); 01829 } 01830 01831 01832 01833 01842 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 01843 equalsIgnoreCaseASCII( 01844 const XalanDOMChar* theLHS, 01845 const XalanDOMChar* theRHS, 01846 XalanDOMString::size_type theLength); 01847 01848 01849 01860 inline bool 01861 equalsIgnoreCaseASCII( 01862 const XalanDOMChar* theLHS, 01863 XalanDOMString::size_type theLHSLength, 01864 const XalanDOMChar* theRHS, 01865 XalanDOMString::size_type theRHSLength) 01866 { 01867 return theLHSLength != theRHSLength ? false : 01868 equalsIgnoreCaseASCII(theLHS, theRHS, theLHSLength); 01869 } 01870 01871 01872 01881 inline bool 01882 equalsIgnoreCaseASCII( 01883 const XalanDOMChar* theLHS, 01884 const XalanDOMChar* theRHS) 01885 { 01886 const XalanDOMString::size_type theLength = length(theLHS); 01887 01888 return theLength != length(theRHS) ? false : 01889 equalsIgnoreCaseASCII(theLHS, theRHS, theLength); 01890 } 01891 01892 01893 01902 inline bool 01903 equalsIgnoreCaseASCII( 01904 const XalanDOMString& theLHS, 01905 const XalanDOMString& theRHS) 01906 { 01907 const XalanDOMString::size_type theLength = length(theLHS); 01908 01909 return theLength != length(theRHS) ? false : 01910 equalsIgnoreCaseASCII(toCharArray(theLHS), toCharArray(theRHS), theLength); 01911 } 01912 01913 01914 01923 inline bool 01924 equalsIgnoreCaseASCII( 01925 const XalanDOMChar* theLHS, 01926 const XalanDOMString& theRHS) 01927 { 01928 const XalanDOMString::size_type theRHSLength = length(theRHS); 01929 01930 return theRHSLength != length(theLHS) ? false : 01931 equalsIgnoreCaseASCII(theLHS, toCharArray(theRHS), theRHSLength); 01932 } 01933 01934 01935 01944 inline bool 01945 equalsIgnoreCaseASCII( 01946 const XalanDOMString& theLHS, 01947 const XalanDOMChar* theRHS) 01948 { 01949 return equalsIgnoreCaseASCII(theRHS, theLHS); 01950 } 01951 01952 01953 01963 inline bool 01964 operator<( 01965 const CharVectorType& theLHS, 01966 const CharVectorType& theRHS) 01967 { 01968 return compare(theLHS, theRHS) < 0 ? true : false; 01969 } 01970 01971 01972 01982 inline bool 01983 operator<( 01984 const XalanDOMString& theLHS, 01985 const XalanDOMString& theRHS) 01986 { 01987 return compare(theLHS, theRHS) < 0 ? true : false; 01988 } 01989 01990 01991 02000 inline XalanDOMString& 02001 assign( 02002 XalanDOMString& theString, 02003 const XalanDOMString& theStringToAssign) 02004 { 02005 theString = theStringToAssign; 02006 02007 return theString; 02008 } 02009 02010 02011 02020 inline XalanDOMString& 02021 assign( 02022 XalanDOMString& theString, 02023 const XalanDOMChar* theStringToAssign, 02024 XalanDOMString::size_type theStringToAssignLength = XalanDOMString::npos) 02025 { 02026 if (theStringToAssignLength == XalanDOMString::npos) 02027 { 02028 theString.assign(theStringToAssign); 02029 } 02030 else 02031 { 02032 theString.assign(theStringToAssign, theStringToAssignLength); 02033 } 02034 02035 return theString; 02036 } 02037 02038 02039 02047 inline XalanDOMString& 02048 append( 02049 XalanDOMString& theString, 02050 const XalanDOMString& theStringToAppend) 02051 { 02052 theString.append(theStringToAppend); 02053 02054 return theString; 02055 } 02056 02057 02058 02067 inline XalanDOMString& 02068 append( 02069 XalanDOMString& theString, 02070 const XalanDOMChar* theStringToAppend, 02071 XalanDOMString::size_type theStringToAppendLength = XalanDOMString::npos) 02072 { 02073 assert(theStringToAppend != 0); 02074 02075 if (theStringToAppendLength == XalanDOMString::npos) 02076 { 02077 theString.append(theStringToAppend); 02078 } 02079 else 02080 { 02081 theString.append(theStringToAppend, theStringToAppendLength); 02082 } 02083 02084 return theString; 02085 } 02086 02087 02088 02097 inline XalanDOMString& 02098 append( 02099 XalanDOMString& theString, 02100 const char* theStringToAppend, 02101 XalanDOMString::size_type theStringToAppendLength = XalanDOMString::npos) 02102 { 02103 XalanDOMString tmp(theString.getMemoryManager()); 02104 02105 TranscodeFromLocalCodePage(theStringToAppend, tmp, theStringToAppendLength); 02106 02107 theString.append(tmp); 02108 02109 return theString; 02110 } 02111 02112 02113 02121 inline XalanDOMString& 02122 append( 02123 XalanDOMString& theString, 02124 const XalanDOMChar theCharToAppend) 02125 { 02126 theString.append(1, theCharToAppend); 02127 02128 return theString; 02129 } 02130 02131 02132 02140 inline XalanDOMString& 02141 append( 02142 XalanDOMString& theString, 02143 char theCharToAppend) 02144 { 02145 // We have to transcode before appending... 02146 char theTempBuffer[] = { theCharToAppend, '\0' }; 02147 02148 return append(theString, theTempBuffer); 02149 } 02150 02151 02152 02161 inline XalanDOMString& 02162 insert( 02163 XalanDOMString& theString, 02164 XalanDOMString::size_type thePosition, 02165 const XalanDOMString& theStringToInsert) 02166 { 02167 theString.insert(thePosition, theStringToInsert); 02168 02169 return theString; 02170 } 02171 02172 02173 02182 inline XalanDOMString& 02183 insert( 02184 XalanDOMString& theString, 02185 XalanDOMString::size_type thePosition, 02186 const XalanDOMChar* theStringToInsert) 02187 { 02188 theString.insert(thePosition, theStringToInsert); 02189 02190 return theString; 02191 } 02192 02193 02194 02201 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 02202 trim(const XalanDOMString& theString, XalanDOMString& theResult); 02203 02204 02205 02211 inline void 02212 clear(XalanDOMString& theString) 02213 { 02214 theString.clear(); 02215 } 02216 02217 02218 02224 inline void 02225 erase(XalanDOMString& theString) 02226 { 02227 theString.erase(); 02228 } 02229 02230 02231 02238 inline void 02239 releaseMemory(XalanDOMString& theString,MemoryManagerType& theManager) 02240 { 02241 XalanDOMString(theManager).swap(theString); 02242 } 02243 02244 02245 02246 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 02247 CopyWideStringToVector( 02248 const XalanDOMChar* theString, 02249 CharVectorType& theVector); 02250 02251 02252 02253 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 02254 CopyStringToVector( 02255 const char* theString, 02256 CharVectorType& theVector); 02257 02258 02259 02268 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMCharVectorType&) 02269 MakeXalanDOMCharVector( 02270 const char* data, 02271 XalanDOMCharVectorType& result, 02272 bool fTranscode = true); 02273 02274 02275 02283 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMCharVectorType&) 02284 MakeXalanDOMCharVector(const XalanDOMChar* data, 02285 XalanDOMCharVectorType& result); 02286 02287 02288 02296 inline XalanDOMCharVectorType& 02297 MakeXalanDOMCharVector(const XalanDOMString& data, 02298 XalanDOMCharVectorType& result) 02299 { 02300 return MakeXalanDOMCharVector(c_wstr(data),result); 02301 } 02302 02303 02304 02305 #if defined(XALAN_NO_STD_NAMESPACE) 02306 struct c_wstr_functor : public unary_function<XalanDOMString, const XalanDOMChar*> 02307 #else 02308 struct c_wstr_functor : public std::unary_function<XalanDOMString, const XalanDOMChar*> 02309 #endif 02310 { 02311 result_type 02312 operator() (const argument_type& theString) const 02313 { 02314 return c_wstr(theString); 02315 } 02316 }; 02317 02318 02319 02326 struct DOMStringHashFunction : public XALAN_STD_QUALIFIER unary_function<const XalanDOMString&, size_t> 02327 { 02328 result_type 02329 operator() (argument_type theKey) const 02330 { 02331 const XalanDOMChar* theRawBuffer = c_wstr(theKey); 02332 02333 hash_null_terminated_arrays<XalanDOMChar> hasher; 02334 02335 return hasher(theRawBuffer); 02336 } 02337 }; 02338 02339 02340 02341 template<> 02342 struct XalanMapKeyTraits<XalanDOMString> 02343 { 02344 typedef DOMStringHashFunction Hasher; 02345 typedef XALAN_STD_QUALIFIER equal_to<XalanDOMString> Comparator; 02346 }; 02347 02348 02349 02356 struct DOMStringPointerHashFunction : public XALAN_STD_QUALIFIER unary_function<const XalanDOMString*, size_t> 02357 { 02358 result_type 02359 operator() (argument_type theKey) const 02360 { 02361 assert (theKey != 0); 02362 return DOMStringHashFunction()(*theKey); 02363 } 02364 }; 02365 02366 02367 02368 template<> 02369 struct XalanMapKeyTraits<XalanDOMString*> 02370 { 02371 typedef DOMStringPointerHashFunction Hasher; 02372 typedef pointer_equal<XalanDOMString> Comparator; 02373 }; 02374 02375 template<> 02376 struct XalanMapKeyTraits<const XalanDOMString*> 02377 { 02378 typedef DOMStringPointerHashFunction Hasher; 02379 typedef pointer_equal<XalanDOMString> Comparator; 02380 }; 02381 02382 02390 #if defined(XALAN_NO_STD_NAMESPACE) 02391 struct DOMStringEqualsFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02392 #else 02393 struct DOMStringEqualsFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02394 #endif 02395 { 02396 result_type 02397 operator() (first_argument_type theLHS, 02398 second_argument_type theRHS) const 02399 { 02400 return equals(theLHS, theRHS); 02401 } 02402 }; 02403 02404 02405 02413 #if defined(XALAN_NO_STD_NAMESPACE) 02414 struct DOMStringNotEqualsFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02415 #else 02416 struct DOMStringNotEqualsFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02417 #endif 02418 { 02419 result_type 02420 operator() (first_argument_type theLHS, 02421 second_argument_type theRHS) const 02422 { 02423 return !equals(theLHS, theRHS); 02424 } 02425 }; 02426 02427 02428 02436 #if defined(XALAN_NO_STD_NAMESPACE) 02437 struct DOMStringLessThanFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02438 #else 02439 struct DOMStringLessThanFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02440 #endif 02441 { 02442 result_type 02443 operator() (first_argument_type theLHS, 02444 second_argument_type theRHS) const 02445 { 02446 return compare(theLHS, theRHS) < 0 ? true : false; 02447 } 02448 }; 02449 02450 02458 struct DOMStringPointerEqualToFunction : public XALAN_STD_QUALIFIER binary_function<const XalanDOMString*, const XalanDOMString*, bool> 02459 { 02460 result_type 02461 operator() (first_argument_type theLHS, 02462 second_argument_type theRHS) const 02463 { 02464 assert(theLHS != 0 && theRHS != 0); 02465 02466 return compare(*theLHS, *theRHS) == 0 ? true : false; 02467 } 02468 }; 02469 02470 02478 #if defined(XALAN_NO_STD_NAMESPACE) 02479 struct DOMStringPointerLessThanFunction : public binary_function<const XalanDOMString*, const XalanDOMString*, bool> 02480 #else 02481 struct DOMStringPointerLessThanFunction : public std::binary_function<const XalanDOMString*, const XalanDOMString*, bool> 02482 #endif 02483 { 02484 result_type 02485 operator() (first_argument_type theLHS, 02486 second_argument_type theRHS) const 02487 { 02488 assert(theLHS != 0 && theRHS != 0); 02489 02490 return compare(*theLHS, *theRHS) < 0 ? true : false; 02491 } 02492 }; 02493 02494 02495 02503 #if defined(XALAN_NO_STD_NAMESPACE) 02504 struct DOMStringLessThanIgnoreCaseASCIIFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02505 #else 02506 struct DOMStringLessThanIgnoreCaseASCIIFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02507 #endif 02508 { 02509 result_type 02510 operator() (first_argument_type theLHS, 02511 second_argument_type theRHS) const 02512 { 02513 return compareIgnoreCaseASCII(theLHS, theRHS) < 0 ? true : false; 02514 } 02515 }; 02516 02517 02518 02526 #if defined(XALAN_NO_STD_NAMESPACE) 02527 struct DOMStringLessThanOrEqualFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02528 #else 02529 struct DOMStringLessThanOrEqualFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02530 #endif 02531 { 02532 result_type 02533 operator() (first_argument_type theLHS, 02534 second_argument_type theRHS) const 02535 { 02536 return compare(theLHS, theRHS) <= 0 ? true : false; 02537 } 02538 }; 02539 02540 02541 02549 #if defined(XALAN_NO_STD_NAMESPACE) 02550 struct DOMStringGreaterThanFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02551 #else 02552 struct DOMStringGreaterThanFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02553 #endif 02554 { 02555 result_type 02556 operator() (first_argument_type theLHS, 02557 second_argument_type theRHS) const 02558 { 02559 return compare(theLHS, theRHS) > 0 ? true : false; 02560 } 02561 }; 02562 02563 02564 02572 #if defined(XALAN_NO_STD_NAMESPACE) 02573 struct DOMStringGreaterThanOrEqualFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02574 #else 02575 struct DOMStringGreaterThanOrEqualFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02576 #endif 02577 { 02578 result_type 02579 operator() (first_argument_type theLHS, 02580 second_argument_type theRHS) const 02581 { 02582 return compare(theLHS, theRHS) >= 0 ? true : false; 02583 } 02584 }; 02585 02586 02587 02593 #if defined(XALAN_NO_STD_NAMESPACE) 02594 struct less_no_case_ascii_wide_string : public binary_function<const XalanDOMChar*, const XalanDOMChar*, bool> 02595 #else 02596 struct less_no_case_ascii_wide_string : public std::binary_function<const XalanDOMChar*, const XalanDOMChar*, bool> 02597 #endif 02598 { 02607 result_type 02608 operator()( 02609 first_argument_type theLHS, 02610 second_argument_type theRHS) const 02611 { 02612 return compareIgnoreCaseASCII(theLHS, theRHS) < 0 ? true : false; 02613 } 02614 }; 02615 02616 02617 02624 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 02625 isXMLWhitespace(const XalanDOMString& string); 02626 02627 02628 02637 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 02638 isXMLWhitespace( 02639 const XalanDOMChar ch[], 02640 XalanDOMString::size_type start, 02641 XalanDOMString::size_type length); 02642 02643 02644 02651 inline bool 02652 isXMLWhitespace(const XalanDOMChar* theString) 02653 { 02654 assert(theString != 0); 02655 02656 return isXMLWhitespace(theString, 0, length(theString)); 02657 } 02658 02659 02660 02661 XALAN_CPP_NAMESPACE_END 02662 02663 02664 02665 #endif // DOMSTRINGHELPER_HEADER_GUARD_1357924680
Doxygen and GraphViz are used to generate this API documentation from the Xalan-C header files.
Xalan-C++ XSLT Processor Version 1.9 |
|