| API Docs for SAX and DOM |

Main Page | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members | Related Pages

# XMLString.hpp

Go to the documentation of this file.

    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
    00017 /*
    00018  * $Log$
    00019  * Revision 1.34  2005/04/05 17:00:45  cargilld
    00020  * Implement version of lowercase that only check a to z, instead of all characters, and don't rely on functionality provided in the transcoders.
    00021  *
    00022  * Revision 1.33  2005/03/20 19:02:45  cargilld
    00023  * Implement versions of uppercase and compareIstring that only check a to z, instead of all characters, and don't rely on functionality provided in the transcoders.
    00024  *
    00025  * Revision 1.32  2005/03/08 09:04:09  amassari
    00026  * Improve performances of XMLString::tokenizeString (jira# 1363) - patch by Christian Will
    00027  *
    00028  * Revision 1.31  2004/12/21 16:02:51  cargilld
    00029  * Attempt to fix various apidoc problems.
    00030  *
    00031  * Revision 1.30  2004/12/14 02:09:20  cargilld
    00032  * Performance update from Christian Will.
    00033  *
    00034  * Revision 1.29  2004/12/06 10:47:01  amassari
    00035  * Added XMLString::release(void**, MemoryManager*) [jira# 1301]
    00036  *
    00037  * Revision 1.28  2004/09/08 13:56:24  peiyongz
    00038  * Apache License Version 2.0
    00039  *
    00040  * Revision 1.27  2004/09/02 19:08:09  cargilld
    00041  * Fix API Doc warning message
    00042  *
    00043  * Revision 1.26  2004/08/11 16:07:27  peiyongz
    00044  * isValidNOTATION
    00045  *
    00046  * Revision 1.25  2004/05/25 18:11:32  peiyongz
    00047  * removeChar() added
    00048  *
    00049  * Revision 1.24  2004/03/10 17:35:17  amassari
    00050  * Fix documentation for binToText (bug# 9207)
    00051  *
    00052  * Revision 1.23  2003/12/24 15:24:13  cargilld
    00053  * More updates to memory management so that the static memory manager.
    00054  *
    00055  * Revision 1.22  2003/12/17 20:00:49  cargilld
    00056  * Update for memory management so that the static memory manager (one
    00057  * used to call Initialize) is only for static data.
    00058  *
    00059  * Revision 1.21  2003/12/17 00:18:35  cargilld
    00060  * Update to memory management so that the static memory manager (one used to call Initialize) is only for static data.
    00061  *
    00062  * Revision 1.20  2003/10/02 11:07:26  gareth
    00063  * Made the non-memory manager version of replicate not inlined. Updated the documentation for the memory manager versions so they don't tell you you should call release.
    00064  *
    00065  * Revision 1.19  2003/10/01 00:22:20  knoaman
    00066  * Add a lastIndexOf method that takes the string length as one of the params.
    00067  *
    00068  * Revision 1.18  2003/08/25 20:39:47  neilg
    00069  * fix XMLString::findAny(...) docs so that they match what the method actually does (and has done since time immemorial)
    00070  *
    00071  * Revision 1.17  2003/05/18 14:02:05  knoaman
    00072  * Memory manager implementation: pass per instance manager.
    00073  *
    00074  * Revision 1.16  2003/05/15 19:07:46  knoaman
    00075  * Partial implementation of the configurable memory manager.
    00076  *
    00077  * Revision 1.15  2003/04/21 20:07:05  knoaman
    00078  * Performance: use memcpy in moveChars and replicate.
    00079  *
    00080  * Revision 1.14  2003/02/25 16:42:31  tng
    00081  * [Bug 7072] Documentation for XMLString::transcode states invalid return value.
    00082  *
    00083  * Revision 1.13  2003/02/05 18:50:56  tng
    00084  * [Bug 11915] Utility for freeing memory.
    00085  *
    00086  * Revision 1.12  2003/01/24 23:16:33  peiyongz
    00087  * removeWS() added;
    00088  *
    00089  * Revision 1.11  2002/12/20 22:10:21  tng
    00090  * XML 1.1
    00091  *
    00092  * Revision 1.10  2002/12/18 14:17:54  gareth
    00093  * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
    00094  *
    00095  * Revision 1.9  2002/12/04 02:32:43  knoaman
    00096  * #include cleanup.
    00097  *
    00098  * Revision 1.8  2002/11/05 17:42:39  peiyongz
    00099  * equals( const char* const, const char* const)
    00100  *
    00101  * Revision 1.7  2002/11/04 15:22:05  tng
    00102  * C++ Namespace Support.
    00103  *
    00104  * Revision 1.6  2002/10/01 19:45:22  tng
    00105  * Performance in XMLString::equals, only need to check one string for null as they are equal already.
    00106  *
    00107  * Revision 1.5  2002/09/24 19:41:21  tng
    00108  * New inline function equals that is modified from compareString but simply return true or false.
    00109  *
    00110  * Revision 1.4  2002/09/23 18:42:18  tng
    00111  * DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path filename to standard URI form.
    00112  *
    00113  * Revision 1.3  2002/08/27 19:24:43  peiyongz
    00114  * Bug#12087: patch from Thomas Ford (tom@decisionsoft.com)
    00115  *
    00116  * Revision 1.2  2002/02/20 18:17:02  tng
    00117  * [Bug 5977] Warnings on generating apiDocs.
    00118  *
    00119  * Revision 1.1.1.1  2002/02/01 22:22:16  peiyongz
    00120  * sane_include
    00121  *
    00122  * Revision 1.26  2001/08/10 16:23:06  peiyongz
    00123  * isHex(), isAlphaNum(), isAllWhiteSpace() and patternMatch() Added
    00124  *
    00125  * Revision 1.25  2001/07/06 20:27:57  peiyongz
    00126  * isValidaQName()
    00127  *
    00128  * Revision 1.24  2001/07/04 14:38:20  peiyongz
    00129  * IDDatatypeValidator: created
    00130  * DatatypeValidatorFactory: IDDTV enabled
    00131  * XMLString:isValidName(): to validate Name (XML [4][5])
    00132  *
    00133  * Revision 1.23  2001/06/13 14:07:55  peiyongz
    00134  * isValidaEncName() to validate an encoding name (EncName)
    00135  *
    00136  * Revision 1.22  2001/05/23 15:44:51  tng
    00137  * Schema: NormalizedString fix.  By Pei Yong Zhang.
    00138  *
    00139  * Revision 1.21  2001/05/11 13:26:31  tng
    00140  * Copyright update.
    00141  *
    00142  * Revision 1.20  2001/05/09 18:43:30  tng
    00143  * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
    00144  *
    00145  * Revision 1.19  2001/05/03 20:34:35  tng
    00146  * Schema: SchemaValidator update
    00147  *
    00148  * Revision 1.18  2001/05/03 19:17:35  knoaman
    00149  * TraverseSchema Part II.
    00150  *
    00151  * Revision 1.17  2001/03/21 21:56:13  tng
    00152  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
    00153  *
    00154  * Revision 1.16  2001/03/02 20:52:46  knoaman
    00155  * Schema: Regular expression - misc. updates for error messages,
    00156  * and additions of new functions to XMLString class.
    00157  *
    00158  * Revision 1.15  2001/01/15 21:26:34  tng
    00159  * Performance Patches by David Bertoni.
    00160  *
    00161  * Details: (see xerces-c-dev mailing Jan 14)
    00162  * XMLRecognizer.cpp: the internal encoding string XMLUni::fgXMLChEncodingString
    00163  * was going through this function numerous times.  As a result, the top hot-spot
    00164  * for the parse was _wcsicmp().  The real problem is that the Microsofts wide string
    00165  * functions are unbelievably slow.  For things like encodings, it might be
    00166  * better to use a special comparison function that only considers a-z and
    00167  * A-Z as characters with case.  This works since the character set for
    00168  * encodings is limit to printable ASCII characters.
    00169  *
    00170  *  XMLScanner2.cpp: This also has some case-sensitive vs. insensitive compares.
    00171  * They are also much faster.  The other tweak is to only make a copy of an attribute
    00172  * string if it needs to be split.  And then, the strategy is to try to use a
    00173  * stack-based buffer, rather than a dynamically-allocated one.
    00174  *
    00175  * SAX2XMLReaderImpl.cpp: Again, more case-sensitive vs. insensitive comparisons.
    00176  *
    00177  * KVStringPair.cpp & hpp: By storing the size of the allocation, the storage can
    00178  * likely be re-used many times, cutting down on dynamic memory allocations.
    00179  *
    00180  * XMLString.hpp: a more efficient implementation of stringLen().
    00181  *
    00182  * DTDValidator.cpp: another case of using a stack-based buffer when possible
    00183  *
    00184  * These patches made a big difference in parse time in some of our test
    00185  * files, especially the ones are very attribute-heavy.
    00186  *
    00187  * Revision 1.14  2000/10/13 22:47:57  andyh
    00188  * Fix bug (failure to null-terminate result) in XMLString::trim().
    00189  * Patch contributed by Nadav Aharoni
    00190  *
    00191  * Revision 1.13  2000/04/12 18:42:15  roddey
    00192  * Improved docs in terms of what 'max chars' means in the method
    00193  * parameters.
    00194  *
    00195  * Revision 1.12  2000/04/06 19:42:51  rahulj
    00196  * Clarified how big the target buffer should be in the API
    00197  * documentation.
    00198  *
    00199  * Revision 1.11  2000/03/23 01:02:38  roddey
    00200  * Updates to the XMLURL class to correct a lot of parsing problems
    00201  * and to add support for the port number. Updated the URL tests
    00202  * to test some of this new stuff.
    00203  *
    00204  * Revision 1.10  2000/03/20 23:00:46  rahulj
    00205  * Moved the inline definition of stringLen before the first
    00206  * use. This satisfied the HP CC compiler.
    00207  *
    00208  * Revision 1.9  2000/03/02 19:54:49  roddey
    00209  * This checkin includes many changes done while waiting for the
    00210  * 1.1.0 code to be finished. I can't list them all here, but a list is
    00211  * available elsewhere.
    00212  *
    00213  * Revision 1.8  2000/02/24 20:05:26  abagchi
    00214  * Swat for removing Log from API docs
    00215  *
    00216  * Revision 1.7  2000/02/16 18:51:52  roddey
    00217  * Fixed some facts in the docs and reformatted the docs to stay within
    00218  * a reasonable line width.
    00219  *
    00220  * Revision 1.6  2000/02/16 17:07:07  abagchi
    00221  * Added API docs
    00222  *
    00223  * Revision 1.5  2000/02/06 07:48:06  rahulj
    00224  * Year 2K copyright swat.
    00225  *
    00226  * Revision 1.4  2000/01/12 00:16:23  roddey
    00227  * Changes to deal with multiply nested, relative pathed, entities and to deal
    00228  * with the new URL class changes.
    00229  *
    00230  * Revision 1.3  1999/12/18 00:18:10  roddey
    00231  * More changes to support the new, completely orthagonal support for
    00232  * intrinsic encodings.
    00233  *
    00234  * Revision 1.2  1999/12/15 19:41:28  roddey
    00235  * Support for the new transcoder system, where even intrinsic encodings are
    00236  * done via the same transcoder abstraction as external ones.
    00237  *
    00238  * Revision 1.1.1.1  1999/11/09 01:05:52  twl
    00239  * Initial checkin
    00240  *
    00241  * Revision 1.2  1999/11/08 20:45:21  rahul
    00242  * Swat for adding in Product name and CVS comment log variable.
    00243  *
    00244  */
    00245
    00246 #if !defined(XMLSTRING_HPP)
    00247 #define XMLSTRING_HPP
    00248
    00249 #include <xercesc/util/BaseRefVectorOf.hpp>
    00250 #include <xercesc/framework/XMLBuffer.hpp>
    00251 #include <xercesc/framework/MemoryManager.hpp>
    00252 #include <string.h>
    00253 #include <assert.h>
    00254
    00255 XERCES_CPP_NAMESPACE_BEGIN
    00256
    00257 class XMLLCPTranscoder;
    00269 class  XMLString
    00270 {
    00271 public:
    00272     /* Static methods for native character mode string manipulation */
    00273
    00274
    00291     static void catString
    00292     (
    00293                 char* const     target
    00294         , const char* const     src
    00295     );
    00296
    00309     static void catString
    00310     (
    00311                 XMLCh* const    target
    00312         , const XMLCh* const    src
    00313     );
    00315
    00329     static int compareIString
    00330     (
    00331         const   char* const     str1
    00332         , const char* const     str2
    00333     );
    00334
    00345     static int compareIString
    00346     (
    00347         const   XMLCh* const    str1
    00348         , const XMLCh* const    str2
    00349     );
    00350
    00362     static int compareIStringASCII
    00363     (
    00364         const   XMLCh* const    str1
    00365         , const XMLCh* const    str2
    00366     );
    00367
    00368
    00369
    00383     static int compareNString
    00384     (
    00385         const   char* const     str1
    00386         , const char* const     str2
    00387         , const unsigned int    count
    00388     );
    00389
    00403     static int compareNString
    00404     (
    00405         const   XMLCh* const    str1
    00406         , const XMLCh* const    str2
    00407         , const unsigned int    count
    00408     );
    00409
    00410
    00424     static int compareNIString
    00425     (
    00426         const   char* const     str1
    00427         , const char* const     str2
    00428         , const unsigned int    count
    00429     );
    00430
    00445     static int compareNIString
    00446     (
    00447         const   XMLCh* const    str1
    00448         , const XMLCh* const    str2
    00449         , const unsigned int    count
    00450     );
    00451
    00464     static int compareString
    00465     (
    00466         const   char* const     str1
    00467         , const char* const     str2
    00468     );
    00469
    00481     static int compareString
    00482     (
    00483         const   XMLCh* const    str1
    00484         , const XMLCh* const    str2
    00485     );
    00486
    00495     static bool equals
    00496     (
    00497           const XMLCh* const    str1
    00498         , const XMLCh* const    str2
    00499     );
    00500
    00501     static bool equals
    00502     (
    00503           const char* const    str1
    00504         , const char* const    str2
    00505     );
    00506
    00533     static bool regionMatches
    00534     (
    00535         const   XMLCh* const    str1
    00536         , const int             offset1
    00537         , const XMLCh* const    str2
    00538         , const int             offset2
    00539         , const unsigned int    charCount
    00540     );
    00541
    00569     static bool regionIMatches
    00570     (
    00571         const   XMLCh* const    str1
    00572         , const int             offset1
    00573         , const XMLCh* const    str2
    00574         , const int             offset2
    00575         , const unsigned int    charCount
    00576     );
    00578
    00591     static void copyString
    00592     (
    00593                 char* const     target
    00594         , const char* const     src
    00595     );
    00596
    00607     static void copyString
    00608     (
    00609                 XMLCh* const    target
    00610         , const XMLCh* const    src
    00611     );
    00612
    00625     static bool copyNString
    00626     (
    00627                 XMLCh* const    target
    00628         , const XMLCh* const    src
    00629         , const unsigned int    maxChars
    00630     );
    00632
    00642     static unsigned int hash
    00643     (
    00644         const   char* const     toHash
    00645         , const unsigned int    hashModulus
    00646         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00647     );
    00648
    00656     static unsigned int hash
    00657     (
    00658         const   XMLCh* const    toHash
    00659         , const unsigned int    hashModulus
    00660         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00661     );
    00662
    00672     static unsigned int hashN
    00673     (
    00674         const   XMLCh* const    toHash
    00675         , const unsigned int    numChars
    00676         , const unsigned int    hashModulus
    00677         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00678     );
    00679
    00681
    00692     static int indexOf(const char* const toSearch, const char ch);
    00693
    00702     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
    00703
    00715     static int indexOf
    00716     (
    00717         const   char* const     toSearch
    00718         , const char            chToFind
    00719         , const unsigned int    fromIndex
    00720         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00721     );
    00722
    00734     static int indexOf
    00735     (
    00736         const   XMLCh* const    toSearch
    00737         , const XMLCh           chToFind
    00738         , const unsigned int    fromIndex
    00739         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00740     );
    00741
    00750     static int lastIndexOf(const char* const toSearch, const char ch);
    00751
    00760     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
    00761
    00771     static int lastIndexOf
    00772     (
    00773         const XMLCh ch
    00774         , const XMLCh* const toSearch
    00775         , const unsigned int toSearchLen
    00776     );
    00777
    00789     static int lastIndexOf
    00790     (
    00791         const   char* const     toSearch
    00792         , const char            chToFind
    00793         , const unsigned int    fromIndex
    00794         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00795     );
    00796
    00808     static int lastIndexOf
    00809     (
    00810         const   XMLCh* const    toSearch
    00811         , const XMLCh           ch
    00812         , const unsigned int    fromIndex
    00813         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00814     );
    00816
    00824     static void moveChars
    00825     (
    00826                 XMLCh* const    targetStr
    00827         , const XMLCh* const    srcStr
    00828         , const unsigned int    count
    00829     );
    00830
    00832
    00844     static void subString
    00845     (
    00846                 char* const    targetStr
    00847         , const char* const    srcStr
    00848         , const int            startIndex
    00849         , const int            endIndex
    00850         , MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager
    00851     );
    00852
    00862     static void subString
    00863     (
    00864                 XMLCh* const    targetStr
    00865         , const XMLCh* const    srcStr
    00866         , const int             startIndex
    00867         , const int             endIndex
    00868         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00869     );
    00870
    00881     static void subString
    00882     (
    00883                 XMLCh* const    targetStr
    00884         , const XMLCh* const    srcStr
    00885         , const int             startIndex
    00886         , const int             endIndex
    00887         , const int             srcStrLength
    00888         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    00889     );
    00890
    00892
    00904     static char* replicate(const char* const toRep);
    00905
    00914     static char* replicate(const char* const toRep,
    00915                            MemoryManager* const manager);
    00916
    00926     static XMLCh* replicate(const XMLCh* const toRep);
    00927
    00936     static XMLCh* replicate(const XMLCh* const toRep,
    00937                             MemoryManager* const manager);
    00938
    00940
    00949     static bool startsWith
    00950     (
    00951         const   char* const     toTest
    00952         , const char* const     prefix
    00953     );
    00954
    00961     static bool startsWith
    00962     (
    00963         const   XMLCh* const    toTest
    00964         , const XMLCh* const    prefix
    00965     );
    00966
    00975     static bool startsWithI
    00976     (
    00977         const   char* const     toTest
    00978         , const char* const     prefix
    00979     );
    00980
    00990     static bool startsWithI
    00991     (
    00992         const   XMLCh* const    toTest
    00993         , const XMLCh* const    prefix
    00994     );
    00995
    01002     static bool endsWith
    01003     (
    01004         const   XMLCh* const    toTest
    01005         , const XMLCh* const    suffix
    01006     );
    01007
    01008
    01017     static const XMLCh* findAny
    01018     (
    01019         const   XMLCh* const    toSearch
    01020         , const XMLCh* const    searchList
    01021     );
    01022
    01031     static XMLCh* findAny
    01032     (
    01033                 XMLCh* const    toSearch
    01034         , const XMLCh* const    searchList
    01035     );
    01036
    01043     static int patternMatch
    01044     (
    01045           const XMLCh* const    toSearch
    01046         , const XMLCh* const    pattern
    01047     );
    01048
    01053     static unsigned int stringLen(const char* const src);
    01054
    01059     static unsigned int stringLen(const XMLCh* const src);
    01060
    01068     static bool isValidNOTATION(const XMLCh*         const name
    01069                               ,       MemoryManager* const manager = XMLPlatformUtils::fgMemoryManager);
    01070
    01078     static bool isValidNCName(const XMLCh* const name);
    01079
    01087     static bool isValidName(const XMLCh* const name);
    01088
    01094     static bool isValidEncName(const XMLCh* const name);
    01095
    01103     static bool isValidQName(const XMLCh* const name);
    01104
    01111     static bool isAlpha(XMLCh const theChar);
    01112
    01118     static bool isDigit(XMLCh const theChar);
    01119
    01125     static bool isAlphaNum(XMLCh const theChar);
    01126
    01132     static bool isHex(XMLCh const theChar);
    01133
    01141     static bool isAllWhiteSpace(const XMLCh* const toCheck);
    01142
    01148     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
    01149
    01151
    01154
    01166     static void binToText
    01167     (
    01168         const   unsigned int    toFormat
    01169         ,       char* const     toFill
    01170         , const unsigned int    maxChars
    01171         , const unsigned int    radix
    01172         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01173     );
    01174
    01186     static void binToText
    01187     (
    01188         const   unsigned int    toFormat
    01189         ,       XMLCh* const    toFill
    01190         , const unsigned int    maxChars
    01191         , const unsigned int    radix
    01192         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01193     );
    01194
    01206     static void binToText
    01207     (
    01208         const   unsigned long   toFormat
    01209         ,       char* const     toFill
    01210         , const unsigned int    maxChars
    01211         , const unsigned int    radix
    01212         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01213     );
    01214
    01226     static void binToText
    01227     (
    01228         const   unsigned long   toFormat
    01229         ,       XMLCh* const    toFill
    01230         , const unsigned int    maxChars
    01231         , const unsigned int    radix
    01232         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01233     );
    01234
    01246     static void binToText
    01247     (
    01248         const   long            toFormat
    01249         ,       char* const     toFill
    01250         , const unsigned int    maxChars
    01251         , const unsigned int    radix
    01252         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01253     );
    01254
    01266     static void binToText
    01267     (
    01268         const   long            toFormat
    01269         ,       XMLCh* const    toFill
    01270         , const unsigned int    maxChars
    01271         , const unsigned int    radix
    01272         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01273     );
    01274
    01286     static void binToText
    01287     (
    01288         const   int             toFormat
    01289         ,       char* const     toFill
    01290         , const unsigned int    maxChars
    01291         , const unsigned int    radix
    01292         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01293     );
    01294
    01306     static void binToText
    01307     (
    01308         const   int             toFormat
    01309         ,       XMLCh* const    toFill
    01310         , const unsigned int    maxChars
    01311         , const unsigned int    radix
    01312         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01313     );
    01314
    01326     static bool textToBin
    01327     (
    01328         const   XMLCh* const    toConvert
    01329         ,       unsigned int&   toFill
    01330         ,       MemoryManager*  const manager = XMLPlatformUtils::fgMemoryManager
    01331     );
    01332
    01346     static int parseInt
    01347     (
    01348         const   XMLCh* const    toConvert
    01349       , MemoryManager* const    manager = XMLPlatformUtils::fgMemoryManager
    01350     );
    01351
    01357     static void cut
    01358     (
    01359                 XMLCh* const    toCutFrom
    01360         , const unsigned int    count
    01361     );
    01362
    01373     static char* transcode
    01374     (
    01375         const   XMLCh* const    toTranscode
    01376     );
    01377     static char* transcode
    01378     (
    01379         const   XMLCh* const         toTranscode
    01380         ,       MemoryManager* const manager
    01381     );
    01382
    01398     static bool transcode
    01399     (
    01400         const   XMLCh* const    toTranscode
    01401         ,       char* const     toFill
    01402         , const unsigned int    maxChars
    01403         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01404     );
    01405
    01416     static XMLCh* transcode
    01417     (
    01418         const   char* const     toTranscode
    01419     );
    01420     static XMLCh* transcode
    01421     (
    01422         const   char* const          toTranscode
    01423         ,       MemoryManager* const manager
    01424     );
    01425
    01436     static bool transcode
    01437     (
    01438         const   char* const     toTranscode
    01439         ,       XMLCh* const    toFill
    01440         , const unsigned int    maxChars
    01441         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01442     );
    01443
    01449     static void trim(char* const toTrim);
    01450
    01456     static void trim(XMLCh* const toTrim);
    01457
    01465     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc
    01466                                         , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
    01467
    01469
    01480     static XMLCh* makeUName
    01481     (
    01482         const   XMLCh* const    pszURI
    01483         , const XMLCh* const    pszName
    01484     );
    01485
    01502     static unsigned int replaceTokens
    01503     (
    01504                 XMLCh* const    errText
    01505         , const unsigned int    maxChars
    01506         , const XMLCh* const    text1
    01507         , const XMLCh* const    text2
    01508         , const XMLCh* const    text3
    01509         , const XMLCh* const    text4
    01510         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager
    01511     );
    01512
    01517     static void upperCase(XMLCh* const toUpperCase);
    01518
    01524     static void upperCaseASCII(XMLCh* const toUpperCase);
    01525
    01530     static void lowerCase(XMLCh* const toLowerCase);
    01531
    01537     static void lowerCaseASCII(XMLCh* const toLowerCase);
    01538
    01542     static bool isWSReplaced(const XMLCh* const toCheck);
    01543
    01547     static bool isWSCollapsed(const XMLCh* const toCheck);
    01548
    01554     static void replaceWS(XMLCh* const toConvert
    01555         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
    01556
    01562     static void collapseWS(XMLCh* const toConvert
    01563         , MemoryManager* const  manager = XMLPlatformUtils::fgMemoryManager);
    01564
    01570     static void removeWS(XMLCh* const toConvert
    01571     , MemoryManager*       const manager = XMLPlatformUtils::fgMemoryManager);
    01572
    01573
    01579     static void removeChar(const XMLCh*     const srcString
    01580                          , const XMLCh&           toRemove
    01581                          ,       XMLBuffer&       dstBuffer);
    01582
    01590     static void fixURI(const XMLCh* const str, XMLCh* const target);
    01591
    01593
    01601     static void release(char** buf);
    01602
    01609     static void release(XMLCh** buf);
    01610
    01617     static void release(XMLByte** buf);
    01618
    01627     static void release
    01628     (
    01629         void**  buf
    01630         ,       MemoryManager* const manager
    01631     );
    01632
    01634
    01635
    01636 private :
    01637
    01641     XMLString();
    01643     ~XMLString();
    01645
    01646
    01650     static void initString(XMLLCPTranscoder* const defToUse,
    01651                            MemoryManager* const manager);
    01652     static void termString();
    01654
    01659     static bool validateRegion(const XMLCh* const str1, const int offset1,
    01660                         const XMLCh* const str2, const int offset2,
    01661                         const unsigned int charCount);
    01662
    01663     static MemoryManager* fgMemoryManager;
    01664
    01665     friend class XMLPlatformUtils;
    01666 };
    01667
    01668
    01669 // ---------------------------------------------------------------------------
    01670 //  Inline some methods that are either just passthroughs to other string
    01671 //  methods, or which are key for performance.
    01672 // ---------------------------------------------------------------------------
    01673 inline void XMLString::moveChars(       XMLCh* const targetStr
    01674                                 , const XMLCh* const srcStr
    01675                                 , const unsigned int count)
    01676 {
    01677     memcpy(targetStr, srcStr, count * sizeof(XMLCh));
    01678 }
    01679
    01680 inline unsigned int XMLString::stringLen(const XMLCh* const src)
    01681 {
    01682     if (src == 0 || *src == 0)
    01683     {
    01684         return 0;
    01685    }
    01686     else
    01687    {
    01688         const XMLCh* pszTmp = src + 1;
    01689
    01690         while (*pszTmp)
    01691             ++pszTmp;
    01692
    01693         return (unsigned int)(pszTmp - src);
    01694     }
    01695 }
    01696
    01697 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
    01698                                    MemoryManager* const manager)
    01699 {
    01700     // If a null string, return a null string!
    01701     XMLCh* ret = 0;
    01702     if (toRep)
    01703     {
    01704         const unsigned int len = stringLen(toRep);
    01705         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
    01706         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
    01707     }
    01708     return ret;
    01709 }
    01710
    01711 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
    01712                                     , const XMLCh* const    prefix)
    01713 {
    01714     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
    01715 }
    01716
    01717 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
    01718                                     , const XMLCh* const    prefix)
    01719 {
    01720     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
    01721 }
    01722
    01723 inline bool XMLString::endsWith(const XMLCh* const toTest,
    01724                                 const XMLCh* const suffix)
    01725 {
    01726
    01727     unsigned int suffixLen = XMLString::stringLen(suffix);
    01728
    01729     return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
    01730                          suffix, 0, suffixLen);
    01731 }
    01732
    01733 inline bool XMLString::validateRegion(const XMLCh* const str1,
    01734                                       const int offset1,
    01735                                       const XMLCh* const str2,
    01736                                       const int offset2,
    01737                                       const unsigned int charCount)
    01738 {
    01739
    01740     if (offset1 < 0 || offset2 < 0 ||
    01741         (offset1 + charCount) > XMLString::stringLen(str1) ||
    01742         (offset2 + charCount) > XMLString::stringLen(str2) )
    01743         return false;
    01744
    01745     return true;
    01746 }
    01747
    01748 inline bool XMLString::equals(   const XMLCh* const    str1
    01749                                , const XMLCh* const    str2)
    01750 {
    01751     const XMLCh* psz1 = str1;
    01752     const XMLCh* psz2 = str2;
    01753
    01754     if (psz1 == 0 || psz2 == 0) {
    01755         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
    01756             return false;
    01757         else
    01758             return true;
    01759     }
    01760
    01761     while (*psz1 == *psz2)
    01762     {
    01763         // If either has ended, then they both ended, so equal
    01764         if (!*psz1)
    01765             return true;
    01766
    01767         // Move upwards for the next round
    01768         psz1++;
    01769         psz2++;
    01770     }
    01771     return false;
    01772 }
    01773
    01774 inline bool XMLString::equals(   const char* const    str1
    01775                                , const char* const    str2)
    01776 {
    01777     const char* psz1 = str1;
    01778     const char* psz2 = str2;
    01779
    01780     if (psz1 == 0 || psz2 == 0) {
    01781         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
    01782             return false;
    01783         else
    01784             return true;
    01785     }
    01786
    01787     while (*psz1 == *psz2)
    01788     {
    01789         // If either has ended, then they both ended, so equal
    01790         if (!*psz1)
    01791             return true;
    01792
    01793         // Move upwards for the next round
    01794         psz1++;
    01795         psz2++;
    01796     }
    01797     return false;
    01798 }
    01799
    01800 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
    01801 {
    01802     return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
    01803 }
    01804
    01805 inline unsigned int XMLString::hash(   const   XMLCh* const    tohash
    01806                                 , const unsigned int    hashModulus
    01807                                 , MemoryManager* const)
    01808 {
    01809     assert(hashModulus);
    01810
    01811     if (tohash == 0 || *tohash == 0)
    01812         return 0;
    01813
    01814     const XMLCh* curCh = tohash;
    01815     unsigned int hashVal = (unsigned int)(*curCh);
    01816     curCh++;
    01817
    01818     while (*curCh)
    01819     {
    01820         hashVal = (hashVal * 38) + (hashVal >> 24) + (unsigned int)(*curCh);
    01821         curCh++;
    01822     }
    01823
    01824     // Divide by modulus
    01825     return hashVal % hashModulus;
    01826 }
    01827
    01828 XERCES_CPP_NAMESPACE_END
    01829
    01830 #endif

Copyright © 1994-2004 The Apache Software Foundation. All Rights Reserved.