XMLString.hpp Source File

| API Docs for SAX and DOM |

Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members File Members

# XMLString.hpp

Go to the documentation of this file.

    00001 /*
    00002  * The Apache Software License, Version 1.1
    00003  *
    00004  * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
    00005  * reserved.
    00006  *
    00007  * Redistribution and use in source and binary forms, with or without
    00008  * modification, are permitted provided that the following conditions
    00009  * are met:
    00010  *
    00011  * 1. Redistributions of source code must retain the above copyright
    00012  *    notice, this list of conditions and the following disclaimer.
    00013  *
    00014  * 2. Redistributions in binary form must reproduce the above copyright
    00015  *    notice, this list of conditions and the following disclaimer in
    00016  *    the documentation and/or other materials provided with the
    00017  *    distribution.
    00018  *
    00019  * 3. The end-user documentation included with the redistribution,
    00020  *    if any, must include the following acknowledgment:
    00021  *       "This product includes software developed by the
    00022  *        Apache Software Foundation (http://www.apache.org/)."
    00023  *    Alternately, this acknowledgment may appear in the software itself,
    00024  *    if and wherever such third-party acknowledgments normally appear.
    00025  *
    00026  * 4. The names "Xerces" and "Apache Software Foundation" must
    00027  *    not be used to endorse or promote products derived from this
    00028  *    software without prior written permission. For written
    00029  *    permission, please contact apache\@apache.org.
    00030  *
    00031  * 5. Products derived from this software may not be called "Apache",
    00032  *    nor may "Apache" appear in their name, without prior written
    00033  *    permission of the Apache Software Foundation.
    00034  *
    00035  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
    00036  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
    00037  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    00038  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
    00039  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    00040  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    00041  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
    00042  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
    00043  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    00044  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
    00045  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    00046  * SUCH DAMAGE.
    00047  * ====================================================================
    00048  *
    00049  * This software consists of voluntary contributions made by many
    00050  * individuals on behalf of the Apache Software Foundation, and was
    00051  * originally based on software copyright (c) 1999, International
    00052  * Business Machines, Inc., http://www.ibm.com .  For more information
    00053  * on the Apache Software Foundation, please see
    00054  * <http://www.apache.org/>.
    00055  */
    00056
    00057 /*
    00058  * $Log: XMLString.hpp,v $
    00059  * Revision 1.17  2003/05/18 14:02:05  knoaman
    00060  * Memory manager implementation: pass per instance manager.
    00061  *
    00062  * Revision 1.16  2003/05/15 19:07:46  knoaman
    00063  * Partial implementation of the configurable memory manager.
    00064  *
    00065  * Revision 1.15  2003/04/21 20:07:05  knoaman
    00066  * Performance: use memcpy in moveChars and replicate.
    00067  *
    00068  * Revision 1.14  2003/02/25 16:42:31  tng
    00069  * [Bug 7072] Documentation for XMLString::transcode states invalid return value.
    00070  *
    00071  * Revision 1.13  2003/02/05 18:50:56  tng
    00072  * [Bug 11915] Utility for freeing memory.
    00073  *
    00074  * Revision 1.12  2003/01/24 23:16:33  peiyongz
    00075  * removeWS() added;
    00076  *
    00077  * Revision 1.11  2002/12/20 22:10:21  tng
    00078  * XML 1.1
    00079  *
    00080  * Revision 1.10  2002/12/18 14:17:54  gareth
    00081  * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
    00082  *
    00083  * Revision 1.9  2002/12/04 02:32:43  knoaman
    00084  * #include cleanup.
    00085  *
    00086  * Revision 1.8  2002/11/05 17:42:39  peiyongz
    00087  * equals( const char* const, const char* const)
    00088  *
    00089  * Revision 1.7  2002/11/04 15:22:05  tng
    00090  * C++ Namespace Support.
    00091  *
    00092  * Revision 1.6  2002/10/01 19:45:22  tng
    00093  * Performance in XMLString::equals, only need to check one string for null as they are equal already.
    00094  *
    00095  * Revision 1.5  2002/09/24 19:41:21  tng
    00096  * New inline function equals that is modified from compareString but simply return true or false.
    00097  *
    00098  * Revision 1.4  2002/09/23 18:42:18  tng
    00099  * DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path filename to standard URI form.
    00100  *
    00101  * Revision 1.3  2002/08/27 19:24:43  peiyongz
    00102  * Bug#12087: patch from Thomas Ford (tom@decisionsoft.com)
    00103  *
    00104  * Revision 1.2  2002/02/20 18:17:02  tng
    00105  * [Bug 5977] Warnings on generating apiDocs.
    00106  *
    00107  * Revision 1.1.1.1  2002/02/01 22:22:16  peiyongz
    00108  * sane_include
    00109  *
    00110  * Revision 1.26  2001/08/10 16:23:06  peiyongz
    00111  * isHex(), isAlphaNum(), isAllWhiteSpace() and patternMatch() Added
    00112  *
    00113  * Revision 1.25  2001/07/06 20:27:57  peiyongz
    00114  * isValidaQName()
    00115  *
    00116  * Revision 1.24  2001/07/04 14:38:20  peiyongz
    00117  * IDDatatypeValidator: created
    00118  * DatatypeValidatorFactory: IDDTV enabled
    00119  * XMLString:isValidName(): to validate Name (XML [4][5])
    00120  *
    00121  * Revision 1.23  2001/06/13 14:07:55  peiyongz
    00122  * isValidaEncName() to validate an encoding name (EncName)
    00123  *
    00124  * Revision 1.22  2001/05/23 15:44:51  tng
    00125  * Schema: NormalizedString fix.  By Pei Yong Zhang.
    00126  *
    00127  * Revision 1.21  2001/05/11 13:26:31  tng
    00128  * Copyright update.
    00129  *
    00130  * Revision 1.20  2001/05/09 18:43:30  tng
    00131  * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
    00132  *
    00133  * Revision 1.19  2001/05/03 20:34:35  tng
    00134  * Schema: SchemaValidator update
    00135  *
    00136  * Revision 1.18  2001/05/03 19:17:35  knoaman
    00137  * TraverseSchema Part II.
    00138  *
    00139  * Revision 1.17  2001/03/21 21:56:13  tng
    00140  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
    00141  *
    00142  * Revision 1.16  2001/03/02 20:52:46  knoaman
    00143  * Schema: Regular expression - misc. updates for error messages,
    00144  * and additions of new functions to XMLString class.
    00145  *
    00146  * Revision 1.15  2001/01/15 21:26:34  tng
    00147  * Performance Patches by David Bertoni.
    00148  *
    00149  * Details: (see xerces-c-dev mailing Jan 14)
    00150  * XMLRecognizer.cpp: the internal encoding string XMLUni::fgXMLChEncodingString
    00151  * was going through this function numerous times.  As a result, the top hot-spot
    00152  * for the parse was _wcsicmp().  The real problem is that the Microsofts wide string
    00153  * functions are unbelievably slow.  For things like encodings, it might be
    00154  * better to use a special comparison function that only considers a-z and
    00155  * A-Z as characters with case.  This works since the character set for
    00156  * encodings is limit to printable ASCII characters.
    00157  *
    00158  *  XMLScanner2.cpp: This also has some case-sensitive vs. insensitive compares.
    00159  * They are also much faster.  The other tweak is to only make a copy of an attribute
    00160  * string if it needs to be split.  And then, the strategy is to try to use a
    00161  * stack-based buffer, rather than a dynamically-allocated one.
    00162  *
    00163  * SAX2XMLReaderImpl.cpp: Again, more case-sensitive vs. insensitive comparisons.
    00164  *
    00165  * KVStringPair.cpp & hpp: By storing the size of the allocation, the storage can
    00166  * likely be re-used many times, cutting down on dynamic memory allocations.
    00167  *
    00168  * XMLString.hpp: a more efficient implementation of stringLen().
    00169  *
    00170  * DTDValidator.cpp: another case of using a stack-based buffer when possible
    00171  *
    00172  * These patches made a big difference in parse time in some of our test
    00173  * files, especially the ones are very attribute-heavy.
    00174  *
    00175  * Revision 1.14  2000/10/13 22:47:57  andyh
    00176  * Fix bug (failure to null-terminate result) in XMLString::trim().
    00177  * Patch contributed by Nadav Aharoni
    00178  *
    00179  * Revision 1.13  2000/04/12 18:42:15  roddey
    00180  * Improved docs in terms of what 'max chars' means in the method
    00181  * parameters.
    00182  *
    00183  * Revision 1.12  2000/04/06 19:42:51  rahulj
    00184  * Clarified how big the target buffer should be in the API
    00185  * documentation.
    00186  *
    00187  * Revision 1.11  2000/03/23 01:02:38  roddey
    00188  * Updates to the XMLURL class to correct a lot of parsing problems
    00189  * and to add support for the port number. Updated the URL tests
    00190  * to test some of this new stuff.
    00191  *
    00192  * Revision 1.10  2000/03/20 23:00:46  rahulj
    00193  * Moved the inline definition of stringLen before the first
    00194  * use. This satisfied the HP CC compiler.
    00195  *
    00196  * Revision 1.9  2000/03/02 19:54:49  roddey
    00197  * This checkin includes many changes done while waiting for the
    00198  * 1.1.0 code to be finished. I can't list them all here, but a list is
    00199  * available elsewhere.
    00200  *
    00201  * Revision 1.8  2000/02/24 20:05:26  abagchi
    00202  * Swat for removing Log from API docs
    00203  *
    00204  * Revision 1.7  2000/02/16 18:51:52  roddey
    00205  * Fixed some facts in the docs and reformatted the docs to stay within
    00206  * a reasonable line width.
    00207  *
    00208  * Revision 1.6  2000/02/16 17:07:07  abagchi
    00209  * Added API docs
    00210  *
    00211  * Revision 1.5  2000/02/06 07:48:06  rahulj
    00212  * Year 2K copyright swat.
    00213  *
    00214  * Revision 1.4  2000/01/12 00:16:23  roddey
    00215  * Changes to deal with multiply nested, relative pathed, entities and to deal
    00216  * with the new URL class changes.
    00217  *
    00218  * Revision 1.3  1999/12/18 00:18:10  roddey
    00219  * More changes to support the new, completely orthagonal support for
    00220  * intrinsic encodings.
    00221  *
    00222  * Revision 1.2  1999/12/15 19:41:28  roddey
    00223  * Support for the new transcoder system, where even intrinsic encodings are
    00224  * done via the same transcoder abstraction as external ones.
    00225  *
    00226  * Revision 1.1.1.1  1999/11/09 01:05:52  twl
    00227  * Initial checkin
    00228  *
    00229  * Revision 1.2  1999/11/08 20:45:21  rahul
    00230  * Swat for adding in Product name and CVS comment log variable.
    00231  *
    00232  */
    00233
    00234 #if !defined(XMLSTRING_HPP)
    00235 #define XMLSTRING_HPP
    00236
    00237 #include <xercesc/util/BaseRefVectorOf.hpp>
    00238 #include <xercesc/framework/MemoryManager.hpp>
    00239 #include <string.h>
    00240
    00241 XERCES_CPP_NAMESPACE_BEGIN
    00242
    00243 class XMLLCPTranscoder;
    00255 class  XMLString
    00256 {
    00257 public:
    00258     /* Static methods for native character mode string manipulation */
    00259
    00260
    00277     static void catString
    00278     (
    00279                 char* const     target
    00280         , const char* const     src
    00281     );
    00282
    00295     static void catString
    00296     (
    00297                 XMLCh* const    target
    00298         , const XMLCh* const    src
    00299     );
    00301
    00315     static int compareIString
    00316     (
    00317         const   char* const     str1
    00318         , const char* const     str2
    00319     );
    00320
    00331     static int compareIString
    00332     (
    00333         const   XMLCh* const    str1
    00334         , const XMLCh* const    str2
    00335     );
    00336
    00337
    00351     static int compareNString
    00352     (
    00353         const   char* const     str1
    00354         , const char* const     str2
    00355         , const unsigned int    count
    00356     );
    00357
    00371     static int compareNString
    00372     (
    00373         const   XMLCh* const    str1
    00374         , const XMLCh* const    str2
    00375         , const unsigned int    count
    00376     );
    00377
    00378
    00392     static int compareNIString
    00393     (
    00394         const   char* const     str1
    00395         , const char* const     str2
    00396         , const unsigned int    count
    00397     );
    00398
    00413     static int compareNIString
    00414     (
    00415         const   XMLCh* const    str1
    00416         , const XMLCh* const    str2
    00417         , const unsigned int    count
    00418     );
    00419
    00432     static int compareString
    00433     (
    00434         const   char* const     str1
    00435         , const char* const     str2
    00436     );
    00437
    00449     static int compareString
    00450     (
    00451         const   XMLCh* const    str1
    00452         , const XMLCh* const    str2
    00453     );
    00454
    00463     static bool equals
    00464     (
    00465           const XMLCh* const    str1
    00466         , const XMLCh* const    str2
    00467     );
    00468
    00469     static bool equals
    00470     (
    00471           const char* const    str1
    00472         , const char* const    str2
    00473     );
    00474
    00501     static bool regionMatches
    00502     (
    00503         const   XMLCh* const    str1
    00504         , const int             offset1
    00505         , const XMLCh* const    str2
    00506         , const int             offset2
    00507         , const unsigned int    charCount
    00508     );
    00509
    00537     static bool regionIMatches
    00538     (
    00539         const   XMLCh* const    str1
    00540         , const int             offset1
    00541         , const XMLCh* const    str2
    00542         , const int             offset2
    00543         , const unsigned int    charCount
    00544     );
    00546
    00559     static void copyString
    00560     (
    00561                 char* const     target
    00562         , const char* const     src
    00563     );
    00564
    00575     static void copyString
    00576     (
    00577                 XMLCh* const    target
    00578         , const XMLCh* const    src
    00579     );
    00580
    00593     static bool copyNString
    00594     (
    00595                 XMLCh* const    target
    00596         , const XMLCh* const    src
    00597         , const unsigned int    maxChars
    00598     );
    00600
    00609     static unsigned int hash
    00610     (
    00611         const   char* const     toHash
    00612         , const unsigned int    hashModulus
    00613     );
    00614
    00621     static unsigned int hash
    00622     (
    00623         const   XMLCh* const    toHash
    00624         , const unsigned int    hashModulus
    00625     );
    00626
    00636     static unsigned int hashN
    00637     (
    00638         const   XMLCh* const    toHash
    00639         , const unsigned int    numChars
    00640         , const unsigned int    hashModulus
    00641     );
    00642
    00644
    00655     static int indexOf(const char* const toSearch, const char ch);
    00656
    00665     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
    00666
    00677     static int indexOf
    00678     (
    00679         const   char* const     toSearch
    00680         , const char            chToFind
    00681         , const unsigned int    fromIndex
    00682     );
    00683
    00694     static int indexOf
    00695     (
    00696         const   XMLCh* const    toSearch
    00697         , const XMLCh           chToFind
    00698         , const unsigned int    fromIndex
    00699     );
    00700
    00709     static int lastIndexOf(const char* const toSearch, const char ch);
    00710
    00719     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
    00720
    00731     static int lastIndexOf
    00732     (
    00733         const   char* const     toSearch
    00734         , const char            chToFind
    00735         , const unsigned int    fromIndex
    00736     );
    00737
    00748     static int lastIndexOf
    00749     (
    00750         const   XMLCh* const    toSearch
    00751         , const XMLCh           ch
    00752         , const unsigned int    fromIndex
    00753     );
    00755
    00763     static void moveChars
    00764     (
    00765                 XMLCh* const    targetStr
    00766         , const XMLCh* const    srcStr
    00767         , const unsigned int    count
    00768     );
    00769
    00771
    00782     static void subString
    00783     (
    00784                 char* const    targetStr
    00785         , const char* const    srcStr
    00786         , const int            startIndex
    00787         , const int            endIndex
    00788     );
    00789
    00798     static void subString
    00799     (
    00800                 XMLCh* const    targetStr
    00801         , const XMLCh* const    srcStr
    00802         , const int             startIndex
    00803         , const int             endIndex
    00804     );
    00805
    00807
    00819     static char* replicate(const char* const toRep);
    00820     static char* replicate(const char* const toRep,
    00821                            MemoryManager* const manager);
    00822
    00832     static XMLCh* replicate(const XMLCh* const toRep);
    00833     static XMLCh* replicate(const XMLCh* const toRep,
    00834                             MemoryManager* const manager);
    00835
    00837
    00846     static bool startsWith
    00847     (
    00848         const   char* const     toTest
    00849         , const char* const     prefix
    00850     );
    00851
    00858     static bool startsWith
    00859     (
    00860         const   XMLCh* const    toTest
    00861         , const XMLCh* const    prefix
    00862     );
    00863
    00872     static bool startsWithI
    00873     (
    00874         const   char* const     toTest
    00875         , const char* const     prefix
    00876     );
    00877
    00887     static bool startsWithI
    00888     (
    00889         const   XMLCh* const    toTest
    00890         , const XMLCh* const    prefix
    00891     );
    00892
    00899     static bool endsWith
    00900     (
    00901         const   XMLCh* const    toTest
    00902         , const XMLCh* const    suffix
    00903     );
    00904
    00905
    00912     static const XMLCh* findAny
    00913     (
    00914         const   XMLCh* const    toSearch
    00915         , const XMLCh* const    searchList
    00916     );
    00917
    00924     static XMLCh* findAny
    00925     (
    00926                 XMLCh* const    toSearch
    00927         , const XMLCh* const    searchList
    00928     );
    00929
    00936     static int patternMatch
    00937     (
    00938           const XMLCh* const    toSearch
    00939         , const XMLCh* const    pattern
    00940     );
    00941
    00946     static unsigned int stringLen(const char* const src);
    00947
    00952     static unsigned int stringLen(const XMLCh* const src);
    00953
    00961     static bool isValidNCName(const XMLCh* const name);
    00962
    00970     static bool isValidName(const XMLCh* const name);
    00971
    00977     static bool isValidEncName(const XMLCh* const name);
    00978
    00986     static bool isValidQName(const XMLCh* const name);
    00987
    00994     static bool isAlpha(XMLCh const theChar);
    00995
    01001     static bool isDigit(XMLCh const theChar);
    01002
    01008     static bool isAlphaNum(XMLCh const theChar);
    01009
    01015     static bool isHex(XMLCh const theChar);
    01016
    01024     static bool isAllWhiteSpace(const XMLCh* const toCheck);
    01025
    01031     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
    01032
    01034
    01037
    01048     static void binToText
    01049     (
    01050         const   unsigned int    toFormat
    01051         ,       char* const     toFill
    01052         , const unsigned int    maxChars
    01053         , const unsigned int    radix
    01054     );
    01055
    01066     static void binToText
    01067     (
    01068         const   unsigned int    toFormat
    01069         ,       XMLCh* const    toFill
    01070         , const unsigned int    maxChars
    01071         , const unsigned int    radix
    01072     );
    01073
    01084     static void binToText
    01085     (
    01086         const   unsigned long   toFormat
    01087         ,       char* const     toFill
    01088         , const unsigned int    maxChars
    01089         , const unsigned int    radix
    01090     );
    01091
    01102     static void binToText
    01103     (
    01104         const   unsigned long   toFormat
    01105         ,       XMLCh* const    toFill
    01106         , const unsigned int    maxChars
    01107         , const unsigned int    radix
    01108     );
    01109
    01120     static void binToText
    01121     (
    01122         const   long            toFormat
    01123         ,       char* const     toFill
    01124         , const unsigned int    maxChars
    01125         , const unsigned int    radix
    01126     );
    01127
    01138     static void binToText
    01139     (
    01140         const   long            toFormat
    01141         ,       XMLCh* const    toFill
    01142         , const unsigned int    maxChars
    01143         , const unsigned int    radix
    01144     );
    01145
    01156     static void binToText
    01157     (
    01158         const   int             toFormat
    01159         ,       char* const     toFill
    01160         , const unsigned int    maxChars
    01161         , const unsigned int    radix
    01162     );
    01163
    01174     static void binToText
    01175     (
    01176         const   int             toFormat
    01177         ,       XMLCh* const    toFill
    01178         , const unsigned int    maxChars
    01179         , const unsigned int    radix
    01180     );
    01181
    01192     static bool textToBin
    01193     (
    01194         const   XMLCh* const    toConvert
    01195         ,       unsigned int&   toFill
    01196     );
    01197
    01210     static int parseInt
    01211     (
    01212         const   XMLCh* const    toConvert
    01213     );
    01214
    01220     static void cut
    01221     (
    01222                 XMLCh* const    toCutFrom
    01223         , const unsigned int    count
    01224     );
    01225
    01236     static char* transcode
    01237     (
    01238         const   XMLCh* const    toTranscode
    01239     );
    01240     static char* transcode
    01241     (
    01242         const   XMLCh* const         toTranscode
    01243         ,       MemoryManager* const manager
    01244     );
    01245
    01260     static bool transcode
    01261     (
    01262         const   XMLCh* const    toTranscode
    01263         ,       char* const     toFill
    01264         , const unsigned int    maxChars
    01265     );
    01266
    01277     static XMLCh* transcode
    01278     (
    01279         const   char* const     toTranscode
    01280     );
    01281     static XMLCh* transcode
    01282     (
    01283         const   char* const          toTranscode
    01284         ,       MemoryManager* const manager
    01285     );
    01286
    01296     static bool transcode
    01297     (
    01298         const   char* const     toTranscode
    01299         ,       XMLCh* const    toFill
    01300         , const unsigned int    maxChars
    01301     );
    01302
    01308     static void trim(char* const toTrim);
    01309
    01315     static void trim(XMLCh* const toTrim);
    01316
    01323     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc);
    01324
    01326
    01337     static XMLCh* makeUName
    01338     (
    01339         const   XMLCh* const    pszURI
    01340         , const XMLCh* const    pszName
    01341     );
    01342
    01358     static unsigned int replaceTokens
    01359     (
    01360                 XMLCh* const    errText
    01361         , const unsigned int    maxChars
    01362         , const XMLCh* const    text1
    01363         , const XMLCh* const    text2
    01364         , const XMLCh* const    text3
    01365         , const XMLCh* const    text4
    01366     );
    01367
    01372     static void upperCase(XMLCh* const toUpperCase);
    01373
    01378     static void lowerCase(XMLCh* const toLowerCase);
    01379
    01383     static bool isWSReplaced(const XMLCh* const toCheck);
    01384
    01388     static bool isWSCollapsed(const XMLCh* const toCheck);
    01389
    01394     static void replaceWS(XMLCh* const toConvert);
    01395
    01400     static void collapseWS(XMLCh* const toConvert);
    01401
    01406     static void removeWS(XMLCh* const toConvert);
    01407
    01415     static void fixURI(const XMLCh* const str, XMLCh* const target);
    01416
    01418
    01426     static void release(char** buf);
    01427
    01434     static void release(XMLCh** buf);
    01435
    01442     static void release(XMLByte** buf);
    01443
    01445
    01446
    01447 private :
    01448
    01452     XMLString();
    01454     ~XMLString();
    01456
    01457
    01461     static void initString(XMLLCPTranscoder* const defToUse,
    01462                            MemoryManager* const manager);
    01463     static void termString();
    01465
    01470     static bool validateRegion(const XMLCh* const str1, const int offset1,
    01471                         const XMLCh* const str2, const int offset2,
    01472                         const unsigned int charCount);
    01473
    01474     static MemoryManager* fgMemoryManager;
    01475
    01476     friend class XMLPlatformUtils;
    01477 };
    01478
    01479
    01480 // ---------------------------------------------------------------------------
    01481 //  Inline some methods that are either just passthroughs to other string
    01482 //  methods, or which are key for performance.
    01483 // ---------------------------------------------------------------------------
    01484 inline void XMLString::moveChars(       XMLCh* const targetStr
    01485                                 , const XMLCh* const srcStr
    01486                                 , const unsigned int count)
    01487 {
    01488     memcpy(targetStr, srcStr, count * sizeof(XMLCh));
    01489 }
    01490
    01491 inline unsigned int XMLString::stringLen(const XMLCh* const src)
    01492 {
    01493     if (src == 0 || *src == 0)
    01494     {
    01495         return 0;
    01496    }
    01497     else
    01498    {
    01499         const XMLCh* pszTmp = src + 1;
    01500
    01501         while (*pszTmp)
    01502             ++pszTmp;
    01503
    01504         return (unsigned int)(pszTmp - src);
    01505     }
    01506 }
    01507
    01508 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
    01509                                     , const XMLCh* const    prefix)
    01510 {
    01511     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
    01512 }
    01513
    01514 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
    01515                                     , const XMLCh* const    prefix)
    01516 {
    01517     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
    01518 }
    01519
    01520 inline bool XMLString::endsWith(const XMLCh* const toTest,
    01521                                 const XMLCh* const suffix)
    01522 {
    01523
    01524     unsigned int suffixLen = XMLString::stringLen(suffix);
    01525
    01526     return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
    01527                          suffix, 0, suffixLen);
    01528 }
    01529
    01530 inline XMLCh* XMLString::replicate(const XMLCh* const toRep)
    01531 {
    01532     // If a null string, return a null string!
    01533     XMLCh* ret = 0;
    01534     if (toRep)
    01535     {
    01536         const unsigned int len = stringLen(toRep);
    01537         ret = new XMLCh[len + 1];
    01538         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
    01539     }
    01540     return ret;
    01541 }
    01542
    01543 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
    01544                                    MemoryManager* const manager)
    01545 {
    01546     // If a null string, return a null string!
    01547     XMLCh* ret = 0;
    01548     if (toRep)
    01549     {
    01550         const unsigned int len = stringLen(toRep);
    01551         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
    01552         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
    01553     }
    01554     return ret;
    01555 }
    01556
    01557 inline bool XMLString::validateRegion(const XMLCh* const str1,
    01558                                       const int offset1,
    01559                                       const XMLCh* const str2,
    01560                                       const int offset2,
    01561                                       const unsigned int charCount)
    01562 {
    01563
    01564     if (offset1 < 0 || offset2 < 0 ||
    01565         (offset1 + charCount) > XMLString::stringLen(str1) ||
    01566         (offset2 + charCount) > XMLString::stringLen(str2) )
    01567         return false;
    01568
    01569     return true;
    01570 }
    01571
    01572 inline bool XMLString::equals(   const XMLCh* const    str1
    01573                                , const XMLCh* const    str2)
    01574 {
    01575     const XMLCh* psz1 = str1;
    01576     const XMLCh* psz2 = str2;
    01577
    01578     if (psz1 == 0 || psz2 == 0) {
    01579         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
    01580             return false;
    01581         else
    01582             return true;
    01583     }
    01584
    01585     while (*psz1 == *psz2)
    01586     {
    01587         // If either has ended, then they both ended, so equal
    01588         if (!*psz1)
    01589             return true;
    01590
    01591         // Move upwards for the next round
    01592         psz1++;
    01593         psz2++;
    01594     }
    01595     return false;
    01596 }
    01597
    01598 inline bool XMLString::equals(   const char* const    str1
    01599                                , const char* const    str2)
    01600 {
    01601     const char* psz1 = str1;
    01602     const char* psz2 = str2;
    01603
    01604     if (psz1 == 0 || psz2 == 0) {
    01605         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
    01606             return false;
    01607         else
    01608             return true;
    01609     }
    01610
    01611     while (*psz1 == *psz2)
    01612     {
    01613         // If either has ended, then they both ended, so equal
    01614         if (!*psz1)
    01615             return true;
    01616
    01617         // Move upwards for the next round
    01618         psz1++;
    01619         psz2++;
    01620     }
    01621     return false;
    01622 }
    01623
    01624 XERCES_CPP_NAMESPACE_END
    01625
    01626 #endif

Copyright © 2000 The Apache Software Foundation. All Rights Reserved.