| 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-2001 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.13  2003/02/05 18:50:56  tng
    00060  * [Bug 11915] Utility for freeing memory.
    00061  *
    00062  * Revision 1.12  2003/01/24 23:16:33  peiyongz
    00063  * removeWS() added;
    00064  *
    00065  * Revision 1.11  2002/12/20 22:10:21  tng
    00066  * XML 1.1
    00067  *
    00068  * Revision 1.10  2002/12/18 14:17:54  gareth
    00069  * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
    00070  *
    00071  * Revision 1.9  2002/12/04 02:32:43  knoaman
    00072  * #include cleanup.
    00073  *
    00074  * Revision 1.8  2002/11/05 17:42:39  peiyongz
    00075  * equals( const char* const, const char* const)
    00076  *
    00077  * Revision 1.7  2002/11/04 15:22:05  tng
    00078  * C++ Namespace Support.
    00079  *
    00080  * Revision 1.6  2002/10/01 19:45:22  tng
    00081  * Performance in XMLString::equals, only need to check one string for null as they are equal already.
    00082  *
    00083  * Revision 1.5  2002/09/24 19:41:21  tng
    00084  * New inline function equals that is modified from compareString but simply return true or false.
    00085  *
    00086  * Revision 1.4  2002/09/23 18:42:18  tng
    00087  * DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path filename to standard URI form.
    00088  *
    00089  * Revision 1.3  2002/08/27 19:24:43  peiyongz
    00090  * Bug#12087: patch from Thomas Ford (tom@decisionsoft.com)
    00091  *
    00092  * Revision 1.2  2002/02/20 18:17:02  tng
    00093  * [Bug 5977] Warnings on generating apiDocs.
    00094  *
    00095  * Revision 1.1.1.1  2002/02/01 22:22:16  peiyongz
    00096  * sane_include
    00097  *
    00098  * Revision 1.26  2001/08/10 16:23:06  peiyongz
    00099  * isHex(), isAlphaNum(), isAllWhiteSpace() and patternMatch() Added
    00100  *
    00101  * Revision 1.25  2001/07/06 20:27:57  peiyongz
    00102  * isValidaQName()
    00103  *
    00104  * Revision 1.24  2001/07/04 14:38:20  peiyongz
    00105  * IDDatatypeValidator: created
    00106  * DatatypeValidatorFactory: IDDTV enabled
    00107  * XMLString:isValidName(): to validate Name (XML [4][5])
    00108  *
    00109  * Revision 1.23  2001/06/13 14:07:55  peiyongz
    00110  * isValidaEncName() to validate an encoding name (EncName)
    00111  *
    00112  * Revision 1.22  2001/05/23 15:44:51  tng
    00113  * Schema: NormalizedString fix.  By Pei Yong Zhang.
    00114  *
    00115  * Revision 1.21  2001/05/11 13:26:31  tng
    00116  * Copyright update.
    00117  *
    00118  * Revision 1.20  2001/05/09 18:43:30  tng
    00119  * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
    00120  *
    00121  * Revision 1.19  2001/05/03 20:34:35  tng
    00122  * Schema: SchemaValidator update
    00123  *
    00124  * Revision 1.18  2001/05/03 19:17:35  knoaman
    00125  * TraverseSchema Part II.
    00126  *
    00127  * Revision 1.17  2001/03/21 21:56:13  tng
    00128  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
    00129  *
    00130  * Revision 1.16  2001/03/02 20:52:46  knoaman
    00131  * Schema: Regular expression - misc. updates for error messages,
    00132  * and additions of new functions to XMLString class.
    00133  *
    00134  * Revision 1.15  2001/01/15 21:26:34  tng
    00135  * Performance Patches by David Bertoni.
    00136  *
    00137  * Details: (see xerces-c-dev mailing Jan 14)
    00138  * XMLRecognizer.cpp: the internal encoding string XMLUni::fgXMLChEncodingString
    00139  * was going through this function numerous times.  As a result, the top hot-spot
    00140  * for the parse was _wcsicmp().  The real problem is that the Microsofts wide string
    00141  * functions are unbelievably slow.  For things like encodings, it might be
    00142  * better to use a special comparison function that only considers a-z and
    00143  * A-Z as characters with case.  This works since the character set for
    00144  * encodings is limit to printable ASCII characters.
    00145  *
    00146  *  XMLScanner2.cpp: This also has some case-sensitive vs. insensitive compares.
    00147  * They are also much faster.  The other tweak is to only make a copy of an attribute
    00148  * string if it needs to be split.  And then, the strategy is to try to use a
    00149  * stack-based buffer, rather than a dynamically-allocated one.
    00150  *
    00151  * SAX2XMLReaderImpl.cpp: Again, more case-sensitive vs. insensitive comparisons.
    00152  *
    00153  * KVStringPair.cpp & hpp: By storing the size of the allocation, the storage can
    00154  * likely be re-used many times, cutting down on dynamic memory allocations.
    00155  *
    00156  * XMLString.hpp: a more efficient implementation of stringLen().
    00157  *
    00158  * DTDValidator.cpp: another case of using a stack-based buffer when possible
    00159  *
    00160  * These patches made a big difference in parse time in some of our test
    00161  * files, especially the ones are very attribute-heavy.
    00162  *
    00163  * Revision 1.14  2000/10/13 22:47:57  andyh
    00164  * Fix bug (failure to null-terminate result) in XMLString::trim().
    00165  * Patch contributed by Nadav Aharoni
    00166  *
    00167  * Revision 1.13  2000/04/12 18:42:15  roddey
    00168  * Improved docs in terms of what 'max chars' means in the method
    00169  * parameters.
    00170  *
    00171  * Revision 1.12  2000/04/06 19:42:51  rahulj
    00172  * Clarified how big the target buffer should be in the API
    00173  * documentation.
    00174  *
    00175  * Revision 1.11  2000/03/23 01:02:38  roddey
    00176  * Updates to the XMLURL class to correct a lot of parsing problems
    00177  * and to add support for the port number. Updated the URL tests
    00178  * to test some of this new stuff.
    00179  *
    00180  * Revision 1.10  2000/03/20 23:00:46  rahulj
    00181  * Moved the inline definition of stringLen before the first
    00182  * use. This satisfied the HP CC compiler.
    00183  *
    00184  * Revision 1.9  2000/03/02 19:54:49  roddey
    00185  * This checkin includes many changes done while waiting for the
    00186  * 1.1.0 code to be finished. I can't list them all here, but a list is
    00187  * available elsewhere.
    00188  *
    00189  * Revision 1.8  2000/02/24 20:05:26  abagchi
    00190  * Swat for removing Log from API docs
    00191  *
    00192  * Revision 1.7  2000/02/16 18:51:52  roddey
    00193  * Fixed some facts in the docs and reformatted the docs to stay within
    00194  * a reasonable line width.
    00195  *
    00196  * Revision 1.6  2000/02/16 17:07:07  abagchi
    00197  * Added API docs
    00198  *
    00199  * Revision 1.5  2000/02/06 07:48:06  rahulj
    00200  * Year 2K copyright swat.
    00201  *
    00202  * Revision 1.4  2000/01/12 00:16:23  roddey
    00203  * Changes to deal with multiply nested, relative pathed, entities and to deal
    00204  * with the new URL class changes.
    00205  *
    00206  * Revision 1.3  1999/12/18 00:18:10  roddey
    00207  * More changes to support the new, completely orthagonal support for
    00208  * intrinsic encodings.
    00209  *
    00210  * Revision 1.2  1999/12/15 19:41:28  roddey
    00211  * Support for the new transcoder system, where even intrinsic encodings are
    00212  * done via the same transcoder abstraction as external ones.
    00213  *
    00214  * Revision 1.1.1.1  1999/11/09 01:05:52  twl
    00215  * Initial checkin
    00216  *
    00217  * Revision 1.2  1999/11/08 20:45:21  rahul
    00218  * Swat for adding in Product name and CVS comment log variable.
    00219  *
    00220  */
    00221
    00222 #if !defined(XMLSTRING_HPP)
    00223 #define XMLSTRING_HPP
    00224
    00225 #include <xercesc/util/BaseRefVectorOf.hpp>
    00226
    00227 XERCES_CPP_NAMESPACE_BEGIN
    00228
    00229 class XMLLCPTranscoder;
    00241 class  XMLString
    00242 {
    00243 public:
    00244     /* Static methods for native character mode string manipulation */
    00245
    00246
    00263     static void catString
    00264     (
    00265                 char* const     target
    00266         , const char* const     src
    00267     );
    00268
    00281     static void catString
    00282     (
    00283                 XMLCh* const    target
    00284         , const XMLCh* const    src
    00285     );
    00287
    00301     static int compareIString
    00302     (
    00303         const   char* const     str1
    00304         , const char* const     str2
    00305     );
    00306
    00317     static int compareIString
    00318     (
    00319         const   XMLCh* const    str1
    00320         , const XMLCh* const    str2
    00321     );
    00322
    00323
    00337     static int compareNString
    00338     (
    00339         const   char* const     str1
    00340         , const char* const     str2
    00341         , const unsigned int    count
    00342     );
    00343
    00357     static int compareNString
    00358     (
    00359         const   XMLCh* const    str1
    00360         , const XMLCh* const    str2
    00361         , const unsigned int    count
    00362     );
    00363
    00364
    00378     static int compareNIString
    00379     (
    00380         const   char* const     str1
    00381         , const char* const     str2
    00382         , const unsigned int    count
    00383     );
    00384
    00399     static int compareNIString
    00400     (
    00401         const   XMLCh* const    str1
    00402         , const XMLCh* const    str2
    00403         , const unsigned int    count
    00404     );
    00405
    00418     static int compareString
    00419     (
    00420         const   char* const     str1
    00421         , const char* const     str2
    00422     );
    00423
    00435     static int compareString
    00436     (
    00437         const   XMLCh* const    str1
    00438         , const XMLCh* const    str2
    00439     );
    00440
    00449     static bool equals
    00450     (
    00451           const XMLCh* const    str1
    00452         , const XMLCh* const    str2
    00453     );
    00454
    00455     static bool equals
    00456     (
    00457           const char* const    str1
    00458         , const char* const    str2
    00459     );
    00460
    00487     static bool regionMatches
    00488     (
    00489         const   XMLCh* const    str1
    00490         , const int             offset1
    00491         , const XMLCh* const    str2
    00492         , const int             offset2
    00493         , const unsigned int    charCount
    00494     );
    00495
    00523     static bool regionIMatches
    00524     (
    00525         const   XMLCh* const    str1
    00526         , const int             offset1
    00527         , const XMLCh* const    str2
    00528         , const int             offset2
    00529         , const unsigned int    charCount
    00530     );
    00532
    00545     static void copyString
    00546     (
    00547                 char* const     target
    00548         , const char* const     src
    00549     );
    00550
    00561     static void copyString
    00562     (
    00563                 XMLCh* const    target
    00564         , const XMLCh* const    src
    00565     );
    00566
    00579     static bool copyNString
    00580     (
    00581                 XMLCh* const    target
    00582         , const XMLCh* const    src
    00583         , const unsigned int    maxChars
    00584     );
    00586
    00595     static unsigned int hash
    00596     (
    00597         const   char* const     toHash
    00598         , const unsigned int    hashModulus
    00599     );
    00600
    00607     static unsigned int hash
    00608     (
    00609         const   XMLCh* const    toHash
    00610         , const unsigned int    hashModulus
    00611     );
    00612
    00622     static unsigned int hashN
    00623     (
    00624         const   XMLCh* const    toHash
    00625         , const unsigned int    numChars
    00626         , const unsigned int    hashModulus
    00627     );
    00628
    00630
    00641     static int indexOf(const char* const toSearch, const char ch);
    00642
    00651     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
    00652
    00663     static int indexOf
    00664     (
    00665         const   char* const     toSearch
    00666         , const char            chToFind
    00667         , const unsigned int    fromIndex
    00668     );
    00669
    00680     static int indexOf
    00681     (
    00682         const   XMLCh* const    toSearch
    00683         , const XMLCh           chToFind
    00684         , const unsigned int    fromIndex
    00685     );
    00686
    00695     static int lastIndexOf(const char* const toSearch, const char ch);
    00696
    00705     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
    00706
    00717     static int lastIndexOf
    00718     (
    00719         const   char* const     toSearch
    00720         , const char            chToFind
    00721         , const unsigned int    fromIndex
    00722     );
    00723
    00734     static int lastIndexOf
    00735     (
    00736         const   XMLCh* const    toSearch
    00737         , const XMLCh           ch
    00738         , const unsigned int    fromIndex
    00739     );
    00741
    00749     static void moveChars
    00750     (
    00751                 XMLCh* const    targetStr
    00752         , const XMLCh* const    srcStr
    00753         , const unsigned int    count
    00754     );
    00755
    00757
    00768     static void subString
    00769     (
    00770                 char* const    targetStr
    00771         , const char* const    srcStr
    00772         , const int            startIndex
    00773         , const int            endIndex
    00774     );
    00775
    00784     static void subString
    00785     (
    00786                 XMLCh* const    targetStr
    00787         , const XMLCh* const    srcStr
    00788         , const int             startIndex
    00789         , const int             endIndex
    00790     );
    00791
    00793
    00805     static char* replicate(const char* const toRep);
    00806
    00816     static XMLCh* replicate(const XMLCh* const toRep);
    00817
    00819
    00828     static bool startsWith
    00829     (
    00830         const   char* const     toTest
    00831         , const char* const     prefix
    00832     );
    00833
    00840     static bool startsWith
    00841     (
    00842         const   XMLCh* const    toTest
    00843         , const XMLCh* const    prefix
    00844     );
    00845
    00854     static bool startsWithI
    00855     (
    00856         const   char* const     toTest
    00857         , const char* const     prefix
    00858     );
    00859
    00869     static bool startsWithI
    00870     (
    00871         const   XMLCh* const    toTest
    00872         , const XMLCh* const    prefix
    00873     );
    00874
    00881     static bool endsWith
    00882     (
    00883         const   XMLCh* const    toTest
    00884         , const XMLCh* const    suffix
    00885     );
    00886
    00887
    00894     static const XMLCh* findAny
    00895     (
    00896         const   XMLCh* const    toSearch
    00897         , const XMLCh* const    searchList
    00898     );
    00899
    00906     static XMLCh* findAny
    00907     (
    00908                 XMLCh* const    toSearch
    00909         , const XMLCh* const    searchList
    00910     );
    00911
    00918     static int patternMatch
    00919     (
    00920           const XMLCh* const    toSearch
    00921         , const XMLCh* const    pattern
    00922     );
    00923
    00928     static unsigned int stringLen(const char* const src);
    00929
    00934     static unsigned int stringLen(const XMLCh* const src);
    00935
    00943     static bool isValidNCName(const XMLCh* const name);
    00944
    00952     static bool isValidName(const XMLCh* const name);
    00953
    00959     static bool isValidEncName(const XMLCh* const name);
    00960
    00968     static bool isValidQName(const XMLCh* const name);
    00969
    00976     static bool isAlpha(XMLCh const theChar);
    00977
    00983     static bool isDigit(XMLCh const theChar);
    00984
    00990     static bool isAlphaNum(XMLCh const theChar);
    00991
    00997     static bool isHex(XMLCh const theChar);
    00998
    01006     static bool isAllWhiteSpace(const XMLCh* const toCheck);
    01007
    01013     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
    01014
    01016
    01019
    01030     static void binToText
    01031     (
    01032         const   unsigned int    toFormat
    01033         ,       char* const     toFill
    01034         , const unsigned int    maxChars
    01035         , const unsigned int    radix
    01036     );
    01037
    01048     static void binToText
    01049     (
    01050         const   unsigned int    toFormat
    01051         ,       XMLCh* const    toFill
    01052         , const unsigned int    maxChars
    01053         , const unsigned int    radix
    01054     );
    01055
    01066     static void binToText
    01067     (
    01068         const   unsigned long   toFormat
    01069         ,       char* 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         ,       XMLCh* const    toFill
    01088         , const unsigned int    maxChars
    01089         , const unsigned int    radix
    01090     );
    01091
    01102     static void binToText
    01103     (
    01104         const   long            toFormat
    01105         ,       char* const     toFill
    01106         , const unsigned int    maxChars
    01107         , const unsigned int    radix
    01108     );
    01109
    01120     static void binToText
    01121     (
    01122         const   long            toFormat
    01123         ,       XMLCh* const    toFill
    01124         , const unsigned int    maxChars
    01125         , const unsigned int    radix
    01126     );
    01127
    01138     static void binToText
    01139     (
    01140         const   int             toFormat
    01141         ,       char* const     toFill
    01142         , const unsigned int    maxChars
    01143         , const unsigned int    radix
    01144     );
    01145
    01156     static void binToText
    01157     (
    01158         const   int             toFormat
    01159         ,       XMLCh* const    toFill
    01160         , const unsigned int    maxChars
    01161         , const unsigned int    radix
    01162     );
    01163
    01174     static bool textToBin
    01175     (
    01176         const   XMLCh* const    toConvert
    01177         ,       unsigned int&   toFill
    01178     );
    01179
    01192     static int parseInt
    01193     (
    01194         const   XMLCh* const    toConvert
    01195     );
    01196
    01202     static void cut
    01203     (
    01204                 XMLCh* const    toCutFrom
    01205         , const unsigned int    count
    01206     );
    01207
    01218     static char* transcode
    01219     (
    01220         const   XMLCh* const    toTranscode
    01221     );
    01222
    01239     static bool transcode
    01240     (
    01241         const   XMLCh* const    toTranscode
    01242         ,       char* const     toFill
    01243         , const unsigned int    maxChars
    01244     );
    01245
    01256     static XMLCh* transcode
    01257     (
    01258         const   char* const     toTranscode
    01259     );
    01260
    01272     static bool transcode
    01273     (
    01274         const   char* const     toTranscode
    01275         ,       XMLCh* const    toFill
    01276         , const unsigned int    maxChars
    01277     );
    01278
    01284     static void trim(char* const toTrim);
    01285
    01291     static void trim(XMLCh* const toTrim);
    01292
    01299     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc);
    01300
    01302
    01313     static XMLCh* makeUName
    01314     (
    01315         const   XMLCh* const    pszURI
    01316         , const XMLCh* const    pszName
    01317     );
    01318
    01334     static unsigned int replaceTokens
    01335     (
    01336                 XMLCh* const    errText
    01337         , const unsigned int    maxChars
    01338         , const XMLCh* const    text1
    01339         , const XMLCh* const    text2
    01340         , const XMLCh* const    text3
    01341         , const XMLCh* const    text4
    01342     );
    01343
    01348     static void upperCase(XMLCh* const toUpperCase);
    01349
    01354     static void lowerCase(XMLCh* const toLowerCase);
    01355
    01359     static bool isWSReplaced(const XMLCh* const toCheck);
    01360
    01364     static bool isWSCollapsed(const XMLCh* const toCheck);
    01365
    01370     static void replaceWS(XMLCh* const toConvert);
    01371
    01376     static void collapseWS(XMLCh* const toConvert);
    01377
    01382     static void removeWS(XMLCh* const toConvert);
    01383
    01391     static void fixURI(const XMLCh* const str, XMLCh* const target);
    01392
    01394
    01402     static void release(char** buf);
    01403
    01410     static void release(XMLCh** buf);
    01411
    01418     static void release(XMLByte** buf);
    01419
    01421
    01422
    01423 private :
    01424
    01428     XMLString();
    01430     ~XMLString();
    01432
    01433
    01437     static void initString(XMLLCPTranscoder* const defToUse);
    01438     static void termString();
    01440
    01445     static bool validateRegion(const XMLCh* const str1, const int offset1,
    01446                         const XMLCh* const str2, const int offset2,
    01447                         const unsigned int charCount);
    01448
    01449     friend class XMLPlatformUtils;
    01450 };
    01451
    01452
    01453 // ---------------------------------------------------------------------------
    01454 //  Inline some methods that are either just passthroughs to other string
    01455 //  methods, or which are key for performance.
    01456 // ---------------------------------------------------------------------------
    01457 inline void XMLString::moveChars(       XMLCh* const    targetStr
    01458                                 , const XMLCh* const    srcStr
    01459                                 , const unsigned int    count)
    01460 {
    01461     XMLCh* outPtr = targetStr;
    01462     const XMLCh* inPtr = srcStr;
    01463     for (unsigned int index = 0; index < count; index++)
    01464         *outPtr++ = *inPtr++;
    01465 }
    01466
    01467 inline unsigned int XMLString::stringLen(const XMLCh* const src)
    01468 {
    01469     if (src == 0 || *src == 0)
    01470     {
    01471         return 0;
    01472    }
    01473     else
    01474    {
    01475         const XMLCh* pszTmp = src + 1;
    01476
    01477         while (*pszTmp)
    01478             ++pszTmp;
    01479
    01480         return (unsigned int)(pszTmp - src);
    01481     }
    01482 }
    01483
    01484 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
    01485                                     , const XMLCh* const    prefix)
    01486 {
    01487     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
    01488 }
    01489
    01490 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
    01491                                     , const XMLCh* const    prefix)
    01492 {
    01493     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
    01494 }
    01495
    01496 inline bool XMLString::endsWith(const XMLCh* const toTest,
    01497                                 const XMLCh* const suffix)
    01498 {
    01499
    01500     unsigned int suffixLen = XMLString::stringLen(suffix);
    01501
    01502     return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
    01503                          suffix, 0, suffixLen);
    01504 }
    01505
    01506 inline XMLCh* XMLString::replicate(const XMLCh* const toRep)
    01507 {
    01508     // If a null string, return a null string!
    01509     XMLCh* ret = 0;
    01510     if (toRep)
    01511     {
    01512         const unsigned int len = stringLen(toRep);
    01513         ret = new XMLCh[len + 1];
    01514         XMLCh* outPtr = ret;
    01515         const XMLCh* inPtr = toRep;
    01516         for (unsigned int index = 0; index <= len; index++)
    01517             *outPtr++ = *inPtr++;
    01518     }
    01519     return ret;
    01520 }
    01521
    01522 inline bool XMLString::validateRegion(const XMLCh* const str1,
    01523                                       const int offset1,
    01524                                       const XMLCh* const str2,
    01525                                       const int offset2,
    01526                                       const unsigned int charCount)
    01527 {
    01528
    01529     if (offset1 < 0 || offset2 < 0 ||
    01530         (offset1 + charCount) > XMLString::stringLen(str1) ||
    01531         (offset2 + charCount) > XMLString::stringLen(str2) )
    01532         return false;
    01533
    01534     return true;
    01535 }
    01536
    01537 inline bool XMLString::equals(   const XMLCh* const    str1
    01538                                , const XMLCh* const    str2)
    01539 {
    01540     const XMLCh* psz1 = str1;
    01541     const XMLCh* psz2 = str2;
    01542
    01543     if (psz1 == 0 || psz2 == 0) {
    01544         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
    01545             return false;
    01546         else
    01547             return true;
    01548     }
    01549
    01550     while (*psz1 == *psz2)
    01551     {
    01552         // If either has ended, then they both ended, so equal
    01553         if (!*psz1)
    01554             return true;
    01555
    01556         // Move upwards for the next round
    01557         psz1++;
    01558         psz2++;
    01559     }
    01560     return false;
    01561 }
    01562
    01563 inline bool XMLString::equals(   const char* const    str1
    01564                                , const char* const    str2)
    01565 {
    01566     const char* psz1 = str1;
    01567     const char* psz2 = str2;
    01568
    01569     if (psz1 == 0 || psz2 == 0) {
    01570         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
    01571             return false;
    01572         else
    01573             return true;
    01574     }
    01575
    01576     while (*psz1 == *psz2)
    01577     {
    01578         // If either has ended, then they both ended, so equal
    01579         if (!*psz1)
    01580             return true;
    01581
    01582         // Move upwards for the next round
    01583         psz1++;
    01584         psz2++;
    01585     }
    01586     return false;
    01587 }
    01588
    01589 XERCES_CPP_NAMESPACE_END
    01590
    01591 #endif

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