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

Home

Readme
Installation
Build

API Docs
Samples
Programming
Migration
FAQs

Releases
Feedback

PDF Document

Download
Dev Snapshots
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-2000 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  2000/04/12 18:42:15  roddey
00060  * Improved docs in terms of what 'max chars' means in the method
00061  * parameters.
00062  *
00063  * Revision 1.12  2000/04/06 19:42:51  rahulj
00064  * Clarified how big the target buffer should be in the API
00065  * documentation.
00066  *
00067  * Revision 1.11  2000/03/23 01:02:38  roddey
00068  * Updates to the XMLURL class to correct a lot of parsing problems
00069  * and to add support for the port number. Updated the URL tests
00070  * to test some of this new stuff.
00071  *
00072  * Revision 1.10  2000/03/20 23:00:46  rahulj
00073  * Moved the inline definition of stringLen before the first
00074  * use. This satisfied the HP CC compiler.
00075  *
00076  * Revision 1.9  2000/03/02 19:54:49  roddey
00077  * This checkin includes many changes done while waiting for the
00078  * 1.1.0 code to be finished. I can't list them all here, but a list is
00079  * available elsewhere.
00080  *
00081  * Revision 1.8  2000/02/24 20:05:26  abagchi
00082  * Swat for removing Log from API docs
00083  *
00084  * Revision 1.7  2000/02/16 18:51:52  roddey
00085  * Fixed some facts in the docs and reformatted the docs to stay within
00086  * a reasonable line width.
00087  *
00088  * Revision 1.6  2000/02/16 17:07:07  abagchi
00089  * Added API docs
00090  *
00091  * Revision 1.5  2000/02/06 07:48:06  rahulj
00092  * Year 2K copyright swat.
00093  *
00094  * Revision 1.4  2000/01/12 00:16:23  roddey
00095  * Changes to deal with multiply nested, relative pathed, entities and to deal
00096  * with the new URL class changes.
00097  *
00098  * Revision 1.3  1999/12/18 00:18:10  roddey
00099  * More changes to support the new, completely orthagonal support for
00100  * intrinsic encodings.
00101  *
00102  * Revision 1.2  1999/12/15 19:41:28  roddey
00103  * Support for the new transcoder system, where even intrinsic encodings are
00104  * done via the same transcoder abstraction as external ones.
00105  *
00106  * Revision 1.1.1.1  1999/11/09 01:05:52  twl
00107  * Initial checkin
00108  *
00109  * Revision 1.2  1999/11/08 20:45:21  rahul
00110  * Swat for adding in Product name and CVS comment log variable.
00111  *
00112  */
00113 
00114 #if !defined(XMLSTRING_HPP)
00115 #define XMLSTRING_HPP
00116 
00117 #include <util/XercesDefs.hpp>
00118 
00119 class XMLLCPTranscoder;
00120 
00132 class  XMLString
00133 {
00134 public:
00135     /* Static methods for native character mode string manipulation */
00137     //@{
00138 
00149     static void binToText
00150     (
00151         const   unsigned int    toFormat
00152         ,       char* const     toFill
00153         , const unsigned int    maxChars
00154         , const unsigned int    radix
00155     );
00156 
00167     static void binToText
00168     (
00169         const   unsigned int    toFormat
00170         ,       XMLCh* const    toFill
00171         , const unsigned int    maxChars
00172         , const unsigned int    radix
00173     );
00174 
00185     static void binToText
00186     (
00187         const   unsigned long   toFormat
00188         ,       char* const     toFill
00189         , const unsigned int    maxChars
00190         , const unsigned int    radix
00191     );
00192 
00203     static void binToText
00204     (
00205         const   unsigned long   toFormat
00206         ,       XMLCh* const    toFill
00207         , const unsigned int    maxChars
00208         , const unsigned int    radix
00209     );
00210 
00221     static void binToText
00222     (
00223         const   long            toFormat
00224         ,       char* const     toFill
00225         , const unsigned int    maxChars
00226         , const unsigned int    radix
00227     );
00228 
00239     static void binToText
00240     (
00241         const   long            toFormat
00242         ,       XMLCh* const    toFill
00243         , const unsigned int    maxChars
00244         , const unsigned int    radix
00245     );
00246 
00257     static void binToText
00258     (
00259         const   int             toFormat
00260         ,       char* const     toFill
00261         , const unsigned int    maxChars
00262         , const unsigned int    radix
00263     );
00264 
00275     static void binToText
00276     (
00277         const   int             toFormat
00278         ,       XMLCh* const    toFill
00279         , const unsigned int    maxChars
00280         , const unsigned int    radix
00281     );
00282 
00293     static bool textToBin
00294     (
00295         const   XMLCh* const    toConvert
00296         ,       unsigned int&   toFill
00297     );
00298     //@}
00299 
00301     //@{
00316     static void catString
00317     (
00318                 char* const     target
00319         , const char* const     src
00320     );
00321 
00334     static void catString
00335     (
00336                 XMLCh* const    target
00337         , const XMLCh* const    src
00338     );
00339     //@}
00340 
00342     //@{
00354     static int compareIString
00355     (
00356         const   char* const     str1
00357         , const char* const     str2
00358     );
00359 
00370     static int compareIString
00371     (
00372         const   XMLCh* const    str1
00373         , const XMLCh* const    str2
00374     );
00375 
00376 
00390     static int compareNString
00391     (
00392         const   char* const     str1
00393         , const char* const     str2
00394         , const unsigned int    count
00395     );
00396 
00410     static int compareNString
00411     (
00412         const   XMLCh* const    str1
00413         , const XMLCh* const    str2
00414         , const unsigned int    count
00415     );
00416 
00417 
00431     static int compareNIString
00432     (
00433         const   char* const     str1
00434         , const char* const     str2
00435         , const unsigned int    count
00436     );
00437 
00452     static int compareNIString
00453     (
00454         const   XMLCh* const    str1
00455         , const XMLCh* const    str2
00456         , const unsigned int    count
00457     );
00458 
00471     static int compareString
00472     (
00473         const   char* const     str1
00474         , const char* const     str2
00475     );
00476 
00488     static int compareString
00489     (
00490         const   XMLCh* const    str1
00491         , const XMLCh* const    str2
00492     );
00493     //@}
00494 
00496     //@{
00507     static void copyString
00508     (
00509                 char* const     target
00510         , const char* const     src
00511     );
00512 
00523     static void copyString
00524     (
00525                 XMLCh* const    target
00526         , const XMLCh* const    src
00527     );
00528 
00541     static bool copyNString
00542     (
00543                 XMLCh* const    target
00544         , const XMLCh* const    src
00545         , const unsigned int    maxChars
00546     );
00547     //@}
00548 
00550     //@{
00557     static unsigned int hash
00558     (
00559         const   char* const     tohash
00560         , const unsigned int    hashModulus
00561     );
00562 
00569     static unsigned int hash
00570     (
00571         const   XMLCh* const    toHash
00572         , const unsigned int    hashModulus
00573     );
00574 
00584     static unsigned int hashN
00585     (
00586         const   XMLCh* const    toHash
00587         , const unsigned int    numChars
00588         , const unsigned int    hashModulus
00589     );
00590 
00591     //@}
00592 
00594     //@{
00603     static int indexOf(const char* const toSearch, const char ch);
00604 
00613     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
00614 
00623     static int lastIndexOf(const char* const toSearch, const char ch);
00624 
00633     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
00634 
00645     static int lastIndexOf
00646     (
00647         const   char* const     toSearch
00648         , const char            chToFind
00649         , const unsigned int    fromIndex
00650     );
00651 
00662     static int lastIndexOf
00663     (
00664         const   XMLCh* const    toSearch
00665         , const XMLCh           ch
00666         , const unsigned int    fromIndex
00667     );
00668     //@}
00669 
00671     //@{
00677     static void moveChars
00678     (
00679                 XMLCh* const    targetStr
00680         , const XMLCh* const    srcStr
00681         , const unsigned int    count
00682     );
00683 
00684     //@}
00685 
00687     //@{
00692     static char* replicate(const char* const toRep);
00693 
00698     static XMLCh* replicate(const XMLCh* const toRep);
00699 
00700     //@}
00701 
00703     //@{
00710     static bool startsWith
00711     (
00712         const   char* const     toTest
00713         , const char* const     prefix
00714     );
00715 
00722     static bool startsWith
00723     (
00724         const   XMLCh* const    toTest
00725         , const XMLCh* const    prefix
00726     );
00727 
00736     static bool startsWithI
00737     (
00738         const   char* const     toTest
00739         , const char* const     prefix
00740     );
00741 
00751     static bool startsWithI
00752     (
00753         const   XMLCh* const    toTest
00754         , const XMLCh* const    prefix
00755     );
00756 
00763     static const XMLCh* findAny
00764     (
00765         const   XMLCh* const    toSearch
00766         , const XMLCh* const    searchList
00767     );
00768 
00775     static XMLCh* findAny
00776     (
00777                 XMLCh* const    toSearch
00778         , const XMLCh* const    searchList
00779     );
00780 
00785     static unsigned int stringLen(const char* const src);
00786 
00791     static unsigned int stringLen(const XMLCh* const src);
00792     //@}
00793 
00795     //@{
00796 
00802     static void cut
00803     (
00804                 XMLCh* const    toCutFrom
00805         , const unsigned int    count
00806     );
00807 
00816     static char* transcode
00817     (
00818         const   XMLCh* const    toTranscode
00819     );
00820 
00837     static bool transcode
00838     (
00839         const   XMLCh* const    toTranscode
00840         ,       char* const     toFill
00841         , const unsigned int    maxChars
00842     );
00843 
00852     static XMLCh* transcode
00853     (
00854         const   char* const     toTranscode
00855     );
00856 
00868     static bool transcode
00869     (
00870         const   char* const     toTranscode
00871         ,       XMLCh* const    toFill
00872         , const unsigned int    maxChars
00873     );
00874 
00879     static void trim(char* const toTrim);
00880 
00885     static void trim(XMLCh* const toTrim);
00886     //@}
00887 
00889     //@{
00898     static XMLCh* makeUName
00899     (
00900         const   XMLCh* const    pszURI
00901         , const XMLCh* const    pszName
00902     );
00903 
00919     static unsigned int replaceTokens
00920     (
00921                 XMLCh* const    errText
00922         , const unsigned int    maxChars
00923         , const XMLCh* const    text1
00924         , const XMLCh* const    text2
00925         , const XMLCh* const    text3
00926         , const XMLCh* const    text4
00927     );
00928 
00933     static void upperCase(XMLCh* const toUpperCase);
00934     //@}
00935 
00936 
00937 private :
00938     
00940     //@{
00942     XMLString();
00944     ~XMLString();
00945     //@}
00946 
00947 
00949     //@{
00951     static void initString(XMLLCPTranscoder* const defToUse);
00952     static void termString();
00953     //@}
00954     friend class XMLPlatformUtils;
00955 };
00956 
00957 
00958 // ---------------------------------------------------------------------------
00959 //  Inline some methods that are either just passthroughs to other string
00960 //  methods, or which are key for performance.
00961 // ---------------------------------------------------------------------------
00962 inline void XMLString::moveChars(       XMLCh* const    targetStr
00963                                 , const XMLCh* const    srcStr
00964                                 , const unsigned int    count)
00965 {
00966     XMLCh* outPtr = targetStr;
00967     const XMLCh* inPtr = srcStr;
00968     for (unsigned int index = 0; index < count; index++)
00969         *outPtr++ = *inPtr++;
00970 }
00971 
00972 inline unsigned int XMLString::stringLen(const XMLCh* const src)
00973 {
00974     unsigned int len = 0;
00975     if (src)
00976     {
00977         const XMLCh* pszTmp = src;
00978         while (*pszTmp++)
00979             len++;
00980     }
00981     return len;
00982 }
00983 
00984 inline bool XMLString::startsWith(  const   XMLCh* const    toTest
00985                                     , const XMLCh* const    prefix)
00986 {
00987     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
00988 }
00989 
00990 inline bool XMLString::startsWithI( const   XMLCh* const    toTest
00991                                     , const XMLCh* const    prefix)
00992 {
00993     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
00994 }
00995 
00996 inline XMLCh* XMLString::replicate(const XMLCh* const toRep)
00997 {
00998     // If a null string, return a null string!
00999     XMLCh* ret = 0;
01000     if (toRep)
01001     {
01002         const unsigned int len = stringLen(toRep);
01003         ret = new XMLCh[len + 1];
01004         XMLCh* outPtr = ret;
01005         const XMLCh* inPtr = toRep;
01006         for (unsigned int index = 0; index <= len; index++)
01007             *outPtr++ = *inPtr++;
01008     }
01009     return ret;
01010 }
01011 
01012 #endif


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