00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one 00003 * or more contributor license agreements. See the NOTICE file 00004 * distributed with this work for additional information 00005 * regarding copyright ownership. The ASF licenses this file 00006 * to you under the Apache License, Version 2.0 (the "License"); 00007 * you may not use this file except in compliance with the License. 00008 * You may obtain a copy of the License at 00009 * 00010 * http://www.apache.org/licenses/LICENSE-2.0 00011 * 00012 * Unless required by applicable law or agreed to in writing, software 00013 * distributed under the License is distributed on an "AS IS" BASIS, 00014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 * See the License for the specific language governing permissions and 00016 * limitations under the License. 00017 */ 00018 #if !defined(XALANDOMSTRING_HEADER_GUARD_1357924680) 00019 #define XALANDOMSTRING_HEADER_GUARD_1357924680 00020 00021 00022 00023 #include <xalanc/XalanDOM/XalanDOMDefinitions.hpp> 00024 00025 00026 00027 #include <cassert> 00028 00029 00030 00031 #include <xalanc/Include/STLHelper.hpp> 00032 #include <xalanc/Include/XalanMemoryManagement.hpp> 00033 #include <xalanc/Include/XalanVector.hpp> 00034 00035 00036 00037 #include <xalanc/XalanDOM/XalanDOMException.hpp> 00038 00039 00040 00041 XALAN_CPP_NAMESPACE_BEGIN 00042 00043 00044 00045 class XALAN_DOM_EXPORT XalanDOMString 00046 { 00047 public: 00048 00049 typedef XalanVector<XalanDOMChar> XalanDOMCharVectorType; 00050 typedef XalanVector<char> CharVectorType; 00051 typedef XalanVector<wchar_t> WideCharVectorType; 00052 00053 typedef XalanDOMChar value_type; 00054 typedef XalanDOMChar& reference; 00055 typedef const XalanDOMChar& const_reference; 00056 00057 typedef XalanSize_t size_type; 00058 00059 typedef XalanDOMCharVectorType::iterator iterator; 00060 typedef XalanDOMCharVectorType::const_iterator const_iterator; 00061 typedef XalanDOMCharVectorType::reverse_iterator reverse_iterator; 00062 typedef XalanDOMCharVectorType::const_reverse_iterator const_reverse_iterator; 00063 00064 #if defined(XALAN_INLINE_INITIALIZATION) 00065 static const size_type npos = ~0u; 00066 #else 00067 enum { npos = ~0u }; 00068 #endif 00069 00070 XalanDOMString(MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR); 00071 00072 explicit 00073 XalanDOMString( 00074 const char* theString, 00075 MemoryManager& theManager XALAN_DEFAULT_MEMMGR, 00076 size_type theCount = size_type(npos)); 00077 00078 XalanDOMString( 00079 const XalanDOMString& theSource, 00080 MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR, 00081 size_type theStartPosition = 0, 00082 size_type theCount = size_type(npos)); 00083 00084 explicit 00085 XalanDOMString( 00086 const XalanDOMChar* theString, 00087 MemoryManager& theManager XALAN_DEFAULT_MEMMGR, 00088 size_type theCount = size_type(npos)); 00089 00090 XalanDOMString( 00091 size_type theCount, 00092 XalanDOMChar theChar, 00093 MemoryManager& theManager XALAN_DEFAULT_MEMMGR); 00094 00095 XalanDOMString* 00096 clone(MemoryManager& theManager); 00097 00098 ~XalanDOMString() 00099 { 00100 } 00101 00102 XalanDOMString& 00103 operator=(const XalanDOMString& theRHS) 00104 { 00105 return assign(theRHS); 00106 } 00107 00108 XalanDOMString& 00109 operator=(const XalanDOMChar* theRHS) 00110 { 00111 return assign(theRHS); 00112 } 00113 00114 XalanDOMString& 00115 operator=(const char* theRHS) 00116 { 00117 return assign(theRHS); 00118 } 00119 00120 XalanDOMString& 00121 operator=(XalanDOMChar theRHS) 00122 { 00123 return assign(1, theRHS); 00124 } 00125 00126 iterator 00127 begin() 00128 { 00129 invariants(); 00130 00131 return m_data.begin(); 00132 } 00133 00134 const_iterator 00135 begin() const 00136 { 00137 invariants(); 00138 00139 return m_data.begin(); 00140 } 00141 00142 iterator 00143 end() 00144 { 00145 invariants(); 00146 00147 return m_data.empty() == true ? m_data.end() : m_data.end() - 1; 00148 } 00149 00150 const_iterator 00151 end() const 00152 { 00153 invariants(); 00154 00155 return m_data.empty() == true ? m_data.end() : m_data.end() - 1; 00156 } 00157 00158 reverse_iterator 00159 rbegin() 00160 { 00161 invariants(); 00162 00163 reverse_iterator i = m_data.rbegin(); 00164 00165 if (m_data.empty() == false) 00166 { 00167 ++i; 00168 } 00169 00170 return i; 00171 } 00172 00173 const_reverse_iterator 00174 rbegin() const 00175 { 00176 invariants(); 00177 00178 const_reverse_iterator i = m_data.rbegin(); 00179 00180 if (m_data.empty() == false) 00181 { 00182 ++i; 00183 } 00184 00185 return i; 00186 } 00187 00188 reverse_iterator 00189 rend() 00190 { 00191 invariants(); 00192 00193 return m_data.rend(); 00194 } 00195 00196 const_reverse_iterator 00197 rend() const 00198 { 00199 invariants(); 00200 00201 return m_data.rend(); 00202 } 00203 00204 size_type 00205 size() const 00206 { 00207 invariants(); 00208 00209 return m_size; 00210 } 00211 00212 size_type 00213 length() const 00214 { 00215 invariants(); 00216 00217 return size(); 00218 } 00219 00220 size_type 00221 max_size() const 00222 { 00223 invariants(); 00224 00225 return ~size_type(0); 00226 } 00227 00228 void 00229 resize( 00230 size_type theCount, 00231 XalanDOMChar theChar); 00232 00233 void 00234 resize(size_type theCount) 00235 { 00236 invariants(); 00237 00238 resize(theCount, XalanDOMChar(0)); 00239 } 00240 00241 size_type 00242 capacity() const 00243 { 00244 invariants(); 00245 00246 const XalanDOMCharVectorType::size_type theCapacity = 00247 m_data.capacity(); 00248 00249 return theCapacity == 0 ? 0 : size_type(theCapacity - 1); 00250 } 00251 00252 void 00253 reserve(size_type theCount = 0) 00254 { 00255 invariants(); 00256 00257 m_data.reserve(theCount + 1); 00258 } 00259 00260 void 00261 clear() 00262 { 00263 invariants(); 00264 00265 m_data.erase(m_data.begin(), m_data.end()); 00266 00267 m_size = 0; 00268 00269 invariants(); 00270 } 00271 00272 iterator 00273 erase(iterator thePosition) 00274 { 00275 invariants(); 00276 00277 m_data.erase(thePosition); 00278 00279 --m_size; 00280 00281 invariants(); 00282 00283 return thePosition; 00284 } 00285 00286 iterator 00287 erase( 00288 iterator theFirst, 00289 iterator theLast) 00290 { 00291 invariants(); 00292 00293 m_data.erase(theFirst, theLast); 00294 00295 m_size = m_data.size() - 1; 00296 00297 invariants(); 00298 00299 return theFirst; 00300 } 00301 00302 XalanDOMString& 00303 erase( 00304 size_type theStartPosition = 0, 00305 size_type theCount = size_type(npos)); 00306 00307 bool 00308 empty() const 00309 { 00310 invariants(); 00311 00312 return m_size == 0 ? true : false; 00313 } 00314 00315 const_reference 00316 operator[](size_type theIndex) const 00317 { 00318 invariants(); 00319 00320 return m_data[theIndex]; 00321 } 00322 00323 reference 00324 operator[](size_type theIndex) 00325 { 00326 invariants(); 00327 00328 return m_data[theIndex]; 00329 } 00330 00331 const_reference 00332 at(size_type theIndex) const 00333 { 00334 invariants(); 00335 00336 return m_data.at(theIndex); 00337 } 00338 00339 reference 00340 at(size_type theIndex) 00341 { 00342 invariants(); 00343 00344 return m_data.at(theIndex); 00345 } 00346 00347 const XalanDOMChar* 00348 c_str() const 00349 { 00350 invariants(); 00351 00352 return m_data.empty() == true ? &s_empty : &m_data[0]; 00353 } 00354 00355 const XalanDOMChar* 00356 data() const 00357 { 00358 invariants(); 00359 00360 return c_str(); 00361 } 00362 00363 void 00364 swap(XalanDOMString& theOther) 00365 { 00366 invariants(); 00367 00368 m_data.swap(theOther.m_data); 00369 00370 #if defined(XALAN_NO_STD_NAMESPACE) 00371 ::swap(m_size, theOther.m_size); 00372 #else 00373 std::swap(m_size, theOther.m_size); 00374 #endif 00375 } 00376 00377 XalanDOMString& 00378 operator+=(const XalanDOMString& theSource) 00379 { 00380 return append(theSource); 00381 } 00382 00383 XalanDOMString& 00384 operator+=(const XalanDOMChar* theString) 00385 { 00386 return append(theString); 00387 } 00388 00389 XalanDOMString& 00390 operator+=(XalanDOMChar theChar) 00391 { 00392 append(1, theChar); 00393 00394 return *this; 00395 } 00396 00397 XalanDOMString& 00398 assign(const XalanDOMChar* theSource) 00399 { 00400 invariants(); 00401 00402 erase(); 00403 00404 invariants(); 00405 00406 return append(theSource); 00407 } 00408 00409 XalanDOMString& 00410 assign( 00411 const XalanDOMChar* theSource, 00412 size_type theCount) 00413 { 00414 invariants(); 00415 00416 erase(); 00417 00418 invariants(); 00419 00420 return append(theSource, theCount); 00421 } 00422 00423 XalanDOMString& 00424 assign(const char* theSource) 00425 { 00426 invariants(); 00427 00428 erase(); 00429 00430 invariants(); 00431 00432 return append(theSource); 00433 } 00434 00435 XalanDOMString& 00436 assign( 00437 const char* theSource, 00438 size_type theCount) 00439 { 00440 invariants(); 00441 00442 erase(); 00443 00444 invariants(); 00445 00446 return append(theSource, theCount); 00447 } 00448 00449 XalanDOMString& 00450 assign( 00451 const XalanDOMString& theSource, 00452 size_type thePosition, 00453 size_type theCount); 00454 00455 XalanDOMString& 00456 assign(const XalanDOMString& theSource) 00457 { 00458 invariants(); 00459 00460 if (&theSource != this) 00461 { 00462 m_data = theSource.m_data; 00463 00464 m_size = theSource.m_size; 00465 } 00466 00467 invariants(); 00468 00469 return *this; 00470 } 00471 00472 XalanDOMString& 00473 assign( 00474 size_type theCount, 00475 XalanDOMChar theChar) 00476 { 00477 invariants(); 00478 00479 erase(); 00480 00481 invariants(); 00482 00483 return append(theCount, theChar); 00484 } 00485 00486 XalanDOMString& 00487 assign( 00488 iterator theFirstPosition, 00489 iterator theLastPosition); 00490 00491 XalanDOMString& 00492 append(const XalanDOMString& theSource) 00493 { 00494 return append(theSource.c_str(), theSource.length()); 00495 } 00496 00497 XalanDOMString& 00498 append( 00499 const XalanDOMString& theSource, 00500 size_type thePosition, 00501 size_type theCount) 00502 { 00503 assert(thePosition < theSource.length() && 00504 (theCount == size_type(npos) || thePosition + theCount <= theSource.length())); 00505 00506 return append(theSource.c_str() + thePosition, theCount); 00507 } 00508 00509 XalanDOMString& 00510 append( 00511 const XalanDOMChar* theString, 00512 size_type theCount); 00513 00514 XalanDOMString& 00515 append(const XalanDOMChar* theString) 00516 { 00517 return append(theString, length(theString)); 00518 } 00519 00520 XalanDOMString& 00521 append( 00522 const char* theString, 00523 size_type theCount); 00524 00525 XalanDOMString& 00526 append(const char* theString) 00527 { 00528 return append(theString, length(theString)); 00529 } 00530 00531 XalanDOMString& 00532 append( 00533 size_type theCount, 00534 XalanDOMChar theChar); 00535 00536 void 00537 push_back(XalanDOMChar theChar) 00538 { 00539 invariants(); 00540 00541 append(1, theChar); 00542 00543 invariants(); 00544 } 00545 00546 XalanDOMString& 00547 insert( 00548 size_type thePosition, 00549 const XalanDOMString& theString) 00550 { 00551 return insert(thePosition, theString.c_str(), theString.length()); 00552 } 00553 00554 XalanDOMString& 00555 insert( 00556 size_type thePosition1, 00557 const XalanDOMString& theString, 00558 size_type thePosition2, 00559 size_type theCount) 00560 { 00561 return insert(thePosition1, theString.c_str() + thePosition2, theCount); 00562 } 00563 00564 XalanDOMString& 00565 insert( 00566 size_type thePosition, 00567 const XalanDOMChar* theString, 00568 size_type theCount); 00569 00570 XalanDOMString& 00571 insert( 00572 size_type thePosition, 00573 const XalanDOMChar* theString) 00574 { 00575 return insert(thePosition, theString, length(theString)); 00576 } 00577 00578 XalanDOMString& 00579 insert( 00580 size_type thePosition, 00581 size_type theCount, 00582 XalanDOMChar theChar); 00583 00584 iterator 00585 insert( 00586 iterator thePosition, 00587 XalanDOMChar theChar); 00588 00589 void 00590 insert( 00591 iterator thePosition, 00592 size_type theCount, 00593 XalanDOMChar theChar); 00594 00595 void 00596 insert( 00597 iterator theInsertPosition, 00598 iterator theFirstPosition, 00599 iterator theLastPosition); 00600 00601 00602 XalanDOMString& 00603 substr( 00604 XalanDOMString& theSubstring, 00605 size_type thePosition = 0, 00606 size_type theCount = size_type(npos)) const 00607 { 00608 assert((theCount == size_type(npos) && thePosition < length() ) || 00609 (thePosition + theCount <= length())); 00610 00611 invariants(); 00612 00613 return theSubstring.assign( 00614 *this, 00615 thePosition, 00616 theCount == npos ? length() : theCount); 00617 } 00618 00619 int 00620 compare(const XalanDOMString& theString) const 00621 { 00622 invariants(); 00623 00624 return compare(theString.c_str()); 00625 } 00626 00627 int 00628 compare( 00629 size_type thePosition1, 00630 size_type theCount1, 00631 const XalanDOMString& theString) const 00632 { 00633 invariants(); 00634 00635 return compare(thePosition1, theCount1, theString.c_str(), theString.length()); 00636 } 00637 00638 int 00639 compare( 00640 size_type thePosition1, 00641 size_type theCount1, 00642 const XalanDOMString& theString, 00643 size_type thePosition2, 00644 size_type theCount2) const 00645 { 00646 invariants(); 00647 00648 return compare(thePosition1, theCount1, theString.c_str() + thePosition2, theCount2); 00649 } 00650 00651 int 00652 compare(const XalanDOMChar* theString) const; 00653 00654 int 00655 compare( 00656 size_type thePosition1, 00657 size_type theCount1, 00658 const XalanDOMChar* theString, 00659 size_type theCount2 = size_type(npos)) const; 00660 00661 00662 void 00663 reset(MemoryManager& theManager, const char* theString); 00664 00665 void 00666 reset(MemoryManager& theManager, const XalanDOMChar* theString); 00667 00668 class TranscodingError : public XalanDOMException 00669 { 00670 public: 00671 00672 TranscodingError() : 00673 XalanDOMException(TRANSCODING_ERR) 00674 { 00675 } 00676 00677 virtual 00678 ~TranscodingError() 00679 { 00680 } 00681 }; 00682 00683 00684 00685 /** 00686 * Transcode the string to the local code page. If the string 00687 * cannot be properly transcoded, and the transcoder can detect 00688 * the error a TranscodingError exception is thrown. 00689 * 00690 * @param theResult A CharVectorType instance for the transcoded string. The string is null-terminated. 00691 */ 00692 void 00693 transcode(CharVectorType& theResult) const; 00694 00695 MemoryManager& 00696 getMemoryManager() 00697 { 00698 return m_data.getMemoryManager(); 00699 } 00700 00701 size_t 00702 hash() const 00703 { 00704 return hash(c_str(), length()); 00705 } 00706 00707 static size_t 00708 hash( 00709 const XalanDOMChar* theString, 00710 size_type theLength) 00711 { 00712 assert(theString != 0); 00713 00714 return hash_non_terminated_array<XalanDOMChar>()(theString, theLength); 00715 } 00716 00717 static bool 00718 equals( 00719 const XalanDOMChar* theLHS, 00720 size_type theLHSLength, 00721 const XalanDOMChar* theRHS, 00722 size_type theRHSLength); 00723 00724 static bool 00725 equals( 00726 const XalanDOMChar* theLHS, 00727 const XalanDOMChar* theRHS) 00728 { 00729 return equals(theLHS, length(theLHS), theRHS, length(theRHS)); 00730 } 00731 00732 static bool 00733 equals( 00734 const XalanDOMString& theLHS, 00735 const XalanDOMString& theRHS); 00736 00737 static bool 00738 equals( 00739 const XalanDOMString& theLHS, 00740 const XalanDOMChar* theRHS) 00741 { 00742 return equals(theLHS.c_str(), theRHS); 00743 } 00744 00745 static bool 00746 equals( 00747 const XalanDOMChar* theLHS, 00748 const XalanDOMString& theRHS) 00749 { 00750 return equals(theLHS, theRHS.c_str()); 00751 } 00752 00753 /* 00754 * Helper function to determine the length of a null- 00755 * terminated string. 00756 * 00757 * @theString The string 00758 * @return the length 00759 */ 00760 static size_type 00761 length(const XalanDOMChar* theString); 00762 00763 /* 00764 * Helper function to determine the length of a null- 00765 * terminated string. 00766 * 00767 * @theString The string 00768 * @return the length 00769 */ 00770 static size_type 00771 length(const char* theString); 00772 00773 protected: 00774 00775 /* 00776 * Function to assert invariant conditions for the class. 00777 * 00778 * @return the iterator 00779 */ 00780 void 00781 invariants() const 00782 { 00783 #if !defined(NDEBUG) 00784 assert((m_data.empty() == true && m_size == 0) || m_size == m_data.size() - 1); 00785 assert(m_data.empty() == true || m_data.back() == 0); 00786 #endif 00787 } 00788 00789 /* 00790 * Get an iterator to the position of the terminating null. 00791 * 00792 * @return the iterator 00793 */ 00794 iterator 00795 getBackInsertIterator() 00796 { 00797 invariants(); 00798 00799 return m_data.empty() == true ? m_data.end() : m_data.end() - 1; 00800 } 00801 00802 const_iterator 00803 getBackInsertIterator() const 00804 { 00805 invariants(); 00806 00807 return m_data.empty() == true ? m_data.end() : m_data.end() - 1; 00808 } 00809 00810 iterator 00811 getIteratorForPosition(size_type thePosition) 00812 { 00813 invariants(); 00814 00815 return m_data.begin() + thePosition; 00816 } 00817 00818 const_iterator 00819 getIteratorForPosition(size_type thePosition) const 00820 { 00821 invariants(); 00822 00823 return m_data.begin() + thePosition; 00824 } 00825 00826 #if defined (XALAN_DEVELOPMENT) 00827 // not defined 00828 XalanDOMString(); 00829 XalanDOMString(const XalanDOMString&); 00830 #endif 00831 00832 private: 00833 00834 00835 XalanDOMCharVectorType m_data; 00836 00837 size_type m_size; 00838 00839 static const XalanDOMChar s_empty; 00840 }; 00841 00842 00843 00844 /** 00845 * Hash functor for DOMStrings 00846 * 00847 * @param theKey XalanDOMString to be hashed 00848 * @return hash value for XalanDOMString 00849 */ 00850 struct DOMStringHashFunction : public XALAN_STD_QUALIFIER unary_function<const XalanDOMString&, size_t> 00851 { 00852 result_type 00853 operator() (argument_type theKey) const 00854 { 00855 return theKey.hash(); 00856 } 00857 }; 00858 00859 00860 00861 /** 00862 * Hash functor for DOMStrings 00863 * 00864 * @param theKey XalanDOMString to be hashed 00865 * @return hash value for XalanDOMString 00866 */ 00867 struct DOMStringPointerHashFunction : public XALAN_STD_QUALIFIER unary_function<const XalanDOMString*, size_t> 00868 { 00869 result_type 00870 operator() (argument_type theKey) const 00871 { 00872 assert (theKey != 0); 00873 00874 return theKey->hash(); 00875 } 00876 }; 00877 00878 00879 00880 template<> 00881 struct XalanMapKeyTraits<XalanDOMString*> 00882 { 00883 typedef DOMStringPointerHashFunction Hasher; 00884 typedef pointer_equal<XalanDOMString> Comparator; 00885 }; 00886 00887 template<> 00888 struct XalanMapKeyTraits<const XalanDOMString*> 00889 { 00890 typedef DOMStringPointerHashFunction Hasher; 00891 typedef pointer_equal<XalanDOMString> Comparator; 00892 }; 00893 00894 00895 /** 00896 * Equals functor for DOMStrings 00897 * 00898 * @param theLHS first string to compare 00899 * @param theRHS second string to compare 00900 * @return true if the contents of both strings are identical 00901 */ 00902 #if defined(XALAN_NO_STD_NAMESPACE) 00903 struct DOMStringEqualsFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 00904 #else 00905 struct DOMStringEqualsFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 00906 #endif 00907 { 00908 result_type 00909 operator() (first_argument_type theLHS, 00910 second_argument_type theRHS) const 00911 { 00912 return XalanDOMString::equals(theLHS, theRHS); 00913 } 00914 }; 00915 00916 00917 00918 /** 00919 * Not equals functor for DOMStrings 00920 * 00921 * @param theLHS first string to compare 00922 * @param theRHS second string to compare 00923 * @return true if the contents of both strings are identical 00924 */ 00925 #if defined(XALAN_NO_STD_NAMESPACE) 00926 struct DOMStringNotEqualsFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 00927 #else 00928 struct DOMStringNotEqualsFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 00929 #endif 00930 { 00931 result_type 00932 operator() (first_argument_type theLHS, 00933 second_argument_type theRHS) const 00934 { 00935 return !XalanDOMString::equals(theLHS, theRHS); 00936 } 00937 }; 00938 00939 00940 00941 /** 00942 * Less than functor for DOMStrings 00943 * 00944 * @param theLHS first string to compare 00945 * @param theRHS second string to compare 00946 * @return true if the theLHS is less than theRHSl 00947 */ 00948 #if defined(XALAN_NO_STD_NAMESPACE) 00949 struct DOMStringLessThanFunction : public binary_function<const XalanDOMString&, const XalanDOMString&, bool> 00950 #else 00951 struct DOMStringLessThanFunction : public std::binary_function<const XalanDOMString&, const XalanDOMString&, bool> 00952 #endif 00953 { 00954 result_type 00955 operator() (first_argument_type theLHS, 00956 second_argument_type theRHS) const 00957 { 00958 return theLHS.compare(theRHS) < 0 ? true : false; 00959 } 00960 }; 00961 00962 00963 /** 00964 * Equal to functor for DOMStrings 00965 * 00966 * @param theLHS first string to compare 00967 * @param theRHS second string to compare 00968 * @return true if the theLHS is equal to theRHS 00969 */ 00970 struct DOMStringPointerEqualToFunction : public XALAN_STD_QUALIFIER binary_function<const XalanDOMString*, const XalanDOMString*, bool> 00971 { 00972 result_type 00973 operator() (first_argument_type theLHS, 00974 second_argument_type theRHS) const 00975 { 00976 assert(theLHS != 0 && theRHS != 0); 00977 00978 return XalanDOMString::equals(*theLHS, *theRHS); 00979 } 00980 }; 00981 00982 00983 /** 00984 * Less than functor for DOMStrings 00985 * 00986 * @param theLHS first string to compare 00987 * @param theRHS second string to compare 00988 * @return true if the theLHS is less than theRHSl 00989 */ 00990 #if defined(XALAN_NO_STD_NAMESPACE) 00991 struct DOMStringPointerLessThanFunction : public binary_function<const XalanDOMString*, const XalanDOMString*, bool> 00992 #else 00993 struct DOMStringPointerLessThanFunction : public std::binary_function<const XalanDOMString*, const XalanDOMString*, bool> 00994 #endif 00995 { 00996 result_type 00997 operator() (first_argument_type theLHS, 00998 second_argument_type theRHS) const 00999 { 01000 assert(theLHS != 0 && theRHS != 0); 01001 01002 return theLHS->compare(*theRHS) < 0 ? true : false; 01003 } 01004 }; 01005 01006 01007 01008 template<> 01009 struct XalanMapKeyTraits<XalanDOMString> 01010 { 01011 typedef DOMStringHashFunction Hasher; 01012 typedef XALAN_STD_QUALIFIER equal_to<XalanDOMString> Comparator; 01013 }; 01014 01015 01016 01017 inline bool 01018 operator==( 01019 const XalanDOMString& theLHS, 01020 const XalanDOMString& theRHS) 01021 { 01022 return XalanDOMString::equals(theLHS, theRHS); 01023 } 01024 01025 01026 01027 inline bool 01028 operator==( 01029 const XalanDOMString& theLHS, 01030 const XalanDOMChar* theRHS) 01031 { 01032 return XalanDOMString::equals(theLHS, theRHS); 01033 } 01034 01035 01036 01037 inline bool 01038 operator==( 01039 const XalanDOMChar* theLHS, 01040 const XalanDOMString& theRHS) 01041 { 01042 // Note reversing of operands... 01043 return XalanDOMString::equals(theLHS, theRHS); 01044 } 01045 01046 01047 01048 inline bool 01049 operator!=( 01050 const XalanDOMString& theLHS, 01051 const XalanDOMString& theRHS) 01052 { 01053 return !(theLHS == theRHS); 01054 } 01055 01056 01057 01058 inline bool 01059 operator!=( 01060 const XalanDOMChar* theLHS, 01061 const XalanDOMString& theRHS) 01062 { 01063 return !(theLHS == theRHS); 01064 } 01065 01066 01067 01068 inline bool 01069 operator!=( 01070 const XalanDOMString& theLHS, 01071 const XalanDOMChar* theRHS) 01072 { 01073 return !(theRHS == theLHS); 01074 } 01075 01076 01077 #if 0 01078 inline XalanDOMString& 01079 add( 01080 const XalanDOMString& theLHS, 01081 const XalanDOMString& theRHS, 01082 XalanDOMString& result) 01083 { 01084 result.assign(theLHS); 01085 01086 return result += theRHS; 01087 } 01088 01089 01090 01091 inline XalanDOMString& 01092 add( 01093 const XalanDOMString& theLHS, 01094 const XalanDOMChar* theRHS, 01095 XalanDOMString& result) 01096 { 01097 result.assign(theLHS); 01098 01099 return result += theRHS; 01100 } 01101 01102 01103 01104 inline XalanDOMString& 01105 add( 01106 const XalanDOMChar* theLHS, 01107 const XalanDOMString& theRHS, 01108 XalanDOMString& result) 01109 { 01110 result.assign(theLHS); 01111 01112 return result += theRHS; 01113 } 01114 01115 01116 01117 inline const XalanDOMString& 01118 add( 01119 const char* theLHS, 01120 const XalanDOMString& theRHS, 01121 XalanDOMString& result) 01122 { 01123 result.assign(theLHS); 01124 01125 result.append(theRHS); 01126 01127 return result; 01128 } 01129 01130 01131 01132 inline const XalanDOMString& 01133 add( 01134 const XalanDOMString& theLHS, 01135 const char* theRHS, 01136 XalanDOMString& result) 01137 { 01138 result.assign(theLHS); 01139 01140 result.append(theRHS); 01141 01142 return result; 01143 } 01144 #endif 01145 01146 01147 // Standard vector of XalanDOMChars and chars 01148 typedef XalanVector<XalanDOMChar> XalanDOMCharVectorType; 01149 01150 typedef XalanVector<char> CharVectorType; 01151 01152 01153 01154 01155 01156 /** 01157 * Convert a XalanDOMChar string to C++ standard library 01158 * vector, transcoding to the default local code 01159 * page. 01160 * 01161 * @param sourceString The source string 01162 * @param sourceStringLength The source string length. 01163 * @param targetVector The target string 01164 * @param terminate If true, the transcoded string will be null-terminated 01165 * @return true if successful, false if not. 01166 */ 01167 XALAN_DOM_EXPORT_FUNCTION(bool) 01168 TranscodeToLocalCodePage( 01169 const XalanDOMChar* theSourceString, 01170 XalanDOMString::size_type theSourceStringLength, 01171 CharVectorType& targetVector, 01172 bool terminate = false); 01173 01174 /** 01175 * Convert a XalanDOMChar string to C++ standard library 01176 * vector, transcoding to the default local code 01177 * page. If the source string contines code points, that can't be 01178 * represented in the local code page, the substitution character will be used 01179 * 01180 * @param sourceString The source string 01181 * @param sourceStringLength The source string length. 01182 * @param targetVector The target string 01183 * @param terminate If true, the transcoded string will be null-terminated 01184 * @param theSubstitutionChar The substitution character for code points that are not presentable 01185 * in the local page 01186 */ 01187 XALAN_DOM_EXPORT_FUNCTION(void) 01188 TranscodeToLocalCodePage( 01189 const XalanDOMChar* theSourceString, 01190 XalanDOMString::size_type theSourceStringLength, 01191 CharVectorType& targetVector, 01192 bool terminate, 01193 char theSubstitutionChar); 01194 01195 /** 01196 * Convert a string to a XalanDOMString, transcoding from 01197 * the default local code page. 01198 * 01199 * @param theSourceString The source string 01200 * @param theSourceStringLength The source string length. 01201 * @return The new string. 01202 */ 01203 #if !defined(XALAN_DEVELOPMENT) 01204 inline const XalanDOMString 01205 TranscodeFromLocalCodePage( 01206 const char* theSourceString, 01207 XalanDOMString::size_type theSourceStringLength = XalanDOMString::npos) 01208 { 01209 return XalanDOMString(theSourceString,XalanMemMgrs::getDefaultXercesMemMgr(), theSourceStringLength); 01210 } 01211 #endif 01212 01213 01214 /** 01215 * Convert a XalanDOMChar string to C++ standard library 01216 * vector, transcoding to the default local code 01217 * page. The string _must_ be null-terminated. 01218 * 01219 * @param theSourceString The source string 01220 * @param targetVector The target string 01221 * @param terminate If true, the transcoded string will be null-terminated 01222 * @return true if successful, false if not. 01223 */ 01224 XALAN_DOM_EXPORT_FUNCTION(bool) 01225 TranscodeToLocalCodePage( 01226 const XalanDOMChar* theSourceString, 01227 CharVectorType& targetVector, 01228 bool terminate = false); 01229 01230 /** 01231 * Convert a XalanDOMChar string to C++ standard library 01232 * vector, transcoding to the default local code 01233 * page. The string _must_ be null-terminated. 01234 * 01235 * @param theSourceString The source string 01236 * @param targetVector The target string 01237 * @param terminate If true, the transcoded string will be null-terminated 01238 */ 01239 XALAN_DOM_EXPORT_FUNCTION(void) 01240 TranscodeToLocalCodePage( 01241 const XalanDOMChar* theSourceString, 01242 CharVectorType& targetVector, 01243 bool terminate, 01244 char theSubstitutionChar); 01245 01246 /** 01247 * Convert XalanDOMString to C++ standard library 01248 * vector, transcoding to the default local code 01249 * page. Null-terminate the sttring... 01250 * 01251 * @param theSourceString source string 01252 * @return The transcoded string. 01253 */ 01254 #if !defined(XALAN_DEVELOPMENT) 01255 inline const CharVectorType 01256 TranscodeToLocalCodePage(const XalanDOMChar* theSourceString) 01257 { 01258 CharVectorType theResult; 01259 01260 TranscodeToLocalCodePage(theSourceString, theResult, true, '?'); 01261 01262 return theResult; 01263 } 01264 #endif 01265 01266 01267 /** 01268 * Convert XalanDOMString to C++ standard library 01269 * vector, transcoding to the default local code 01270 * page. 01271 * 01272 * @param theSourceString The source string 01273 * @param theTargetVector The target string 01274 * @return true if successful, false if not. 01275 */ 01276 inline bool 01277 TranscodeToLocalCodePage( 01278 const XalanDOMString& theSourceString, 01279 CharVectorType& theTargetVector, 01280 bool terminate = false) 01281 { 01282 return TranscodeToLocalCodePage( 01283 theSourceString.c_str(), 01284 theTargetVector, 01285 terminate); 01286 } 01287 01288 /** 01289 * Convert XalanDOMString to C++ standard library 01290 * vector, transcoding to the default local code 01291 * page. 01292 * 01293 * @param theSourceString The source string 01294 * @param targetVector The target string 01295 * @param terminate If true, the transcoded string will be null-terminated 01296 * @param theSubstitutionChar The substitution character for code points that are not presentable 01297 * in the local page 01298 */ 01299 XALAN_DOM_EXPORT_FUNCTION(void) 01300 TranscodeToLocalCodePage( 01301 const XalanDOMString& theSourceString, 01302 CharVectorType& theTargetVector, 01303 bool terminate, 01304 char theSubstitutionChar); 01305 01306 01307 01308 /** 01309 * Convert XalanDOMString to C++ standard library 01310 * vector, transcoding to the default local code 01311 * page. 01312 * 01313 * @param thetheSourceString source string 01314 * @return The transcoded string. 01315 */ 01316 #if !defined(XALAN_DEVELOPMENT) 01317 inline const CharVectorType 01318 TranscodeToLocalCodePage(const XalanDOMString& theSourceString) 01319 { 01320 CharVectorType theResult; 01321 01322 TranscodeToLocalCodePage(theSourceString.c_str(), theResult, true, '?'); 01323 01324 return theResult; 01325 } 01326 #endif 01327 01328 01329 /** 01330 * Convert a string to a XalanDOMString, transcoding from 01331 * the default local code page. 01332 * 01333 * @param theSourceString The source string 01334 * @param theResult The result. 01335 * @param theSourceStringLength The source string length. 01336 * @return The new string. 01337 */ 01338 inline const XalanDOMString& 01339 TranscodeFromLocalCodePage( 01340 const char* theSourceString, 01341 XalanDOMString& theResult, 01342 XalanDOMString::size_type theSourceStringLength = XalanDOMString::npos) 01343 { 01344 theResult.assign(theSourceString, theSourceStringLength); 01345 01346 return theResult; 01347 } 01348 01349 01350 01351 /** 01352 * Convert a string to a C++ standard library 01353 * vector, transcoding from the default local code 01354 * page. 01355 * 01356 * @param theSourceString The source string 01357 * @param theSourceStringLength The source string length. 01358 * @param targetVector The target string 01359 * @param terminate If true, the transcoded string will be null-terminated 01360 * @return true if successful, false if not. 01361 */ 01362 XALAN_DOM_EXPORT_FUNCTION(bool) 01363 TranscodeFromLocalCodePage( 01364 const char* theSourceString, 01365 XalanDOMString::size_type theSourceStringLength, 01366 XalanDOMCharVectorType& theTargetVector, 01367 bool terminate = false); 01368 01369 /** 01370 * Convert a string to a C++ standard library 01371 * vector, transcoding from the default local code 01372 * page. The string _must_ be null-terminated. 01373 * 01374 * @param sourceString The source string 01375 * @param targetVector The target string 01376 * @param terminate If true, the transcoded string will be null-terminated 01377 * @return true if successful, false if not. 01378 */ 01379 XALAN_DOM_EXPORT_FUNCTION(bool) 01380 TranscodeFromLocalCodePage( 01381 const char* theSourceString, 01382 XalanDOMCharVectorType& theTargetVector, 01383 bool terminate = false); 01384 01385 /** 01386 * Convert a string to a C++ standard library 01387 * vector, transcoding from the default local code 01388 * page. 01389 * 01390 * @param theSourceString The source string 01391 * @param theSourceStringLength The source string length. 01392 * @param theSourceStringIsNullTerminated true if the source string is null-terminated, otherwise false. 01393 * @param targetVector The target string 01394 * @param terminate If true, the transcoded string will be null-terminated 01395 * @return true if successful, false if not. 01396 */ 01397 XALAN_DOM_EXPORT_FUNCTION(bool) 01398 TranscodeFromLocalCodePage( 01399 const char* theSourceString, 01400 XalanDOMString::size_type theSourceStringLength, 01401 bool theSourceStringIsNullTerminated, 01402 XalanDOMCharVectorType& theTargetVector, 01403 bool terminate = false); 01404 01405 /** 01406 * Convert a vector of characters to a XalanDOMString, 01407 * transcoding from the default local code 01408 * 01409 * @param theSourceString The source vector. 01410 * @param theResult The result. 01411 * @return The transcoded string. 01412 */ 01413 XALAN_DOM_EXPORT_FUNCTION(const XalanDOMString&) 01414 TranscodeFromLocalCodePage( 01415 const CharVectorType& theSourceString, 01416 XalanDOMString& theResult); 01417 01418 01419 XALAN_USES_MEMORY_MANAGER(XalanDOMString) 01420 01421 01422 01423 XALAN_CPP_NAMESPACE_END 01424 01425 01426 01427 #endif // !defined(XALANDOMSTRING_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.11 |
|