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/XalanMemoryManagement.hpp> 00040 #include <xalanc/Include/STLHelper.hpp> 00041 00042 00043 00044 #include <xalanc/XalanDOM/XalanDOMString.hpp> 00045 00046 00047 00048 #include <xalanc/PlatformSupport/FormatterListener.hpp> 00049 #include <xalanc/PlatformSupport/XalanUnicode.hpp> 00050 #include <xalanc/PlatformSupport/XalanXMLChar.hpp> 00051 00052 00053 00054 XALAN_CPP_NAMESPACE_BEGIN 00055 00056 00057 00058 XALAN_USING_XERCES(MemoryManager) 00059 00060 00061 00062 class XalanOutputStream; 00063 00064 00065 00066 // This macro has been defined to deal with certain C++ compilers which 00067 // do not create Unicode strings when the "L" string constant prefix is 00068 // used. It is meant _only_ for use with static strings. 00069 #if defined(XALAN_LSTRSUPPORT) && !defined(XALAN_XALANDOMCHAR_USHORT_MISMATCH) 00070 00071 #define XALAN_STATIC_UCODE_STRING(str) L##str 00072 00073 #else 00074 00075 #define XALAN_STATIC_UCODE_STRING(str) str 00076 00077 #endif 00078 00079 00080 00081 #if defined(XALAN_NO_ALGORITHMS_WITH_BUILTINS) 00082 00083 template<class InputIteratorType, class OutputIteratorType> 00084 inline OutputIteratorType 00085 XalanCopy( 00086 InputIteratorType begin, 00087 InputIteratorType end, 00088 OutputIteratorType iterator) 00089 { 00090 for(; begin != end; ++iterator, ++begin) 00091 { 00092 *iterator = *begin; 00093 } 00094 00095 return iterator; 00096 } 00097 00098 00099 00100 template<class InputIteratorType, class OutputIteratorType, class UnaryFunction> 00101 inline OutputIteratorType 00102 XalanTransform( 00103 InputIteratorType begin, 00104 InputIteratorType end, 00105 OutputIteratorType iterator, 00106 UnaryFunction function) 00107 { 00108 for(; begin != end; ++iterator, ++begin) 00109 { 00110 *iterator = function(*begin); 00111 } 00112 00113 return iterator; 00114 } 00115 00116 #else 00117 00118 template<class InputIteratorType, class OutputIteratorType> 00119 inline OutputIteratorType 00120 XalanCopy( 00121 InputIteratorType begin, 00122 InputIteratorType end, 00123 OutputIteratorType iterator) 00124 { 00125 return XALAN_STD_QUALIFIER copy(begin, end, iterator); 00126 } 00127 00128 00129 00130 template<class InputIteratorType, class OutputIteratorType, class UnaryFunction> 00131 inline OutputIteratorType 00132 XalanTransform( 00133 InputIteratorType begin, 00134 InputIteratorType end, 00135 OutputIteratorType iterator, 00136 UnaryFunction function) 00137 { 00138 return XALAN_STD_QUALIFIER transform(begin, end, iterator); 00139 } 00140 00141 #endif 00142 00143 00144 00152 inline const XalanDOMChar* 00153 c_wstr(const XalanDOMString& theString) 00154 { 00155 return theString.c_str(); 00156 } 00157 00158 00159 00167 inline const char* 00168 c_str(const CharVectorType& theString) 00169 { 00170 if (theString.empty() == true) 00171 { 00172 return 0; 00173 } 00174 else 00175 { 00176 const char* const ptr = &theString[0]; 00177 00178 assert(ptr[theString.size() - 1] == '\0'); 00179 00180 return ptr; 00181 } 00182 } 00183 00184 00185 00201 inline const XalanDOMChar* 00202 c_wstr(const XalanDOMChar* theString) 00203 { 00204 return theString; 00205 } 00206 00207 00208 00216 inline const XalanDOMChar* 00217 toCharArray(const XalanDOMString& theString) 00218 { 00219 return theString.c_str(); 00220 } 00221 00222 00223 00230 inline const XalanDOMChar* 00231 toCharArray(const XalanDOMChar* theString) 00232 { 00233 return theString; 00234 } 00235 00236 00237 00245 inline const char* 00246 toCharArray(const CharVectorType& theString) 00247 { 00248 return theString.empty() == true ? 0 : &theString[0]; 00249 } 00250 00251 00252 00260 inline void 00261 reserve( 00262 XalanDOMString& theString, 00263 XalanDOMString::size_type theCount) 00264 { 00265 theString.reserve(theCount); 00266 } 00267 00268 00269 00276 inline XalanDOMString::size_type 00277 length(const XalanDOMString& theString) 00278 { 00279 return theString.length(); 00280 } 00281 00282 00283 00291 inline XalanDOMString::size_type 00292 length(const XalanDOMChar* theString) 00293 { 00294 assert(theString != 0); 00295 00296 const XalanDOMChar* theBufferPointer = theString; 00297 00298 while(*theBufferPointer != 0) 00299 { 00300 theBufferPointer++; 00301 } 00302 00303 return XalanDOMString::size_type(theBufferPointer - theString); 00304 } 00305 00306 00307 00314 inline XalanDOMString::size_type 00315 length(const char* theString) 00316 { 00317 assert(theString != 0); 00318 00319 return XalanDOMString::length(theString); 00320 } 00321 00322 00323 00330 inline bool 00331 isEmpty(const XalanDOMString& str) 00332 { 00333 return str.empty(); 00334 } 00335 00336 00337 00347 inline XalanDOMString::size_type 00348 indexOf( 00349 const XalanDOMChar* theString, 00350 XalanDOMChar theChar) 00351 { 00352 assert(theString != 0); 00353 00354 const XalanDOMChar* thePointer = theString; 00355 00356 while(*thePointer != theChar && *thePointer != 0) 00357 { 00358 ++thePointer; 00359 } 00360 00361 return XalanDOMString::size_type(thePointer - theString); 00362 } 00363 00364 00365 00376 inline XalanDOMString::size_type 00377 indexOf( 00378 const XalanDOMChar* theString, 00379 XalanDOMString::size_type theStringLength, 00380 XalanDOMChar theChar) 00381 { 00382 assert(theString != 0); 00383 00384 const XalanDOMChar* thePointer = theString; 00385 const XalanDOMChar* const theEndPointer = theString + theStringLength; 00386 00387 while(*thePointer != theChar && thePointer != theEndPointer) 00388 { 00389 ++thePointer; 00390 } 00391 00392 return XalanDOMString::size_type(thePointer - theString); 00393 } 00394 00395 00396 00406 inline XalanDOMString::size_type 00407 indexOf( 00408 const XalanDOMString& theString, 00409 XalanDOMChar theChar) 00410 { 00411 return length(theString) == 0 ? 0 : indexOf(c_wstr(theString), theChar); 00412 } 00413 00414 00415 00427 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00428 indexOf( 00429 const XalanDOMChar* theString, 00430 XalanDOMString::size_type theStringLength, 00431 const XalanDOMChar* theSubstring, 00432 XalanDOMString::size_type theSubstringLength); 00433 00434 00435 00445 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00446 indexOf( 00447 const XalanDOMChar* theString, 00448 const XalanDOMChar* theSubstring); 00449 00450 00451 00461 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00462 indexOf( 00463 const XalanDOMString& theString, 00464 const XalanDOMString& theSubstring); 00465 00466 00467 00477 00478 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString::size_type) 00479 lastIndexOf( 00480 const XalanDOMChar* theString, 00481 XalanDOMChar theChar); 00482 00483 00484 00494 inline XalanDOMString::size_type 00495 lastIndexOf( 00496 const XalanDOMString& theString, 00497 XalanDOMChar theChar) 00498 { 00499 return lastIndexOf(c_wstr(theString), theChar); 00500 } 00501 00502 00503 00513 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 00514 startsWith( 00515 const XalanDOMChar* theString, 00516 XalanDOMString::size_type theStringLength, 00517 const XalanDOMChar* theSubstring, 00518 XalanDOMString::size_type theSubstringLength); 00519 00520 00521 00529 inline bool 00530 startsWith( 00531 const XalanDOMChar* theString, 00532 const XalanDOMChar* theSubstring) 00533 { 00534 assert(theString != 0 && theSubstring != 0); 00535 00536 return startsWith(theString, length(theString), theSubstring, length(theSubstring)); 00537 } 00538 00539 00540 00548 inline bool 00549 startsWith( 00550 const XalanDOMChar* theString, 00551 const XalanDOMString& theSubstring) 00552 { 00553 assert(theString != 0); 00554 00555 return startsWith(theString, length(theString), c_wstr(theSubstring), length(theSubstring)); 00556 } 00557 00558 00559 00567 inline bool 00568 startsWith( 00569 const XalanDOMString& theString, 00570 const XalanDOMChar* theSubstring) 00571 { 00572 assert(theSubstring != 0); 00573 00574 return startsWith(c_wstr(theString), length(theString), theSubstring, length(theSubstring)); 00575 } 00576 00577 00578 00587 inline bool 00588 startsWith( 00589 const XalanDOMString& theString, 00590 const XalanDOMChar* theSubstring, 00591 XalanDOMString::size_type theSubstringLength) 00592 { 00593 assert(theSubstring != 0); 00594 00595 return startsWith(c_wstr(theString), length(theString), theSubstring, theSubstringLength); 00596 } 00597 00598 00599 00607 inline bool 00608 startsWith( 00609 const XalanDOMString& theString, 00610 const XalanDOMString& theSubstring) 00611 { 00612 return startsWith(c_wstr(theString), length(theString), c_wstr(theSubstring), length(theSubstring)); 00613 } 00614 00615 00616 00617 00618 00619 00620 00628 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 00629 endsWith( 00630 const XalanDOMChar* theString, 00631 XalanDOMString::size_type theStringLength, 00632 const XalanDOMChar* theSubstring, 00633 XalanDOMString::size_type theSubstringLength); 00634 00635 00636 00644 inline bool 00645 endsWith( 00646 const XalanDOMChar* theString, 00647 const XalanDOMChar* theSubstring) 00648 { 00649 assert(theString != 0 && theSubstring != 0); 00650 00651 return endsWith(theString, length(theString), theSubstring, length(theSubstring)); 00652 } 00653 00654 00655 00663 inline bool 00664 endsWith( 00665 const XalanDOMString& theString, 00666 const XalanDOMString& theSubstring) 00667 { 00668 return endsWith(c_wstr(theString), length(theString), c_wstr(theSubstring), length(theSubstring)); 00669 } 00670 00671 00672 00680 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00681 PointerToDOMString( 00682 const void* theValue, 00683 XalanDOMString& theResult); 00684 00685 00686 00687 00688 00696 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00697 DoubleToDOMString( 00698 double theValue, 00699 XalanDOMString& theResult); 00700 00701 00702 00703 00704 class XALAN_PLATFORMSUPPORT_EXPORT DOMStringHelper 00705 { 00706 public: 00707 00708 typedef void (FormatterListener::*MemberFunctionPtr)(const XMLCh* const, const unsigned int); 00709 00710 static void 00711 DoubleToCharacters( 00712 double theDouble, 00713 FormatterListener& formatterListener, 00714 MemberFunctionPtr function); 00715 00716 static void 00717 LongToCharacters( 00718 long theLong, 00719 FormatterListener& formatterListener, 00720 MemberFunctionPtr function); 00721 }; 00722 00723 00724 00733 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00734 LongToHexDOMString( 00735 long theValue, 00736 XalanDOMString& theResult); 00737 00738 00739 00740 00741 00742 00751 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00752 UnsignedLongToHexDOMString( 00753 unsigned long theValue, 00754 XalanDOMString& theResult); 00755 00756 00757 00765 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00766 LongToDOMString( 00767 long theValue, 00768 XalanDOMString& theResult); 00769 00770 00771 00772 00781 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 00782 UnsignedLongToDOMString( 00783 unsigned long theValue, 00784 XalanDOMString& theResult); 00785 00786 00787 00788 00789 00796 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 00797 WideStringToInt(const XalanDOMChar* theString); 00798 00799 00800 00807 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(long) 00808 WideStringToLong(const XalanDOMChar* theString); 00809 00810 00811 00818 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(unsigned long) 00819 WideStringToUnsignedLong(const XalanDOMChar* theString); 00820 00821 00822 00830 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(double) 00831 WideStringToDouble( 00832 const XalanDOMChar* theString, 00833 MemoryManager& theMemoryManager); 00834 00835 00836 00843 inline int 00844 DOMStringToInt(const XalanDOMString& theString) 00845 { 00846 return WideStringToInt(c_wstr(theString)); 00847 } 00848 00849 00850 00857 inline long 00858 DOMStringToLong(const XalanDOMString& theString) 00859 { 00860 return WideStringToLong(c_wstr(theString)); 00861 } 00862 00863 00864 00871 inline unsigned long 00872 DOMStringToUnsignedLong(const XalanDOMString& theString) 00873 { 00874 return WideStringToUnsignedLong(c_wstr(theString)); 00875 } 00876 00877 00878 00886 inline double 00887 DOMStringToDouble( 00888 const XalanDOMString& theString, 00889 MemoryManager& theMemoryManager) 00890 { 00891 return WideStringToDouble( 00892 c_wstr(theString), 00893 theMemoryManager); 00894 } 00895 00896 00897 00905 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00906 OutputString( 00907 XalanOutputStream& theStream, 00908 const CharVectorType& theString); 00909 00910 00911 00919 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00920 OutputString( 00921 #if defined(XALAN_NO_STD_NAMESPACE) 00922 ostream& theStream, 00923 #else 00924 std::ostream& theStream, 00925 #endif 00926 const CharVectorType& theString); 00927 00928 00929 00937 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00938 OutputString( 00939 XalanOutputStream& theStream, 00940 const XalanDOMChar* theString); 00941 00942 00943 00951 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 00952 OutputString( 00953 #if defined(XALAN_NO_STD_NAMESPACE) 00954 ostream& theStream, 00955 #else 00956 std::ostream& theStream, 00957 #endif 00958 const XalanDOMChar* theString, 00959 MemoryManager& theMemoryManager); 00960 00961 00962 00970 inline void 00971 OutputString( 00972 XalanOutputStream& theStream, 00973 const XalanDOMString& theString) 00974 { 00975 if (isEmpty(theString) == false) 00976 { 00977 OutputString( 00978 theStream, 00979 c_wstr(theString)); 00980 } 00981 } 00982 00983 00984 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 MemoryManager& theMemoryManager) 01002 { 01003 OutputString( 01004 theStream, 01005 c_wstr(theString), 01006 theMemoryManager); 01007 } 01008 01009 01010 01018 inline XalanOutputStream& 01019 operator<<( 01020 XalanOutputStream& theStream, 01021 const CharVectorType& theString) 01022 { 01023 OutputString( 01024 theStream, 01025 theString); 01026 01027 return theStream; 01028 } 01029 01030 01031 01039 #if defined(XALAN_NO_STD_NAMESPACE) 01040 inline ostream& 01041 operator<<( 01042 ostream& theStream, 01043 #else 01044 inline std::ostream& 01045 operator<<( 01046 std::ostream& theStream, 01047 #endif 01048 const CharVectorType& theString) 01049 { 01050 OutputString( 01051 theStream, 01052 theString); 01053 01054 return theStream; 01055 } 01056 01057 01058 01066 inline XalanOutputStream& 01067 operator<<( 01068 XalanOutputStream& theStream, 01069 const XalanDOMChar* theString) 01070 { 01071 OutputString( 01072 theStream, 01073 theString); 01074 01075 return theStream; 01076 } 01077 01078 01079 01087 #if defined(XALAN_NO_STD_NAMESPACE) 01088 inline ostream& 01089 operator<<( 01090 ostream& theStream, 01091 #else 01092 inline std::ostream& 01093 operator<<( 01094 std::ostream& theStream, 01095 #endif 01096 const XalanDOMChar* theString) 01097 { 01098 OutputString( 01099 theStream, 01100 theString, 01101 XalanMemMgrs::getDefault()); 01102 01103 return theStream; 01104 } 01105 01106 01107 01115 inline XalanOutputStream& 01116 operator<<( 01117 XalanOutputStream& theStream, 01118 const XalanDOMString& theString) 01119 { 01120 OutputString(theStream, 01121 theString); 01122 01123 return theStream; 01124 } 01125 01126 01127 01135 #if defined(XALAN_NO_STD_NAMESPACE) 01136 inline ostream& 01137 operator<<( 01138 ostream& theStream, 01139 #else 01140 inline std::ostream& 01141 operator<<( 01142 std::ostream& theStream, 01143 #endif 01144 const XalanDOMString& theString) 01145 { 01146 OutputString( 01147 theStream, 01148 theString, 01149 XalanMemMgrs::getDefault()); 01150 01151 return theStream; 01152 } 01153 01154 01155 01163 #if defined(XALAN_NO_STD_NAMESPACE) 01164 inline ostream& 01165 operator<<( 01166 ostream& theStream, 01167 #else 01168 inline std::ostream& 01169 operator<<( 01170 std::ostream& theStream, 01171 #endif 01172 XalanDOMString& theString) 01173 { 01174 OutputString( 01175 theStream, 01176 theString, 01177 theString.getMemoryManager()); 01178 01179 return theStream; 01180 } 01181 01182 01183 01191 inline XalanDOMChar 01192 charAt( 01193 const XalanDOMString& theString, 01194 XalanDOMString::size_type theIndex) 01195 { 01196 return theString[theIndex]; 01197 } 01198 01199 01200 01207 inline bool 01208 isXMLWhitespace(XalanDOMChar theChar) 01209 { 01210 return XalanXMLChar::isWhitespace(theChar); 01211 } 01212 01213 01214 01221 inline bool 01222 isXMLDigit(XalanDOMChar theChar) 01223 { 01224 return XalanXMLChar::isDigit(theChar); 01225 } 01226 01227 01228 01235 inline bool 01236 isXMLLetterOrDigit(XalanDOMChar theChar) 01237 { 01238 return XalanXMLChar::isDigit(theChar) || 01239 XalanXMLChar::isLetter(theChar); 01240 } 01241 01242 01243 01244 01245 01246 01259 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01260 substring( 01261 const XalanDOMChar* theString, 01262 XalanDOMString& theSubstring, 01263 XalanDOMString::size_type theStartIndex, 01264 XalanDOMString::size_type theEndIndex = XalanDOMString::npos); 01265 01266 01267 01279 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 01280 substring( 01281 const XalanDOMString& theString, 01282 XalanDOMString& theSubstring, 01283 XalanDOMString::size_type theStartIndex, 01284 XalanDOMString::size_type theEndIndex = XalanDOMString::npos); 01285 01286 01287 01299 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01300 substring( 01301 const XalanDOMString& theString, 01302 XalanDOMString::size_type theStartIndex, 01303 XalanDOMString& theResult, 01304 XalanDOMString::size_type theEndIndex = XalanDOMString::npos); 01305 01306 01307 01316 inline XalanDOMChar 01317 toLowerASCII(XalanDOMChar theChar) 01318 { 01319 if (theChar >= XalanUnicode::charLetter_A && theChar <= XalanUnicode::charLetter_Z) 01320 { 01321 return XalanDOMChar(theChar - (XalanUnicode::charLetter_A - XalanUnicode::charLetter_a)); 01322 } 01323 else 01324 { 01325 return theChar; 01326 } 01327 } 01328 01329 01330 01339 inline XalanDOMChar 01340 toUpperASCII(XalanDOMChar theChar) 01341 { 01342 if (theChar >= XalanUnicode::charLetter_a && theChar <= XalanUnicode::charLetter_z) 01343 { 01344 return XalanDOMChar(theChar + (XalanUnicode::charLetter_A - XalanUnicode::charLetter_a)); 01345 } 01346 else 01347 { 01348 return theChar; 01349 } 01350 } 01351 01352 01353 01363 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01364 toLowerCaseASCII( 01365 const XalanDOMChar* theString, 01366 XalanDOMString& theResult); 01367 01368 01369 01379 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01380 toLowerCaseASCII( 01381 const XalanDOMString& theString, 01382 XalanDOMString& theResult); 01383 01384 01385 01394 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01395 toLowerCaseASCII(XalanDOMString& theString); 01396 01397 01398 01408 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01409 toUpperCaseASCII( 01410 const XalanDOMChar* theString, 01411 XalanDOMString& theResult); 01412 01413 01414 01424 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01425 toUpperCaseASCII( 01426 const XalanDOMString& theString, 01427 XalanDOMString& theResult); 01428 01429 01430 01439 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 01440 toUpperCaseASCII(XalanDOMString& theString); 01441 01442 01443 01456 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01457 compare( 01458 const CharVectorType& theLHS, 01459 const CharVectorType& theRHS); 01460 01461 01462 01476 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01477 compare( 01478 const XalanDOMChar* theLHS, 01479 XalanDOMString::size_type theLHSLength, 01480 const XalanDOMChar* theRHS, 01481 XalanDOMString::size_type theRHSLength); 01482 01483 01484 01496 inline int 01497 compare( 01498 const XalanDOMChar* theLHS, 01499 const XalanDOMChar* theRHS) 01500 { 01501 return compare(theLHS, length(theLHS), theRHS, length(theRHS)); 01502 } 01503 01504 01505 01519 inline int 01520 compare( 01521 const XalanDOMString& theLHS, 01522 const XalanDOMString& theRHS) 01523 { 01524 return compare(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS)); 01525 } 01526 01527 01528 01540 inline int 01541 compare( 01542 const XalanDOMChar* theLHS, 01543 const XalanDOMString& theRHS) 01544 { 01545 return compare(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS)); 01546 } 01547 01548 01549 01561 inline int 01562 compare( 01563 const XalanDOMString& theLHS, 01564 const XalanDOMChar* theRHS) 01565 { 01566 return compare(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS)); 01567 } 01568 01569 01570 01586 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01587 compareIgnoreCaseASCII( 01588 const XalanDOMChar* theLHS, 01589 XalanDOMString::size_type theLHSLength, 01590 const XalanDOMChar* theRHS, 01591 XalanDOMString::size_type theRHSLength); 01592 01593 01594 01608 inline int 01609 compareIgnoreCaseASCII( 01610 const XalanDOMChar* theLHS, 01611 const XalanDOMChar* theRHS) 01612 { 01613 return compareIgnoreCaseASCII(theLHS, length(theLHS), theRHS, length(theRHS)); 01614 } 01615 01616 01617 01633 inline int 01634 compareIgnoreCaseASCII( 01635 const XalanDOMString& theLHS, 01636 const XalanDOMString& theRHS) 01637 { 01638 return compareIgnoreCaseASCII(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS)); 01639 } 01640 01641 01642 01656 inline int 01657 compareIgnoreCaseASCII( 01658 const XalanDOMString& theLHS, 01659 const XalanDOMChar* theRHS) 01660 { 01661 return compareIgnoreCaseASCII(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS)); 01662 } 01663 01664 01665 01679 inline int 01680 compareIgnoreCaseASCII( 01681 const XalanDOMChar* theLHS, 01682 const XalanDOMString& theRHS) 01683 { 01684 return compareIgnoreCaseASCII(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS)); 01685 } 01686 01687 01688 01699 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(int) 01700 collationCompare( 01701 const XalanDOMChar* theLHS, 01702 XalanDOMString::size_type theLHSLength, 01703 const XalanDOMChar* theRHS, 01704 XalanDOMString::size_type theRHSLength); 01705 01706 01707 01718 inline int 01719 collationCompare( 01720 const XalanDOMChar* theLHS, 01721 const XalanDOMChar* theRHS) 01722 { 01723 return collationCompare(theLHS, length(theLHS), theRHS, length(theRHS)); 01724 } 01725 01726 01727 01738 inline int 01739 collationCompare( 01740 const XalanDOMString& theLHS, 01741 const XalanDOMString& theRHS) 01742 { 01743 return collationCompare(toCharArray(theLHS), length(theLHS), toCharArray(theRHS), length(theRHS)); 01744 } 01745 01746 01747 01756 inline int 01757 collationCompare( 01758 const XalanDOMChar* theLHS, 01759 const XalanDOMString& theRHS) 01760 { 01761 return collationCompare(theLHS, length(theLHS), toCharArray(theRHS), length(theRHS)); 01762 } 01763 01764 01765 01774 inline int 01775 collationCompare( 01776 const XalanDOMString& theLHS, 01777 const XalanDOMChar* theRHS) 01778 { 01779 return collationCompare(toCharArray(theLHS), length(theLHS), theRHS, length(theRHS)); 01780 } 01781 01782 01783 01792 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 01793 equals( 01794 const XalanDOMChar* theLHS, 01795 const XalanDOMChar* theRHS, 01796 XalanDOMString::size_type theLength); 01797 01798 01799 01809 inline bool 01810 equals( 01811 const XalanDOMChar* theLHS, 01812 XalanDOMString::size_type theLHSLength, 01813 const XalanDOMChar* theRHS, 01814 XalanDOMString::size_type theRHSLength) 01815 { 01816 return theLHSLength != theRHSLength ? false : equals(theLHS, theRHS, theLHSLength); 01817 } 01818 01819 01820 01828 inline bool 01829 equals( 01830 const XalanDOMChar* theLHS, 01831 const XalanDOMChar* theRHS) 01832 { 01833 const XalanDOMString::size_type theLHSLength = length(theLHS); 01834 01835 return theLHSLength != length(theRHS) ? false : equals(theLHS, theRHS, theLHSLength); 01836 } 01837 01838 01839 01847 inline bool 01848 equals( 01849 const XalanDOMString& theLHS, 01850 const XalanDOMString& theRHS) 01851 { 01852 return theLHS == theRHS; 01853 } 01854 01855 01856 01864 inline bool 01865 equals( 01866 const XalanDOMChar* theLHS, 01867 const XalanDOMString& theRHS) 01868 { 01869 assert(theLHS != 0); 01870 01871 // Swap them... 01872 return theRHS == theLHS; 01873 } 01874 01875 01876 01884 inline bool 01885 equals(const XalanDOMString& theLHS, 01886 const XalanDOMChar* theRHS) 01887 { 01888 return equals(theRHS, theLHS); 01889 } 01890 01891 01892 01901 inline bool 01902 equals( 01903 const XalanDOMString& theLHS, 01904 const XalanDOMChar* theRHS, 01905 XalanDOMString::size_type theRHSLength) 01906 { 01907 return theRHSLength != length(theLHS) ? false : equals(c_wstr(theLHS), theRHSLength, theRHS, theRHSLength); 01908 } 01909 01910 01911 01912 01921 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 01922 equalsIgnoreCaseASCII( 01923 const XalanDOMChar* theLHS, 01924 const XalanDOMChar* theRHS, 01925 XalanDOMString::size_type theLength); 01926 01927 01928 01939 inline bool 01940 equalsIgnoreCaseASCII( 01941 const XalanDOMChar* theLHS, 01942 XalanDOMString::size_type theLHSLength, 01943 const XalanDOMChar* theRHS, 01944 XalanDOMString::size_type theRHSLength) 01945 { 01946 return theLHSLength != theRHSLength ? false : 01947 equalsIgnoreCaseASCII(theLHS, theRHS, theLHSLength); 01948 } 01949 01950 01951 01960 inline bool 01961 equalsIgnoreCaseASCII( 01962 const XalanDOMChar* theLHS, 01963 const XalanDOMChar* theRHS) 01964 { 01965 const XalanDOMString::size_type theLength = length(theLHS); 01966 01967 return theLength != length(theRHS) ? false : 01968 equalsIgnoreCaseASCII(theLHS, theRHS, theLength); 01969 } 01970 01971 01972 01981 inline bool 01982 equalsIgnoreCaseASCII( 01983 const XalanDOMString& theLHS, 01984 const XalanDOMString& theRHS) 01985 { 01986 const XalanDOMString::size_type theLength = length(theLHS); 01987 01988 return theLength != length(theRHS) ? false : 01989 equalsIgnoreCaseASCII(toCharArray(theLHS), toCharArray(theRHS), theLength); 01990 } 01991 01992 01993 02002 inline bool 02003 equalsIgnoreCaseASCII( 02004 const XalanDOMChar* theLHS, 02005 const XalanDOMString& theRHS) 02006 { 02007 const XalanDOMString::size_type theRHSLength = length(theRHS); 02008 02009 return theRHSLength != length(theLHS) ? false : 02010 equalsIgnoreCaseASCII(theLHS, toCharArray(theRHS), theRHSLength); 02011 } 02012 02013 02014 02023 inline bool 02024 equalsIgnoreCaseASCII( 02025 const XalanDOMString& theLHS, 02026 const XalanDOMChar* theRHS) 02027 { 02028 return equalsIgnoreCaseASCII(theRHS, theLHS); 02029 } 02030 02031 02032 02042 inline bool 02043 operator<( 02044 const CharVectorType& theLHS, 02045 const CharVectorType& theRHS) 02046 { 02047 return compare(theLHS, theRHS) < 0 ? true : false; 02048 } 02049 02050 02051 02061 inline bool 02062 operator<( 02063 const XalanDOMString& theLHS, 02064 const XalanDOMString& theRHS) 02065 { 02066 return compare(theLHS, theRHS) < 0 ? true : false; 02067 } 02068 02069 02070 02079 inline XalanDOMString& 02080 assign( 02081 XalanDOMString& theString, 02082 const XalanDOMString& theStringToAssign) 02083 { 02084 theString = theStringToAssign; 02085 02086 return theString; 02087 } 02088 02089 02090 02099 inline XalanDOMString& 02100 assign( 02101 XalanDOMString& theString, 02102 const XalanDOMChar* theStringToAssign, 02103 XalanDOMString::size_type theStringToAssignLength = XalanDOMString::npos) 02104 { 02105 if (theStringToAssignLength == XalanDOMString::npos) 02106 { 02107 theString.assign(theStringToAssign); 02108 } 02109 else 02110 { 02111 theString.assign(theStringToAssign, theStringToAssignLength); 02112 } 02113 02114 return theString; 02115 } 02116 02117 02118 02126 inline XalanDOMString& 02127 append( 02128 XalanDOMString& theString, 02129 const XalanDOMString& theStringToAppend) 02130 { 02131 theString.append(theStringToAppend); 02132 02133 return theString; 02134 } 02135 02136 02137 02146 inline XalanDOMString& 02147 append( 02148 XalanDOMString& theString, 02149 const XalanDOMChar* theStringToAppend, 02150 XalanDOMString::size_type theStringToAppendLength = XalanDOMString::npos) 02151 { 02152 assert(theStringToAppend != 0); 02153 02154 if (theStringToAppendLength == XalanDOMString::npos) 02155 { 02156 theString.append(theStringToAppend); 02157 } 02158 else 02159 { 02160 theString.append(theStringToAppend, theStringToAppendLength); 02161 } 02162 02163 return theString; 02164 } 02165 02166 02167 02176 inline XalanDOMString& 02177 append( 02178 XalanDOMString& theString, 02179 const char* theStringToAppend, 02180 XalanDOMString::size_type theStringToAppendLength = XalanDOMString::npos) 02181 { 02182 XalanDOMString tmp(theString.getMemoryManager()); 02183 02184 TranscodeFromLocalCodePage(theStringToAppend, tmp, theStringToAppendLength); 02185 02186 theString.append(tmp); 02187 02188 return theString; 02189 } 02190 02191 02192 02200 inline XalanDOMString& 02201 append( 02202 XalanDOMString& theString, 02203 const XalanDOMChar theCharToAppend) 02204 { 02205 theString.append(1, theCharToAppend); 02206 02207 return theString; 02208 } 02209 02210 02211 02219 inline XalanDOMString& 02220 append( 02221 XalanDOMString& theString, 02222 char theCharToAppend) 02223 { 02224 // We have to transcode before appending... 02225 char theTempBuffer[] = { theCharToAppend, '\0' }; 02226 02227 return append(theString, theTempBuffer); 02228 } 02229 02230 02231 02240 inline XalanDOMString& 02241 insert( 02242 XalanDOMString& theString, 02243 XalanDOMString::size_type thePosition, 02244 const XalanDOMString& theStringToInsert) 02245 { 02246 theString.insert(thePosition, theStringToInsert); 02247 02248 return theString; 02249 } 02250 02251 02252 02261 inline XalanDOMString& 02262 insert( 02263 XalanDOMString& theString, 02264 XalanDOMString::size_type thePosition, 02265 const XalanDOMChar* theStringToInsert) 02266 { 02267 theString.insert(thePosition, theStringToInsert); 02268 02269 return theString; 02270 } 02271 02272 02273 02280 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMString&) 02281 trim(const XalanDOMString& theString, XalanDOMString& theResult); 02282 02283 02284 02290 inline void 02291 clear(XalanDOMString& theString) 02292 { 02293 theString.clear(); 02294 } 02295 02296 02297 02303 inline void 02304 erase(XalanDOMString& theString) 02305 { 02306 theString.erase(); 02307 } 02308 02309 02310 02317 inline void 02318 releaseMemory(XalanDOMString& theString,MemoryManagerType& theManager) 02319 { 02320 XalanDOMString(theManager).swap(theString); 02321 } 02322 02323 02324 02325 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 02326 CopyWideStringToVector( 02327 const XalanDOMChar* theString, 02328 CharVectorType& theVector); 02329 02330 02331 02332 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(void) 02333 CopyStringToVector( 02334 const char* theString, 02335 CharVectorType& theVector); 02336 02337 02338 02347 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMCharVectorType&) 02348 MakeXalanDOMCharVector( 02349 const char* data, 02350 XalanDOMCharVectorType& result, 02351 bool fTranscode = true); 02352 02353 02354 02362 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(XalanDOMCharVectorType&) 02363 MakeXalanDOMCharVector(const XalanDOMChar* data, 02364 XalanDOMCharVectorType& result); 02365 02366 02367 02375 inline XalanDOMCharVectorType& 02376 MakeXalanDOMCharVector(const XalanDOMString& data, 02377 XalanDOMCharVectorType& result) 02378 { 02379 return MakeXalanDOMCharVector(c_wstr(data),result); 02380 } 02381 02382 02383 02384 #if defined(XALAN_NO_STD_NAMESPACE) 02385 struct c_wstr_functor : public unary_function<XalanDOMString, const XalanDOMChar*> 02386 #else 02387 struct c_wstr_functor : public std::unary_function<XalanDOMString, const XalanDOMChar*> 02388 #endif 02389 { 02390 result_type 02391 operator() (const argument_type& theString) const 02392 { 02393 return c_wstr(theString); 02394 } 02395 }; 02396 02397 02398 02405 struct DOMStringHashFunction : public XALAN_STD_QUALIFIER unary_function<const XalanDOMString&, size_t> 02406 { 02407 result_type 02408 operator() (argument_type theKey) const 02409 { 02410 const XalanDOMChar* theRawBuffer = c_wstr(theKey); 02411 02412 hash_null_terminated_arrays<XalanDOMChar> hasher; 02413 02414 return hasher(theRawBuffer); 02415 } 02416 }; 02417 02418 02419 02420 template<> 02421 struct XalanMapKeyTraits<XalanDOMString> 02422 { 02423 typedef DOMStringHashFunction Hasher; 02424 typedef XALAN_STD_QUALIFIER equal_to<XalanDOMString> Comparator; 02425 }; 02426 02427 02428 02435 struct DOMStringPointerHashFunction : public XALAN_STD_QUALIFIER unary_function<const XalanDOMString*, size_t> 02436 { 02437 result_type 02438 operator() (argument_type theKey) const 02439 { 02440 assert (theKey != 0); 02441 return DOMStringHashFunction()(*theKey); 02442 } 02443 }; 02444 02445 02446 02447 template<> 02448 struct XalanMapKeyTraits<XalanDOMString*> 02449 { 02450 typedef DOMStringPointerHashFunction Hasher; 02451 typedef pointer_equal<XalanDOMString> Comparator; 02452 }; 02453 02454 template<> 02455 struct XalanMapKeyTraits<const XalanDOMString*> 02456 { 02457 typedef DOMStringPointerHashFunction Hasher; 02458 typedef pointer_equal<XalanDOMString> Comparator; 02459 }; 02460 02461 02469 #if defined(XALAN_NO_STD_NAMESPACE) 02470 struct DOMStringEqualsFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02471 #else 02472 struct DOMStringEqualsFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02473 #endif 02474 { 02475 result_type 02476 operator() (first_argument_type theLHS, 02477 second_argument_type theRHS) const 02478 { 02479 return equals(theLHS, theRHS); 02480 } 02481 }; 02482 02483 02484 02492 #if defined(XALAN_NO_STD_NAMESPACE) 02493 struct DOMStringNotEqualsFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02494 #else 02495 struct DOMStringNotEqualsFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02496 #endif 02497 { 02498 result_type 02499 operator() (first_argument_type theLHS, 02500 second_argument_type theRHS) const 02501 { 02502 return !equals(theLHS, theRHS); 02503 } 02504 }; 02505 02506 02507 02515 #if defined(XALAN_NO_STD_NAMESPACE) 02516 struct DOMStringLessThanFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02517 #else 02518 struct DOMStringLessThanFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02519 #endif 02520 { 02521 result_type 02522 operator() (first_argument_type theLHS, 02523 second_argument_type theRHS) const 02524 { 02525 return compare(theLHS, theRHS) < 0 ? true : false; 02526 } 02527 }; 02528 02529 02537 struct DOMStringPointerEqualToFunction : public XALAN_STD_QUALIFIER binary_function<const XalanDOMString*, const XalanDOMString*, bool> 02538 { 02539 result_type 02540 operator() (first_argument_type theLHS, 02541 second_argument_type theRHS) const 02542 { 02543 assert(theLHS != 0 && theRHS != 0); 02544 02545 return compare(*theLHS, *theRHS) == 0 ? true : false; 02546 } 02547 }; 02548 02549 02557 #if defined(XALAN_NO_STD_NAMESPACE) 02558 struct DOMStringPointerLessThanFunction : public binary_function<const XalanDOMString*, const XalanDOMString*, bool> 02559 #else 02560 struct DOMStringPointerLessThanFunction : public std::binary_function<const XalanDOMString*, const XalanDOMString*, bool> 02561 #endif 02562 { 02563 result_type 02564 operator() (first_argument_type theLHS, 02565 second_argument_type theRHS) const 02566 { 02567 assert(theLHS != 0 && theRHS != 0); 02568 02569 return compare(*theLHS, *theRHS) < 0 ? true : false; 02570 } 02571 }; 02572 02573 02574 02582 #if defined(XALAN_NO_STD_NAMESPACE) 02583 struct DOMStringLessThanIgnoreCaseASCIIFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02584 #else 02585 struct DOMStringLessThanIgnoreCaseASCIIFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02586 #endif 02587 { 02588 result_type 02589 operator() (first_argument_type theLHS, 02590 second_argument_type theRHS) const 02591 { 02592 return compareIgnoreCaseASCII(theLHS, theRHS) < 0 ? true : false; 02593 } 02594 }; 02595 02596 02597 02605 #if defined(XALAN_NO_STD_NAMESPACE) 02606 struct DOMStringLessThanOrEqualFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02607 #else 02608 struct DOMStringLessThanOrEqualFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02609 #endif 02610 { 02611 result_type 02612 operator() (first_argument_type theLHS, 02613 second_argument_type theRHS) const 02614 { 02615 return compare(theLHS, theRHS) <= 0 ? true : false; 02616 } 02617 }; 02618 02619 02620 02628 #if defined(XALAN_NO_STD_NAMESPACE) 02629 struct DOMStringGreaterThanFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02630 #else 02631 struct DOMStringGreaterThanFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02632 #endif 02633 { 02634 result_type 02635 operator() (first_argument_type theLHS, 02636 second_argument_type theRHS) const 02637 { 02638 return compare(theLHS, theRHS) > 0 ? true : false; 02639 } 02640 }; 02641 02642 02643 02651 #if defined(XALAN_NO_STD_NAMESPACE) 02652 struct DOMStringGreaterThanOrEqualFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02653 #else 02654 struct DOMStringGreaterThanOrEqualFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 02655 #endif 02656 { 02657 result_type 02658 operator() (first_argument_type theLHS, 02659 second_argument_type theRHS) const 02660 { 02661 return compare(theLHS, theRHS) >= 0 ? true : false; 02662 } 02663 }; 02664 02665 02666 02672 #if defined(XALAN_NO_STD_NAMESPACE) 02673 struct less_no_case_ascii_wide_string : public binary_function<const XalanDOMChar*, const XalanDOMChar*, bool> 02674 #else 02675 struct less_no_case_ascii_wide_string : public std::binary_function<const XalanDOMChar*, const XalanDOMChar*, bool> 02676 #endif 02677 { 02686 result_type 02687 operator()( 02688 first_argument_type theLHS, 02689 second_argument_type theRHS) const 02690 { 02691 return compareIgnoreCaseASCII(theLHS, theRHS) < 0 ? true : false; 02692 } 02693 }; 02694 02695 02696 02703 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 02704 isXMLWhitespace(const XalanDOMString& string); 02705 02706 02707 02716 XALAN_PLATFORMSUPPORT_EXPORT_FUNCTION(bool) 02717 isXMLWhitespace( 02718 const XalanDOMChar ch[], 02719 XalanDOMString::size_type start, 02720 XalanDOMString::size_type length); 02721 02722 02723 02730 inline bool 02731 isXMLWhitespace(const XalanDOMChar* theString) 02732 { 02733 assert(theString != 0); 02734 02735 return isXMLWhitespace(theString, 0, length(theString)); 02736 } 02737 02738 02739 02740 XALAN_CPP_NAMESPACE_END 02741 02742 02743 02744 #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.10 |
|