http://xml.apache.org/http://www.apache.org/http://www.w3.org/

Home

Readme
Release Info

Installation
Download
Build

FAQs
Samples
API Docs

DOM C++ Binding
Programming
Migration Guide

Feedback
Bug-Reporting
PDF Document

CVS Repository
Mail Archive

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.20  2003/10/02 11:07:26  gareth
00060  * 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.
00061  *
00062  * Revision 1.19  2003/10/01 00:22:20  knoaman
00063  * Add a lastIndexOf method that takes the string length as one of the params.
00064  *
00065  * Revision 1.18  2003/08/25 20:39:47  neilg
00066  * fix XMLString::findAny(...) docs so that they match what the method actually does (and has done since time immemorial)
00067  *
00068  * Revision 1.17  2003/05/18 14:02:05  knoaman
00069  * Memory manager implementation: pass per instance manager.
00070  *
00071  * Revision 1.16  2003/05/15 19:07:46  knoaman
00072  * Partial implementation of the configurable memory manager.
00073  *
00074  * Revision 1.15  2003/04/21 20:07:05  knoaman
00075  * Performance: use memcpy in moveChars and replicate.
00076  *
00077  * Revision 1.14  2003/02/25 16:42:31  tng
00078  * [Bug 7072] Documentation for XMLString::transcode states invalid return value.
00079  *
00080  * Revision 1.13  2003/02/05 18:50:56  tng
00081  * [Bug 11915] Utility for freeing memory.
00082  *
00083  * Revision 1.12  2003/01/24 23:16:33  peiyongz
00084  * removeWS() added;
00085  *
00086  * Revision 1.11  2002/12/20 22:10:21  tng
00087  * XML 1.1
00088  *
00089  * Revision 1.10  2002/12/18 14:17:54  gareth
00090  * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
00091  *
00092  * Revision 1.9  2002/12/04 02:32:43  knoaman
00093  * #include cleanup.
00094  *
00095  * Revision 1.8  2002/11/05 17:42:39  peiyongz
00096  * equals( const char* const, const char* const)
00097  *
00098  * Revision 1.7  2002/11/04 15:22:05  tng
00099  * C++ Namespace Support.
00100  *
00101  * Revision 1.6  2002/10/01 19:45:22  tng
00102  * Performance in XMLString::equals, only need to check one string for null as they are equal already.
00103  *
00104  * Revision 1.5  2002/09/24 19:41:21  tng
00105  * New inline function equals that is modified from compareString but simply return true or false.
00106  *
00107  * Revision 1.4  2002/09/23 18:42:18  tng
00108  * DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path filename to standard URI form.
00109  *
00110  * Revision 1.3  2002/08/27 19:24:43  peiyongz
00111  * Bug#12087: patch from Thomas Ford (tom@decisionsoft.com)
00112  *
00113  * Revision 1.2  2002/02/20 18:17:02  tng
00114  * [Bug 5977] Warnings on generating apiDocs.
00115  *
00116  * Revision 1.1.1.1  2002/02/01 22:22:16  peiyongz
00117  * sane_include
00118  *
00119  * Revision 1.26  2001/08/10 16:23:06  peiyongz
00120  * isHex(), isAlphaNum(), isAllWhiteSpace() and patternMatch() Added
00121  *
00122  * Revision 1.25  2001/07/06 20:27:57  peiyongz
00123  * isValidaQName()
00124  *
00125  * Revision 1.24  2001/07/04 14:38:20  peiyongz
00126  * IDDatatypeValidator: created
00127  * DatatypeValidatorFactory: IDDTV enabled
00128  * XMLString:isValidName(): to validate Name (XML [4][5])
00129  *
00130  * Revision 1.23  2001/06/13 14:07:55  peiyongz
00131  * isValidaEncName() to validate an encoding name (EncName)
00132  *
00133  * Revision 1.22  2001/05/23 15:44:51  tng
00134  * Schema: NormalizedString fix.  By Pei Yong Zhang.
00135  *
00136  * Revision 1.21  2001/05/11 13:26:31  tng
00137  * Copyright update.
00138  *
00139  * Revision 1.20  2001/05/09 18:43:30  tng
00140  * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
00141  *
00142  * Revision 1.19  2001/05/03 20:34:35  tng
00143  * Schema: SchemaValidator update
00144  *
00145  * Revision 1.18  2001/05/03 19:17:35  knoaman
00146  * TraverseSchema Part II.
00147  *
00148  * Revision 1.17  2001/03/21 21:56:13  tng
00149  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
00150  *
00151  * Revision 1.16  2001/03/02 20:52:46  knoaman
00152  * Schema: Regular expression - misc. updates for error messages,
00153  * and additions of new functions to XMLString class.
00154  *
00155  * Revision 1.15  2001/01/15 21:26:34  tng
00156  * Performance Patches by David Bertoni.
00157  *
00158  * Details: (see xerces-c-dev mailing Jan 14)
00159  * XMLRecognizer.cpp: the internal encoding string XMLUni::fgXMLChEncodingString
00160  * was going through this function numerous times.  As a result, the top hot-spot
00161  * for the parse was _wcsicmp().  The real problem is that the Microsofts wide string
00162  * functions are unbelievably slow.  For things like encodings, it might be
00163  * better to use a special comparison function that only considers a-z and
00164  * A-Z as characters with case.  This works since the character set for
00165  * encodings is limit to printable ASCII characters.
00166  *
00167  *  XMLScanner2.cpp: This also has some case-sensitive vs. insensitive compares.
00168  * They are also much faster.  The other tweak is to only make a copy of an attribute
00169  * string if it needs to be split.  And then, the strategy is to try to use a
00170  * stack-based buffer, rather than a dynamically-allocated one.
00171  *
00172  * SAX2XMLReaderImpl.cpp: Again, more case-sensitive vs. insensitive comparisons.
00173  *
00174  * KVStringPair.cpp & hpp: By storing the size of the allocation, the storage can
00175  * likely be re-used many times, cutting down on dynamic memory allocations.
00176  *
00177  * XMLString.hpp: a more efficient implementation of stringLen().
00178  *
00179  * DTDValidator.cpp: another case of using a stack-based buffer when possible
00180  *
00181  * These patches made a big difference in parse time in some of our test
00182  * files, especially the ones are very attribute-heavy.
00183  *
00184  * Revision 1.14  2000/10/13 22:47:57  andyh
00185  * Fix bug (failure to null-terminate result) in XMLString::trim().
00186  * Patch contributed by Nadav Aharoni
00187  *
00188  * Revision 1.13  2000/04/12 18:42:15  roddey
00189  * Improved docs in terms of what 'max chars' means in the method
00190  * parameters.
00191  *
00192  * Revision 1.12  2000/04/06 19:42:51  rahulj
00193  * Clarified how big the target buffer should be in the API
00194  * documentation.
00195  *
00196  * Revision 1.11  2000/03/23 01:02:38  roddey
00197  * Updates to the XMLURL class to correct a lot of parsing problems
00198  * and to add support for the port number. Updated the URL tests
00199  * to test some of this new stuff.
00200  *
00201  * Revision 1.10  2000/03/20 23:00:46  rahulj
00202  * Moved the inline definition of stringLen before the first
00203  * use. This satisfied the HP CC compiler.
00204  *
00205  * Revision 1.9  2000/03/02 19:54:49  roddey
00206  * This checkin includes many changes done while waiting for the
00207  * 1.1.0 code to be finished. I can't list them all here, but a list is
00208  * available elsewhere.
00209  *
00210  * Revision 1.8  2000/02/24 20:05:26  abagchi
00211  * Swat for removing Log from API docs
00212  *
00213  * Revision 1.7  2000/02/16 18:51:52  roddey
00214  * Fixed some facts in the docs and reformatted the docs to stay within
00215  * a reasonable line width.
00216  *
00217  * Revision 1.6  2000/02/16 17:07:07  abagchi
00218  * Added API docs
00219  *
00220  * Revision 1.5  2000/02/06 07:48:06  rahulj
00221  * Year 2K copyright swat.
00222  *
00223  * Revision 1.4  2000/01/12 00:16:23  roddey
00224  * Changes to deal with multiply nested, relative pathed, entities and to deal
00225  * with the new URL class changes.
00226  *
00227  * Revision 1.3  1999/12/18 00:18:10  roddey
00228  * More changes to support the new, completely orthagonal support for
00229  * intrinsic encodings.
00230  *
00231  * Revision 1.2  1999/12/15 19:41:28  roddey
00232  * Support for the new transcoder system, where even intrinsic encodings are
00233  * done via the same transcoder abstraction as external ones.
00234  *
00235  * Revision 1.1.1.1  1999/11/09 01:05:52  twl
00236  * Initial checkin
00237  *
00238  * Revision 1.2  1999/11/08 20:45:21  rahul
00239  * Swat for adding in Product name and CVS comment log variable.
00240  *
00241  */
00242 
00243 #if !defined(XMLSTRING_HPP)
00244 #define XMLSTRING_HPP
00245 
00246 #include <xercesc/util/BaseRefVectorOf.hpp>
00247 #include <xercesc/framework/MemoryManager.hpp>
00248 #include <string.h>
00249 
00250 XERCES_CPP_NAMESPACE_BEGIN
00251 
00252 class XMLLCPTranscoder;
00264 class  XMLString
00265 {
00266 public:
00267     /* Static methods for native character mode string manipulation */
00268 
00269 
00286     static void catString
00287     (
00288                 char* const     target
00289         , const char* const     src
00290     );
00291 
00304     static void catString
00305     (
00306                 XMLCh* const    target
00307         , const XMLCh* const    src
00308     );
00310 
00324     static int compareIString
00325     (
00326         const   char* const     str1
00327         , const char* const     str2
00328     );
00329 
00340     static int compareIString
00341     (
00342         const   XMLCh* const    str1
00343         , const XMLCh* const    str2
00344     );
00345 
00346 
00360     static int compareNString
00361     (
00362         const   char* const     str1
00363         , const char* const     str2
00364         , const unsigned int    count
00365     );
00366 
00380     static int compareNString
00381     (
00382         const   XMLCh* const    str1
00383         , const XMLCh* const    str2
00384         , const unsigned int    count
00385     );
00386 
00387 
00401     static int compareNIString
00402     (
00403         const   char* const     str1
00404         , const char* const     str2
00405         , const unsigned int    count
00406     );
00407 
00422     static int compareNIString
00423     (
00424         const   XMLCh* const    str1
00425         , const XMLCh* const    str2
00426         , const unsigned int    count
00427     );
00428 
00441     static int compareString
00442     (
00443         const   char* const     str1
00444         , const char* const     str2
00445     );
00446 
00458     static int compareString
00459     (
00460         const   XMLCh* const    str1
00461         , const XMLCh* const    str2
00462     );
00463 
00472     static bool equals
00473     (
00474           const XMLCh* const    str1
00475         , const XMLCh* const    str2
00476     );
00477 
00478     static bool equals
00479     (
00480           const char* const    str1
00481         , const char* const    str2
00482     );
00483 
00510     static bool regionMatches
00511     (
00512         const   XMLCh* const    str1
00513         , const int             offset1
00514         , const XMLCh* const    str2
00515         , const int             offset2
00516         , const unsigned int    charCount
00517     );
00518 
00546     static bool regionIMatches
00547     (
00548         const   XMLCh* const    str1
00549         , const int             offset1
00550         , const XMLCh* const    str2
00551         , const int             offset2
00552         , const unsigned int    charCount
00553     );
00555 
00568     static void copyString
00569     (
00570                 char* const     target
00571         , const char* const     src
00572     );
00573 
00584     static void copyString
00585     (
00586                 XMLCh* const    target
00587         , const XMLCh* const    src
00588     );
00589 
00602     static bool copyNString
00603     (
00604                 XMLCh* const    target
00605         , const XMLCh* const    src
00606         , const unsigned int    maxChars
00607     );
00609 
00618     static unsigned int hash
00619     (
00620         const   char* const     toHash
00621         , const unsigned int    hashModulus
00622     );
00623 
00630     static unsigned int hash
00631     (
00632         const   XMLCh* const    toHash
00633         , const unsigned int    hashModulus
00634     );
00635 
00645     static unsigned int hashN
00646     (
00647         const   XMLCh* const    toHash
00648         , const unsigned int    numChars
00649         , const unsigned int    hashModulus
00650     );
00651 
00653 
00664     static int indexOf(const char* const toSearch, const char ch);
00665 
00674     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
00675 
00686     static int indexOf
00687     (
00688         const   char* const     toSearch
00689         , const char            chToFind
00690         , const unsigned int    fromIndex
00691     );
00692 
00703     static int indexOf
00704     (
00705         const   XMLCh* const    toSearch
00706         , const XMLCh           chToFind
00707         , const unsigned int    fromIndex
00708     );
00709 
00718     static int lastIndexOf(const char* const toSearch, const char ch);
00719 
00728     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
00729 
00739     static int lastIndexOf
00740     (
00741         const XMLCh ch
00742         , const XMLCh* const toSearch
00743         , const unsigned int toSearchLen
00744     );
00745 
00756     static int lastIndexOf
00757     (
00758         const   char* const     toSearch
00759         , const char            chToFind
00760         , const unsigned int    fromIndex
00761     );
00762 
00773     static int lastIndexOf
00774     (
00775         const   XMLCh* const    toSearch
00776         , const XMLCh           ch
00777         , const unsigned int    fromIndex
00778     );
00780 
00788     static void moveChars
00789     (
00790                 XMLCh* const    targetStr
00791         , const XMLCh* const    srcStr
00792         , const unsigned int    count
00793     );
00794 
00796 
00807     static void subString
00808     (
00809                 char* const    targetStr
00810         , const char* const    srcStr
00811         , const int            startIndex
00812         , const int            endIndex
00813     );
00814 
00823     static void subString
00824     (
00825                 XMLCh* const    targetStr
00826         , const XMLCh* const    srcStr
00827         , const int             startIndex
00828         , const int             endIndex
00829     );
00830 
00832 
00844     static char* replicate(const char* const toRep);
00845 
00846 
00847 
00856     static char* replicate(const char* const toRep,
00857                            MemoryManager* const manager);
00858 
00868     static XMLCh* replicate(const XMLCh* const toRep);
00869 
00870 
00879     static XMLCh* replicate(const XMLCh* const toRep,
00880                             MemoryManager* const manager);
00881 
00883 
00892     static bool startsWith
00893     (
00894         const   char* const     toTest
00895         , const char* const     prefix
00896     );
00897 
00904     static bool startsWith
00905     (
00906         const   XMLCh* const    toTest
00907         , const XMLCh* const    prefix
00908     );
00909 
00918     static bool startsWithI
00919     (
00920         const   char* const     toTest
00921         , const char* const     prefix
00922     );
00923 
00933     static bool startsWithI
00934     (
00935         const   XMLCh* const    toTest
00936         , const XMLCh* const    prefix
00937     );
00938 
00945     static bool endsWith
00946     (
00947         const   XMLCh* const    toTest
00948         , const XMLCh* const    suffix
00949     );
00950 
00951 
00960     static const XMLCh* findAny
00961     (
00962         const   XMLCh* const    toSearch
00963         , const XMLCh* const    searchList
00964     );
00965 
00974     static XMLCh* findAny
00975     (
00976                 XMLCh* const    toSearch
00977         , const XMLCh* const    searchList
00978     );
00979 
00986     static int patternMatch
00987     (
00988           const XMLCh* const    toSearch
00989         , const XMLCh* const    pattern
00990     );
00991 
00996     static unsigned int stringLen(const char* const src);
00997 
01002     static unsigned int stringLen(const XMLCh* const src);
01003 
01011     static bool isValidNCName(const XMLCh* const name);
01012 
01020     static bool isValidName(const XMLCh* const name);
01021 
01027     static bool isValidEncName(const XMLCh* const name);
01028 
01036     static bool isValidQName(const XMLCh* const name);
01037 
01044     static bool isAlpha(XMLCh const theChar);
01045 
01051     static bool isDigit(XMLCh const theChar);
01052 
01058     static bool isAlphaNum(XMLCh const theChar);
01059 
01065     static bool isHex(XMLCh const theChar);
01066 
01074     static bool isAllWhiteSpace(const XMLCh* const toCheck);
01075 
01081     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
01082 
01084 
01087 
01098     static void binToText
01099     (
01100         const   unsigned int    toFormat
01101         ,       char* const     toFill
01102         , const unsigned int    maxChars
01103         , const unsigned int    radix
01104     );
01105 
01116     static void binToText
01117     (
01118         const   unsigned int    toFormat
01119         ,       XMLCh* const    toFill
01120         , const unsigned int    maxChars
01121         , const unsigned int    radix
01122     );
01123 
01134     static void binToText
01135     (
01136         const   unsigned long   toFormat
01137         ,       char* const     toFill
01138         , const unsigned int    maxChars
01139         , const unsigned int    radix
01140     );
01141 
01152     static void binToText
01153     (
01154         const   unsigned long   toFormat
01155         ,       XMLCh* const    toFill
01156         , const unsigned int    maxChars
01157         , const unsigned int    radix
01158     );
01159 
01170     static void binToText
01171     (
01172         const   long            toFormat
01173         ,       char* const     toFill
01174         , const unsigned int    maxChars
01175         , const unsigned int    radix
01176     );
01177 
01188     static void binToText
01189     (
01190         const   long            toFormat
01191         ,       XMLCh* const    toFill
01192         , const unsigned int    maxChars
01193         , const unsigned int    radix
01194     );
01195 
01206     static void binToText
01207     (
01208         const   int             toFormat
01209         ,       char* const     toFill
01210         , const unsigned int    maxChars
01211         , const unsigned int    radix
01212     );
01213 
01224     static void binToText
01225     (
01226         const   int             toFormat
01227         ,       XMLCh* const    toFill
01228         , const unsigned int    maxChars
01229         , const unsigned int    radix
01230     );
01231 
01242     static bool textToBin
01243     (
01244         const   XMLCh* const    toConvert
01245         ,       unsigned int&   toFill
01246     );
01247 
01260     static int parseInt
01261     (
01262         const   XMLCh* const    toConvert
01263     );
01264 
01270     static void cut
01271     (
01272                 XMLCh* const    toCutFrom
01273         , const unsigned int    count
01274     );
01275 
01286     static char* transcode
01287     (
01288         const   XMLCh* const    toTranscode
01289     );
01290     static char* transcode
01291     (
01292         const   XMLCh* const         toTranscode
01293         ,       MemoryManager* const manager
01294     );
01295 
01310     static bool transcode
01311     (
01312         const   XMLCh* const    toTranscode
01313         ,       char* const     toFill
01314         , const unsigned int    maxChars
01315     );
01316 
01327     static XMLCh* transcode
01328     (
01329         const   char* const     toTranscode
01330     );
01331     static XMLCh* transcode
01332     (
01333         const   char* const          toTranscode
01334         ,       MemoryManager* const manager
01335     );
01336 
01346     static bool transcode
01347     (
01348         const   char* const     toTranscode
01349         ,       XMLCh* const    toFill
01350         , const unsigned int    maxChars
01351     );
01352 
01358     static void trim(char* const toTrim);
01359 
01365     static void trim(XMLCh* const toTrim);
01366 
01373     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc);
01374 
01376 
01387     static XMLCh* makeUName
01388     (
01389         const   XMLCh* const    pszURI
01390         , const XMLCh* const    pszName
01391     );
01392 
01408     static unsigned int replaceTokens
01409     (
01410                 XMLCh* const    errText
01411         , const unsigned int    maxChars
01412         , const XMLCh* const    text1
01413         , const XMLCh* const    text2
01414         , const XMLCh* const    text3
01415         , const XMLCh* const    text4
01416     );
01417 
01422     static void upperCase(XMLCh* const toUpperCase);
01423 
01428     static void lowerCase(XMLCh* const toLowerCase);
01429 
01433     static bool isWSReplaced(const XMLCh* const toCheck);
01434 
01438     static bool isWSCollapsed(const XMLCh* const toCheck);
01439 
01444     static void replaceWS(XMLCh* const toConvert);
01445 
01450     static void collapseWS(XMLCh* const toConvert);
01451 
01456     static void removeWS(XMLCh* const toConvert);
01457 
01465     static void fixURI(const XMLCh* const str, XMLCh* const target);
01466 
01468 
01476     static void release(char** buf);
01477 
01484     static void release(XMLCh** buf);
01485 
01492     static void release(XMLByte** buf);
01493 
01495 
01496 
01497 private :
01498 
01502     XMLString();
01504     ~XMLString();
01506 
01507 
01511     static void initString(XMLLCPTranscoder* const defToUse,
01512                            MemoryManager* const manager);
01513     static void termString();
01515 
01520     static bool validateRegion(const XMLCh* const str1, const int offset1,
01521                         const XMLCh* const str2, const int offset2,
01522                         const unsigned int charCount);
01523 
01524     static MemoryManager* fgMemoryManager;
01525 
01526     friend class XMLPlatformUtils;
01527 };
01528 
01529 
01530 // ---------------------------------------------------------------------------
01531 //  Inline some methods that are either just passthroughs to other string
01532 //  methods, or which are key for performance.
01533 // ---------------------------------------------------------------------------
01534 inline void XMLString::moveChars(       XMLCh* const targetStr
01535                                 , const XMLCh* const srcStr
01536                                 , const unsigned int count)
01537 {
01538     memcpy(targetStr, srcStr, count * sizeof(XMLCh));
01539 }
01540 
01541 inline unsigned int XMLString::stringLen(const XMLCh* const src)
01542 {
01543     if (src == 0 || *src == 0)
01544     {
01545         return 0;
01546    }
01547     else
01548    {
01549         const XMLCh* pszTmp = src + 1;
01550 
01551         while (*pszTmp)
01552             ++pszTmp;
01553 
01554         return (unsigned int)(pszTmp - src);
01555     }
01556 }
01557 
01558 inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
01559                                    MemoryManager* const manager)
01560 {
01561     // If a null string, return a null string!
01562     XMLCh* ret = 0;
01563     if (toRep)
01564     {
01565         const unsigned int len = stringLen(toRep);
01566         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
01567         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
01568     }
01569     return ret;
01570 }
01571 
01572 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
01573                                     , const XMLCh* const    prefix)
01574 {
01575     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
01576 }
01577 
01578 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
01579                                     , const XMLCh* const    prefix)
01580 {
01581     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
01582 }
01583 
01584 inline bool XMLString::endsWith(const XMLCh* const toTest,
01585                                 const XMLCh* const suffix)
01586 {
01587 
01588     unsigned int suffixLen = XMLString::stringLen(suffix);
01589 
01590     return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
01591                          suffix, 0, suffixLen);
01592 }
01593 
01594 inline bool XMLString::validateRegion(const XMLCh* const str1,
01595                                       const int offset1,
01596                                       const XMLCh* const str2,
01597                                       const int offset2,
01598                                       const unsigned int charCount)
01599 {
01600 
01601     if (offset1 < 0 || offset2 < 0 ||
01602         (offset1 + charCount) > XMLString::stringLen(str1) ||
01603         (offset2 + charCount) > XMLString::stringLen(str2) )
01604         return false;
01605 
01606     return true;
01607 }
01608 
01609 inline bool XMLString::equals(   const XMLCh* const    str1
01610                                , const XMLCh* const    str2)
01611 {
01612     const XMLCh* psz1 = str1;
01613     const XMLCh* psz2 = str2;
01614 
01615     if (psz1 == 0 || psz2 == 0) {
01616         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01617             return false;
01618         else
01619             return true;
01620     }
01621 
01622     while (*psz1 == *psz2)
01623     {
01624         // If either has ended, then they both ended, so equal
01625         if (!*psz1)
01626             return true;
01627 
01628         // Move upwards for the next round
01629         psz1++;
01630         psz2++;
01631     }
01632     return false;
01633 }
01634 
01635 inline bool XMLString::equals(   const char* const    str1
01636                                , const char* const    str2)
01637 {
01638     const char* psz1 = str1;
01639     const char* psz2 = str2;
01640 
01641     if (psz1 == 0 || psz2 == 0) {
01642         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
01643             return false;
01644         else
01645             return true;
01646     }
01647 
01648     while (*psz1 == *psz2)
01649     {
01650         // If either has ended, then they both ended, so equal
01651         if (!*psz1)
01652             return true;
01653 
01654         // Move upwards for the next round
01655         psz1++;
01656         psz2++;
01657     }
01658     return false;
01659 }
01660 
01661 inline int XMLString::lastIndexOf(const XMLCh* const toSearch, const XMLCh ch)
01662 {
01663     return XMLString::lastIndexOf(ch, toSearch, stringLen(toSearch));
01664 }
01665 
01666 XERCES_CPP_NAMESPACE_END
01667 
01668 #endif


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