XMLString.hpp
上传用户:zhuqijet
上传日期:2013-06-25
资源大小:10074k
文件大小:59k
源码类别:

词法分析

开发平台:

Visual C++

  1. /*
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 1999-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Xerces" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation, and was
  51.  * originally based on software copyright (c) 1999, International
  52.  * Business Machines, Inc., http://www.ibm.com .  For more information
  53.  * on the Apache Software Foundation, please see
  54.  * <http://www.apache.org/>.
  55.  */
  56. /*
  57.  * $Log: XMLString.hpp,v $
  58.  * Revision 1.17  2003/05/18 14:02:05  knoaman
  59.  * Memory manager implementation: pass per instance manager.
  60.  *
  61.  * Revision 1.16  2003/05/15 19:07:46  knoaman
  62.  * Partial implementation of the configurable memory manager.
  63.  *
  64.  * Revision 1.15  2003/04/21 20:07:05  knoaman
  65.  * Performance: use memcpy in moveChars and replicate.
  66.  *
  67.  * Revision 1.14  2003/02/25 16:42:31  tng
  68.  * [Bug 7072] Documentation for XMLString::transcode states invalid return value.
  69.  *
  70.  * Revision 1.13  2003/02/05 18:50:56  tng
  71.  * [Bug 11915] Utility for freeing memory.
  72.  *
  73.  * Revision 1.12  2003/01/24 23:16:33  peiyongz
  74.  * removeWS() added;
  75.  *
  76.  * Revision 1.11  2002/12/20 22:10:21  tng
  77.  * XML 1.1
  78.  *
  79.  * Revision 1.10  2002/12/18 14:17:54  gareth
  80.  * Fix to bug #13438. When you eant a vector that calls delete[] on its members you should use RefArrayVectorOf.
  81.  *
  82.  * Revision 1.9  2002/12/04 02:32:43  knoaman
  83.  * #include cleanup.
  84.  *
  85.  * Revision 1.8  2002/11/05 17:42:39  peiyongz
  86.  * equals( const char* const, const char* const)
  87.  *
  88.  * Revision 1.7  2002/11/04 15:22:05  tng
  89.  * C++ Namespace Support.
  90.  *
  91.  * Revision 1.6  2002/10/01 19:45:22  tng
  92.  * Performance in XMLString::equals, only need to check one string for null as they are equal already.
  93.  *
  94.  * Revision 1.5  2002/09/24 19:41:21  tng
  95.  * New inline function equals that is modified from compareString but simply return true or false.
  96.  *
  97.  * Revision 1.4  2002/09/23 18:42:18  tng
  98.  * DOM L3: Support baseURI.   Add utility fixURI to transform an absolute path filename to standard URI form.
  99.  *
  100.  * Revision 1.3  2002/08/27 19:24:43  peiyongz
  101.  * Bug#12087: patch from Thomas Ford (tom@decisionsoft.com)
  102.  *
  103.  * Revision 1.2  2002/02/20 18:17:02  tng
  104.  * [Bug 5977] Warnings on generating apiDocs.
  105.  *
  106.  * Revision 1.1.1.1  2002/02/01 22:22:16  peiyongz
  107.  * sane_include
  108.  *
  109.  * Revision 1.26  2001/08/10 16:23:06  peiyongz
  110.  * isHex(), isAlphaNum(), isAllWhiteSpace() and patternMatch() Added
  111.  *
  112.  * Revision 1.25  2001/07/06 20:27:57  peiyongz
  113.  * isValidaQName()
  114.  *
  115.  * Revision 1.24  2001/07/04 14:38:20  peiyongz
  116.  * IDDatatypeValidator: created
  117.  * DatatypeValidatorFactory: IDDTV enabled
  118.  * XMLString:isValidName(): to validate Name (XML [4][5])
  119.  *
  120.  * Revision 1.23  2001/06/13 14:07:55  peiyongz
  121.  * isValidaEncName() to validate an encoding name (EncName)
  122.  *
  123.  * Revision 1.22  2001/05/23 15:44:51  tng
  124.  * Schema: NormalizedString fix.  By Pei Yong Zhang.
  125.  *
  126.  * Revision 1.21  2001/05/11 13:26:31  tng
  127.  * Copyright update.
  128.  *
  129.  * Revision 1.20  2001/05/09 18:43:30  tng
  130.  * Add StringDatatypeValidator and BooleanDatatypeValidator.  By Pei Yong Zhang.
  131.  *
  132.  * Revision 1.19  2001/05/03 20:34:35  tng
  133.  * Schema: SchemaValidator update
  134.  *
  135.  * Revision 1.18  2001/05/03 19:17:35  knoaman
  136.  * TraverseSchema Part II.
  137.  *
  138.  * Revision 1.17  2001/03/21 21:56:13  tng
  139.  * Schema: Add Schema Grammar, Schema Validator, and split the DTDValidator into DTDValidator, DTDScanner, and DTDGrammar.
  140.  *
  141.  * Revision 1.16  2001/03/02 20:52:46  knoaman
  142.  * Schema: Regular expression - misc. updates for error messages,
  143.  * and additions of new functions to XMLString class.
  144.  *
  145.  * Revision 1.15  2001/01/15 21:26:34  tng
  146.  * Performance Patches by David Bertoni.
  147.  *
  148.  * Details: (see xerces-c-dev mailing Jan 14)
  149.  * XMLRecognizer.cpp: the internal encoding string XMLUni::fgXMLChEncodingString
  150.  * was going through this function numerous times.  As a result, the top hot-spot
  151.  * for the parse was _wcsicmp().  The real problem is that the Microsofts wide string
  152.  * functions are unbelievably slow.  For things like encodings, it might be
  153.  * better to use a special comparison function that only considers a-z and
  154.  * A-Z as characters with case.  This works since the character set for
  155.  * encodings is limit to printable ASCII characters.
  156.  *
  157.  *  XMLScanner2.cpp: This also has some case-sensitive vs. insensitive compares.
  158.  * They are also much faster.  The other tweak is to only make a copy of an attribute
  159.  * string if it needs to be split.  And then, the strategy is to try to use a
  160.  * stack-based buffer, rather than a dynamically-allocated one.
  161.  *
  162.  * SAX2XMLReaderImpl.cpp: Again, more case-sensitive vs. insensitive comparisons.
  163.  *
  164.  * KVStringPair.cpp & hpp: By storing the size of the allocation, the storage can
  165.  * likely be re-used many times, cutting down on dynamic memory allocations.
  166.  *
  167.  * XMLString.hpp: a more efficient implementation of stringLen().
  168.  *
  169.  * DTDValidator.cpp: another case of using a stack-based buffer when possible
  170.  *
  171.  * These patches made a big difference in parse time in some of our test
  172.  * files, especially the ones are very attribute-heavy.
  173.  *
  174.  * Revision 1.14  2000/10/13 22:47:57  andyh
  175.  * Fix bug (failure to null-terminate result) in XMLString::trim().
  176.  * Patch contributed by Nadav Aharoni
  177.  *
  178.  * Revision 1.13  2000/04/12 18:42:15  roddey
  179.  * Improved docs in terms of what 'max chars' means in the method
  180.  * parameters.
  181.  *
  182.  * Revision 1.12  2000/04/06 19:42:51  rahulj
  183.  * Clarified how big the target buffer should be in the API
  184.  * documentation.
  185.  *
  186.  * Revision 1.11  2000/03/23 01:02:38  roddey
  187.  * Updates to the XMLURL class to correct a lot of parsing problems
  188.  * and to add support for the port number. Updated the URL tests
  189.  * to test some of this new stuff.
  190.  *
  191.  * Revision 1.10  2000/03/20 23:00:46  rahulj
  192.  * Moved the inline definition of stringLen before the first
  193.  * use. This satisfied the HP CC compiler.
  194.  *
  195.  * Revision 1.9  2000/03/02 19:54:49  roddey
  196.  * This checkin includes many changes done while waiting for the
  197.  * 1.1.0 code to be finished. I can't list them all here, but a list is
  198.  * available elsewhere.
  199.  *
  200.  * Revision 1.8  2000/02/24 20:05:26  abagchi
  201.  * Swat for removing Log from API docs
  202.  *
  203.  * Revision 1.7  2000/02/16 18:51:52  roddey
  204.  * Fixed some facts in the docs and reformatted the docs to stay within
  205.  * a reasonable line width.
  206.  *
  207.  * Revision 1.6  2000/02/16 17:07:07  abagchi
  208.  * Added API docs
  209.  *
  210.  * Revision 1.5  2000/02/06 07:48:06  rahulj
  211.  * Year 2K copyright swat.
  212.  *
  213.  * Revision 1.4  2000/01/12 00:16:23  roddey
  214.  * Changes to deal with multiply nested, relative pathed, entities and to deal
  215.  * with the new URL class changes.
  216.  *
  217.  * Revision 1.3  1999/12/18 00:18:10  roddey
  218.  * More changes to support the new, completely orthagonal support for
  219.  * intrinsic encodings.
  220.  *
  221.  * Revision 1.2  1999/12/15 19:41:28  roddey
  222.  * Support for the new transcoder system, where even intrinsic encodings are
  223.  * done via the same transcoder abstraction as external ones.
  224.  *
  225.  * Revision 1.1.1.1  1999/11/09 01:05:52  twl
  226.  * Initial checkin
  227.  *
  228.  * Revision 1.2  1999/11/08 20:45:21  rahul
  229.  * Swat for adding in Product name and CVS comment log variable.
  230.  *
  231.  */
  232. #if !defined(XMLSTRING_HPP)
  233. #define XMLSTRING_HPP
  234. #include <xercesc/util/BaseRefVectorOf.hpp>
  235. #include <xercesc/framework/MemoryManager.hpp>
  236. #include <string.h>
  237. XERCES_CPP_NAMESPACE_BEGIN
  238. class XMLLCPTranscoder;
  239. /**
  240.   * Class for representing native character strings and handling common string
  241.   * operations
  242.   *
  243.   * This class is Unicode compliant. This class is designed primarily
  244.   * for internal use, but due to popular demand, it is being made
  245.   * publicly available. Users of this class must understand that this
  246.   * is not an officially supported class. All public methods of this
  247.   * class are <i>static functions</i>.
  248.   *
  249.   */
  250. class XMLUTIL_EXPORT XMLString
  251. {
  252. public:
  253.     /* Static methods for native character mode string manipulation */
  254.     /** @name String concatenation functions */
  255.     //@{
  256.     /** Concatenates two strings.
  257.       *
  258.       * <code>catString</code> appends <code>src</code> to <code>target</code> and
  259.       * terminates the resulting string with a null character. The initial character
  260.       * of <code>src</code> overwrites the terminating character of <code>target
  261.       * </code>.
  262.       *
  263.       * No overflow checking is performed when strings are copied or appended.
  264.       * The behavior of <code>catString</code> is undefined if source and
  265.       * destination strings overlap.
  266.       *
  267.       * @param target Null-terminated destination string
  268.       * @param src Null-terminated source string
  269.       */
  270.     static void catString
  271.     (
  272.                 char* const     target
  273.         , const char* const     src
  274.     );
  275.     /** Concatenates two strings.
  276.       *
  277.       * <code>catString</code> appends <code>src</code> to <code>target</code> and
  278.       * terminates the resulting string with a null character. The initial character of
  279.       * <code>src</code> overwrites the terminating character of <code>target</code>.
  280.       * No overflow checking is performed when strings are copied or appended.
  281.       * The behavior of <code>catString</code> is undefined if source and destination
  282.       * strings overlap.
  283.       *
  284.       *    @param target Null-terminated destination string
  285.       * @param src Null-terminated source string
  286.       */
  287.     static void catString
  288.     (
  289.                 XMLCh* const    target
  290.         , const XMLCh* const    src
  291.     );
  292.     //@}
  293.     /** @name String comparison functions */
  294.     //@{
  295.     /** Lexicographically compares lowercase versions of <code>str1</code> and
  296.       * <code>str2</code> and returns a value indicating their relationship.
  297.       * @param str1 Null-terminated string to compare
  298.       * @param str2 Null-terminated string to compare
  299.       *
  300.       * @return The return value indicates the relation of <code>str1</code> to
  301.       * <code>str2</code> as follows
  302.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  303.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  304.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  305.       */
  306.     static int compareIString
  307.     (
  308.         const   char* const     str1
  309.         , const char* const     str2
  310.     );
  311.     /** Lexicographically compares lowercase versions of <code>str1</code> and
  312.       * <code>str2</code> and returns a value indicating their relationship.
  313.       * @param str1 Null-terminated string to compare
  314.       * @param str2 Null-terminated string to compare
  315.       * @return The return value indicates the relation of <code>str1</code> to
  316.       * <code>str2</code> as follows
  317.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  318.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  319.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  320.       */
  321.     static int compareIString
  322.     (
  323.         const   XMLCh* const    str1
  324.         , const XMLCh* const    str2
  325.     );
  326.     /** Lexicographically compares, at most, the first count characters in
  327.       * <code>str1</code> and <code>str2</code> and returns a value indicating the
  328.       * relationship between the substrings.
  329.       * @param str1 Null-terminated string to compare
  330.       * @param str2 Null-terminated string to compare
  331.       * @param count The number of characters to compare
  332.       *
  333.       * @return The return value indicates the relation of <code>str1</code> to
  334.       * <code>str2</code> as follows
  335.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  336.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  337.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  338.       */
  339.     static int compareNString
  340.     (
  341.         const   char* const     str1
  342.         , const char* const     str2
  343.         , const unsigned int    count
  344.     );
  345.     /** Lexicographically compares, at most, the first count characters in
  346.       * <code>str1</code> and <code>str2</code> and returns a value indicating
  347.       * the relationship between the substrings.
  348.       * @param str1 Null-terminated string to compare
  349.       * @param str2 Null-terminated string to compare
  350.       * @param count The number of characters to compare
  351.       *
  352.       * @return The return value indicates the relation of <code>str1</code> to
  353.       * <code>str2</code> as follows
  354.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  355.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  356.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  357.       */
  358.     static int compareNString
  359.     (
  360.         const   XMLCh* const    str1
  361.         , const XMLCh* const    str2
  362.         , const unsigned int    count
  363.     );
  364.     /** Lexicographically compares, at most, the first count characters in
  365.       * <code>str1</code> and <code>str2</code> without regard to case and
  366.       * returns a value indicating the relationship between the substrings.
  367.       *
  368.       * @param str1 Null-terminated string to compare
  369.       * @param str2 Null-terminated string to compare
  370.       * @param count The number of characters to compare
  371.       * @return The return value indicates the relation of <code>str1</code> to
  372.       * <code>str2</code> as follows
  373.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  374.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  375.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  376.       */
  377.     static int compareNIString
  378.     (
  379.         const   char* const     str1
  380.         , const char* const     str2
  381.         , const unsigned int    count
  382.     );
  383.     /** Lexicographically compares, at most, the first count characters in
  384.       * <code>str1</code> and <code>str2</code> without regard to case and
  385.       * returns a value indicating the relationship between the substrings.
  386.       *
  387.       * @param str1 Null-terminated string to compare
  388.       * @param str2 Null-terminated string to compare
  389.       * @param count The number of characters to compare
  390.       *
  391.       * @return The return value indicates the relation of <code>str1</code> to
  392.       * <code>str2</code> as follows
  393.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  394.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  395.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  396.       */
  397.     static int compareNIString
  398.     (
  399.         const   XMLCh* const    str1
  400.         , const XMLCh* const    str2
  401.         , const unsigned int    count
  402.     );
  403.     /** Lexicographically compares <code>str1</code> and <code>str2</code> and
  404.       * returns a value indicating their relationship.
  405.       *
  406.       * @param str1 Null-terminated string to compare
  407.       * @param str2 Null-terminated string to compare
  408.       *
  409.       * @return The return value indicates the relation of <code>str1</code> to
  410.       * <code>str2</code> as follows
  411.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  412.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  413.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  414.       */
  415.     static int compareString
  416.     (
  417.         const   char* const     str1
  418.         , const char* const     str2
  419.     );
  420.     /** Lexicographically compares <code>str1</code> and <code>str2</code> and
  421.       * returns a value indicating their relationship.
  422.       *
  423.       * @param str1 Null-terminated string to compare
  424.       * @param str2 Null-terminated string to compare
  425.       * @return The return value indicates the relation of <code>str1</code> to
  426.       * <code>str2</code> as follows
  427.       *  Less than 0 means <code>str1</code> is less than <code>str2</code>
  428.       *  Equal to 0 means <code>str1</code> is identical to <code>str2</code>
  429.       *  Greater than 0 means <code>str1</code> is more than <code>str2</code>
  430.       */
  431.     static int compareString
  432.     (
  433.         const   XMLCh* const    str1
  434.         , const XMLCh* const    str2
  435.     );
  436.     /** compares <code>str1</code> and <code>str2</code>
  437.       *
  438.       * @param str1 Null-terminated string to compare
  439.       * @param str2 Null-terminated string to compare
  440.       * @return true if two strings are equal, false if not
  441.       *  If one string is null, while the other is zero-length string,
  442.       *  it is considered as equal.
  443.       */
  444.     static bool equals
  445.     (
  446.           const XMLCh* const    str1
  447.         , const XMLCh* const    str2
  448.     );
  449.     static bool equals
  450.     (
  451.           const char* const    str1
  452.         , const char* const    str2
  453.     );
  454. /** Lexicographically compares <code>str1</code> and <code>str2</code>
  455.   * regions and returns true if they are equal, otherwise false.
  456.   *
  457.       * A substring of <code>str1</code> is compared to a substring of
  458.   * <code>str2</code>. The result is true if these substrings represent
  459.   * identical character sequences. The substring of <code>str1</code>
  460.       * to be compared begins at offset1 and has length charCount. The
  461.   * substring of <code>str2</code> to be compared begins at offset2 and
  462.   * has length charCount. The result is false if and only if at least
  463.       * one of the following is true:
  464.       *   offset1 is negative.
  465.       *   offset2 is negative.
  466.       *   offset1+charCount is greater than the length of str1.
  467.       *   offset2+charCount is greater than the length of str2.
  468.       *   There is some nonnegative integer k less than charCount such that:
  469.       *   str1.charAt(offset1+k) != str2.charAt(offset2+k)
  470.       *
  471.       * @param str1 Null-terminated string to compare
  472.   * @param offset1 Starting offset of str1
  473.       * @param str2 Null-terminated string to compare
  474.   * @param offset2 Starting offset of str2
  475.   * @param charCount The number of characters to compare
  476.       * @return true if the specified subregion of <code>str1</code> exactly
  477.   *  matches the specified subregion of <code>str2></code>; false
  478.   *  otherwise.
  479.       */
  480.     static bool regionMatches
  481.     (
  482.         const   XMLCh* const    str1
  483. , const int offset1
  484.         , const XMLCh* const    str2
  485. , const int offset2
  486. , const unsigned int charCount
  487.     );
  488. /** Lexicographically compares <code>str1</code> and <code>str2</code>
  489.   * regions without regard to case and returns true if they are equal,
  490.   * otherwise false.
  491.   *
  492.       * A substring of <code>str1</code> is compared to a substring of
  493.   * <code>str2</code>. The result is true if these substrings represent
  494.   * identical character sequences. The substring of <code>str1</code>
  495.       * to be compared begins at offset1 and has length charCount. The
  496.   * substring of <code>str2</code> to be compared begins at offset2 and
  497.   * has length charCount. The result is false if and only if at least
  498.       * one of the following is true:
  499.       *   offset1 is negative.
  500.       *   offset2 is negative.
  501.       *   offset1+charCount is greater than the length of str1.
  502.       *   offset2+charCount is greater than the length of str2.
  503.       *   There is some nonnegative integer k less than charCount such that:
  504.       *   str1.charAt(offset1+k) != str2.charAt(offset2+k)
  505.       *
  506.       * @param str1 Null-terminated string to compare
  507.   * @param offset1 Starting offset of str1
  508.       * @param str2 Null-terminated string to compare
  509.   * @param offset2 Starting offset of str2
  510.   * @param charCount The number of characters to compare
  511.       * @return true if the specified subregion of <code>str1</code> exactly
  512.   *  matches the specified subregion of <code>str2></code>; false
  513.   *  otherwise.
  514.       */
  515.     static bool regionIMatches
  516.     (
  517.         const   XMLCh* const    str1
  518. , const int offset1
  519.         , const XMLCh* const    str2
  520. , const int offset2
  521. , const unsigned int charCount
  522.     );
  523.     //@}
  524.     /** @name String copy functions */
  525.     //@{
  526.     /** Copies <code>src</code>, including the terminating null character, to the
  527.       * location specified by <code>target</code>.
  528.       *
  529.       * No overflow checking is performed when strings are copied or appended.
  530.       * The behavior of strcpy is undefined if the source and destination strings
  531.       * overlap.
  532.       *
  533.       * @param target Destination string
  534.       * @param src Null-terminated source string
  535.       */
  536.     static void copyString
  537.     (
  538.                 char* const     target
  539.         , const char* const     src
  540.     );
  541.     /** Copies <code>src</code>, including the terminating null character, to
  542.       *   the location specified by <code>target</code>.
  543.       *
  544.       * No overflow checking is performed when strings are copied or appended.
  545.       * The behavior of <code>copyString</code> is undefined if the source and
  546.       * destination strings overlap.
  547.       *
  548.       * @param target Destination string
  549.       * @param src Null-terminated source string
  550.       */
  551.     static void copyString
  552.     (
  553.                 XMLCh* const    target
  554.         , const XMLCh* const    src
  555.     );
  556.     /** Copies <code>src</code>, upto a fixed number of characters, to the
  557.       * location specified by <code>target</code>.
  558.       *
  559.       * No overflow checking is performed when strings are copied or appended.
  560.       * The behavior of <code>copyNString</code> is undefined if the source and
  561.       * destination strings overlap.
  562.       *
  563.       * @param target Destination string. The size of the buffer should
  564.       *        atleast be 'maxChars + 1'.
  565.       * @param src Null-terminated source string
  566.       * @param maxChars The maximum number of characters to copy
  567.       */
  568.     static bool copyNString
  569.     (
  570.                 XMLCh* const    target
  571.         , const XMLCh* const    src
  572.         , const unsigned int    maxChars
  573.     );
  574.     //@}
  575.     /** @name Hash functions */
  576.     //@{
  577.     /** Hashes a string given a modulus
  578.       *
  579.       * @param toHash The string to hash
  580.       * @param hashModulus The divisor to be used for hashing
  581.       * @return Returns the hash value
  582.       */
  583.     static unsigned int hash
  584.     (
  585.         const   char* const     toHash
  586.         , const unsigned int    hashModulus
  587.     );
  588.     /** Hashes a string given a modulus
  589.       *
  590.       * @param toHash The string to hash
  591.       * @param hashModulus The divisor to be used for hashing
  592.       * @return Returns the hash value
  593.       */
  594.     static unsigned int hash
  595.     (
  596.         const   XMLCh* const    toHash
  597.         , const unsigned int    hashModulus
  598.     );
  599.     /** Hashes a string given a modulus taking a maximum number of characters
  600.       * as the limit
  601.       *
  602.       * @param toHash The string to hash
  603.       * @param numChars The maximum number of characters to consider for hashing
  604.       * @param hashModulus The divisor to be used for hashing
  605.       *
  606.       * @return Returns the hash value
  607.       */
  608.     static unsigned int hashN
  609.     (
  610.         const   XMLCh* const    toHash
  611.         , const unsigned int    numChars
  612.         , const unsigned int    hashModulus
  613.     );
  614.     //@}
  615.     /** @name Search functions */
  616.     //@{
  617.     /**
  618.       * Provides the index of the first occurance of a character within a string
  619.       *
  620.       * @param toSearch The string to search
  621.       * @param ch The character to search within the string
  622.       * @return If found, returns the index of the character within the string,
  623.       * else returns -1.
  624.       */
  625.     static int indexOf(const char* const toSearch, const char ch);
  626.     /**
  627.       * Provides the index of the first occurance of a character within a string
  628.       *
  629.       * @param toSearch The string to search
  630.       * @param ch The character to search within the string
  631.       * @return If found, returns the index of the character within the string,
  632.       * else returns -1.
  633.       */
  634.     static int indexOf(const XMLCh* const toSearch, const XMLCh ch);
  635.     /**
  636.       * Provides the index of the first occurance of a character within a string
  637.       * starting from a given index
  638.       *
  639.       * @param toSearch The string to search
  640.       * @param chToFind The character to search within the string
  641.       * @param fromIndex The index to start earch from
  642.       * @return If found, returns the index of the character within the string,
  643.       * else returns -1.
  644.       */
  645.     static int indexOf
  646.     (
  647.         const   char* const     toSearch
  648.         , const char            chToFind
  649.         , const unsigned int    fromIndex
  650.     );
  651.     /**
  652.       * Provides the index of the first occurance of a character within a string
  653.       * starting from a given index
  654.       *
  655.       * @param toSearch The string to search
  656.       * @param chToFind The character to search within the string
  657.       * @param fromIndex The index to start search from
  658.       * @return If found, returns the index of the character within the string,
  659.       * else returns -1.
  660.       */
  661.     static int indexOf
  662.     (
  663.         const   XMLCh* const    toSearch
  664.         , const XMLCh           chToFind
  665.         , const unsigned int    fromIndex
  666.     );
  667.     /**
  668.       * Provides the index of the last occurance of a character within a string
  669.       *
  670.       * @param toSearch The string to search
  671.       * @param ch The character to search within the string
  672.       * @return If found, returns the index of the character within the string,
  673.       * else returns -1.
  674.       */
  675.     static int lastIndexOf(const char* const toSearch, const char ch);
  676.     /**
  677.       * Provides the index of the last occurance of a character within a string
  678.       *
  679.       * @param toSearch The string to search
  680.       * @param ch The character to search within the string
  681.       * @return If found, returns the index of the character within the string,
  682.       * else returns -1.
  683.       */
  684.     static int lastIndexOf(const XMLCh* const toSearch, const XMLCh ch);
  685.     /**
  686.       * Provides the index of the last occurance of a character within a string
  687.       * starting backward from a given index
  688.       *
  689.       * @param toSearch The string to search
  690.       * @param chToFind The character to search within the string
  691.       * @param fromIndex The index to start backward search from
  692.       * @return If found, returns the index of the character within the string,
  693.       * else returns -1.
  694.       */
  695.     static int lastIndexOf
  696.     (
  697.         const   char* const     toSearch
  698.         , const char            chToFind
  699.         , const unsigned int    fromIndex
  700.     );
  701.     /**
  702.       * Provides the index of the last occurance of a character within a string
  703.       * starting backward from a given index
  704.       *
  705.       * @param toSearch The string to search
  706.       * @param ch       The character to search within the string
  707.       * @param fromIndex The index to start backward search from
  708.       * @return If found, returns the index of the character within the string,
  709.       * else returns -1.
  710.       */
  711.     static int lastIndexOf
  712.     (
  713.         const   XMLCh* const    toSearch
  714.         , const XMLCh           ch
  715.         , const unsigned int    fromIndex
  716.     );
  717.     //@}
  718.     /** @name Fixed size string movement */
  719.     //@{
  720.     /** Moves X number of chars
  721.       * @param targetStr The string to copy the chars to
  722.       * @param srcStr The string to copy the chars from
  723.       * @param count The number of chars to move
  724.       */
  725.     static void moveChars
  726.     (
  727.                 XMLCh* const    targetStr
  728.         , const XMLCh* const    srcStr
  729.         , const unsigned int    count
  730.     );
  731.     //@}
  732.     /** @name Substring function */
  733.     //@{
  734.     /** Create a substring of a givend string. The substring begins at the
  735.       * specified beginIndex and extends to the character at index
  736.       * endIndex - 1.
  737.       * @param targetStr The string to copy the chars to
  738.       * @param srcStr The string to copy the chars from
  739.       * @param startIndex beginning index, inclusive.
  740.       * @param endIndex the ending index, exclusive.
  741.       */
  742.     static void subString
  743.     (
  744.                 char* const    targetStr
  745.         , const char* const    srcStr
  746.         , const int            startIndex
  747.         , const int            endIndex
  748.     );
  749.     /** Create a substring of a givend string. The substring begins at the
  750.       * specified beginIndex and extends to the character at index
  751.       * endIndex - 1.
  752.       * @param targetStr The string to copy the chars to
  753.       * @param srcStr The string to copy the chars from
  754.       * @param startIndex beginning index, inclusive.
  755.       * @param endIndex the ending index, exclusive.
  756.       */
  757.     static void subString
  758.     (
  759.                 XMLCh* const    targetStr
  760.         , const XMLCh* const    srcStr
  761.         , const int             startIndex
  762.         , const int             endIndex
  763.     );
  764.     //@}
  765.     /** @name Replication function */
  766.     //@{
  767.     /** Replicates a string
  768.       * NOTE: The returned buffer is dynamically allocated and is the
  769.       * responsibility of the caller to delete it when not longer needed.
  770.       * You can call XMLString::release to release this returned buffer.
  771.       *
  772.       * @param toRep The string to replicate
  773.       * @return Returns a pointer to the replicated string
  774.       * @see   XMLString::release(char**)
  775.       */
  776.     static char* replicate(const char* const toRep);
  777.     static char* replicate(const char* const toRep,
  778.                            MemoryManager* const manager);
  779.     /** Replicates a string
  780.       * NOTE: The returned buffer is dynamically allocated and is the
  781.       * responsibility of the caller to delete it when not longer needed.
  782.       * You can call XMLString::release to release this returned buffer.
  783.       * @param toRep The string to replicate
  784.       * @return Returns a pointer to the replicated string
  785.       * @see   XMLString::release(XMLCh**)
  786.       */
  787.     static XMLCh* replicate(const XMLCh* const toRep);
  788.     static XMLCh* replicate(const XMLCh* const toRep,
  789.                             MemoryManager* const manager);
  790.     //@}
  791.     /** @name String query function */
  792.     //@{
  793.     /** Tells if the sub-string appears within a string at the beginning
  794.       * @param toTest The string to test
  795.       * @param prefix The sub-string that needs to be checked
  796.       * @return Returns true if the sub-string was found at the beginning of
  797.       * <code>toTest</code>, else false
  798.       */
  799.     static bool startsWith
  800.     (
  801.         const   char* const     toTest
  802.         , const char* const     prefix
  803.     );
  804.     /** Tells if the sub-string appears within a string at the beginning
  805.       * @param toTest The string to test
  806.       * @param prefix The sub-string that needs to be checked
  807.       * @return Returns true if the sub-string was found at the beginning of
  808.       * <code>toTest</code>, else false
  809.       */
  810.     static bool startsWith
  811.     (
  812.         const   XMLCh* const    toTest
  813.         , const XMLCh* const    prefix
  814.     );
  815.     /** Tells if the sub-string appears within a string at the beginning
  816.       * without regard to case
  817.       *
  818.       * @param toTest The string to test
  819.       * @param prefix The sub-string that needs to be checked
  820.       * @return Returns true if the sub-string was found at the beginning of
  821.       * <code>toTest</code>, else false
  822.       */
  823.     static bool startsWithI
  824.     (
  825.         const   char* const     toTest
  826.         , const char* const     prefix
  827.     );
  828.     /** Tells if the sub-string appears within a string at the beginning
  829.       * without regard to case
  830.       *
  831.       * @param toTest The string to test
  832.       * @param prefix The sub-string that needs to be checked
  833.       *
  834.       * @return Returns true if the sub-string was found at the beginning
  835.       * of <code>toTest</code>, else false
  836.       */
  837.     static bool startsWithI
  838.     (
  839.         const   XMLCh* const    toTest
  840.         , const XMLCh* const    prefix
  841.     );
  842.     /** Tells if the sub-string appears within a string at the end.
  843.       * @param toTest The string to test
  844.       * @param suffix The sub-string that needs to be checked
  845.       * @return Returns true if the sub-string was found at the end of
  846.       * <code>toTest</code>, else false
  847.       */
  848.     static bool endsWith
  849.     (
  850.         const   XMLCh* const    toTest
  851.         , const XMLCh* const    suffix
  852.     );
  853.     /** Tells if a string has any occurance of another string within itself
  854.       * @param toSearch The string to be searched
  855.       * @param searchList The sub-string to be searched within the string
  856.       * @return Returns the pointer to the location where the sub-string was
  857.       * found, else returns 0
  858.       */
  859.     static const XMLCh* findAny
  860.     (
  861.         const   XMLCh* const    toSearch
  862.         , const XMLCh* const    searchList
  863.     );
  864.     /** Tells if a string has any occurance of another string within itself
  865.       * @param toSearch The string to be searched
  866.       * @param searchList The sub-string to be searched within the string
  867.       * @return Returns the pointer to the location where the sub-string was
  868.       * found, else returns 0
  869.       */
  870.     static XMLCh* findAny
  871.     (
  872.                 XMLCh* const    toSearch
  873.         , const XMLCh* const    searchList
  874.     );
  875.     /** Tells if a string has pattern within itself
  876.       * @param toSearch The string to be searched
  877.       * @param pattern The pattern to be searched within the string
  878.       * @return Returns index to the location where the pattern was
  879.       * found, else returns -1
  880.       */
  881.     static int patternMatch
  882.     (
  883.           const XMLCh* const    toSearch
  884.         , const XMLCh* const    pattern
  885.     );
  886.     /** Get the length of the string
  887.       * @param src The string whose length is to be determined
  888.       * @return Returns the length of the string
  889.       */
  890.     static unsigned int stringLen(const char* const src);
  891.     /** Get the length of the string
  892.       * @param src The string whose length is to be determined
  893.       * @return Returns the length of the string
  894.       */
  895.     static unsigned int stringLen(const XMLCh* const src);
  896.     /**
  897.       * Deprecated: please use XMLChar1_0::isValidNCName
  898.       *
  899.       * Checks whether an name is a valid NCName according to XML 1.0
  900.       * @param name The string to check its NCName validity
  901.       * @return Returns true if name is NCName valid, otherwise false
  902.       */
  903.     static bool isValidNCName(const XMLCh* const name);
  904.     /**
  905.       * Deprecated: please use XMLChar1_0::isValidName
  906.       *
  907.       * Checks whether an name is a valid Name according to XML 1.0
  908.       * @param name The string to check its Name validity
  909.       * @return Returns true if name is Name valid, otherwise false
  910.       */
  911.     static bool isValidName(const XMLCh* const name);
  912.     /**
  913.       * Checks whether an name is a valid EncName.
  914.       * @param name The string to check its EncName validity
  915.       * @return Returns true if name is EncName valid, otherwise false
  916.       */
  917.     static bool isValidEncName(const XMLCh* const name);
  918.     /**
  919.       * Deprecated: please use XMLChar1_0::isValidQName
  920.       *
  921.       * Checks whether an name is a valid QName according to XML 1.0
  922.       * @param name The string to check its QName validity
  923.       * @return Returns true if name is QName valid, otherwise false
  924.       */
  925.     static bool isValidQName(const XMLCh* const name);
  926.     /**
  927.       * Checks whether a character is within [a-zA-Z].
  928.       * @param theChar the character to check
  929.       * @return Returns true if within the range, otherwise false
  930.       */
  931.     static bool isAlpha(XMLCh const theChar);
  932.     /**
  933.       * Checks whether a character is within [0-9].
  934.       * @param theChar the character to check
  935.       * @return Returns true if within the range, otherwise false
  936.       */
  937.     static bool isDigit(XMLCh const theChar);
  938.     /**
  939.       * Checks whether a character is within [0-9a-zA-Z].
  940.       * @param theChar the character to check
  941.       * @return Returns true if within the range, otherwise false
  942.       */
  943.     static bool isAlphaNum(XMLCh const theChar);
  944.     /**
  945.       * Checks whether a character is within [0-9a-fA-F].
  946.       * @param theChar the character to check
  947.       * @return Returns true if within the range, otherwise false
  948.       */
  949.     static bool isHex(XMLCh const theChar);
  950.     /**
  951.       * Deprecated: please use XMLChar1_0::isAllWhiteSpace
  952.       *
  953.       * Checks whether aa string contains only whitespace according to XML 1.0
  954.       * @param toCheck the string to check
  955.       * @return Returns true if it is, otherwise false
  956.       */
  957.     static bool isAllWhiteSpace(const XMLCh* const toCheck);
  958.     /** Find is the string appears in the enum list
  959.       * @param toFind the string to be found
  960.       * @param enumList the list
  961.       * return true if found
  962.       */
  963.     static bool isInList(const XMLCh* const toFind, const XMLCh* const enumList);
  964.     //@}
  965.     /** @name Conversion functions */
  966.     //@{
  967.     /** Converts binary data to a text string based a given radix
  968.       *
  969.       * @param toFormat The beginning of the input string to convert
  970.       * @param toFill The buffer that will hold the output on return. The
  971.       *        size of this buffer should at least be 'maxChars + 1'.
  972.       * @param maxChars The maximum number of output characters that can be
  973.       *         accepted. If the result will not fit, it is an error.
  974.       * @param radix The radix of the input data, based on which the conversion
  975.       * will be done
  976.       */
  977.     static void binToText
  978.     (
  979.         const   unsigned int    toFormat
  980.         ,       char* const     toFill
  981.         , const unsigned int    maxChars
  982.         , const unsigned int    radix
  983.     );
  984.     /** Converts binary data to a text string based a given radix
  985.       *
  986.       * @param toFormat The beginning of the input string to convert
  987.       * @param toFill The buffer that will hold the output on return. The
  988.       *        size of this buffer should at least be 'maxChars + 1'.
  989.       * @param maxChars The maximum number of output characters that can be
  990.       *         accepted. If the result will not fit, it is an error.
  991.       * @param radix The radix of the input data, based on which the conversion
  992.       * will be done
  993.       */
  994.     static void binToText
  995.     (
  996.         const   unsigned int    toFormat
  997.         ,       XMLCh* const    toFill
  998.         , const unsigned int    maxChars
  999.         , const unsigned int    radix
  1000.     );
  1001.     /** Converts binary data to a text string based a given radix
  1002.       *
  1003.       * @param toFormat The beginning of the input string to convert
  1004.       * @param toFill The buffer that will hold the output on return. The
  1005.       *        size of this buffer should at least be 'maxChars + 1'.
  1006.       * @param maxChars The maximum number of output characters that can be
  1007.       *         accepted. If the result will not fit, it is an error.
  1008.       * @param radix The radix of the input data, based on which the conversion
  1009.       * will be done
  1010.       */
  1011.     static void binToText
  1012.     (
  1013.         const   unsigned long   toFormat
  1014.         ,       char* const     toFill
  1015.         , const unsigned int    maxChars
  1016.         , const unsigned int    radix
  1017.     );
  1018.     /** Converts binary data to a text string based a given radix
  1019.       *
  1020.       * @param toFormat The beginning of the input string to convert
  1021.       * @param toFill The buffer that will hold the output on return. The
  1022.       *        size of this buffer should at least be 'maxChars + 1'.
  1023.       * @param maxChars The maximum number of output characters that can be
  1024.       *         accepted. If the result will not fit, it is an error.
  1025.       * @param radix The radix of the input data, based on which the conversion
  1026.       * will be done
  1027.       */
  1028.     static void binToText
  1029.     (
  1030.         const   unsigned long   toFormat
  1031.         ,       XMLCh* const    toFill
  1032.         , const unsigned int    maxChars
  1033.         , const unsigned int    radix
  1034.     );
  1035.     /** Converts binary data to a text string based a given radix
  1036.       *
  1037.       * @param toFormat The beginning of the input string to convert
  1038.       * @param toFill The buffer that will hold the output on return. The
  1039.       *        size of this buffer should at least be 'maxChars + 1'.
  1040.       * @param maxChars The maximum number of output characters that can be
  1041.       *         accepted. If the result will not fit, it is an error.
  1042.       * @param radix The radix of the input data, based on which the conversion
  1043.       * will be done
  1044.       */
  1045.     static void binToText
  1046.     (
  1047.         const   long            toFormat
  1048.         ,       char* const     toFill
  1049.         , const unsigned int    maxChars
  1050.         , const unsigned int    radix
  1051.     );
  1052.     /** Converts binary data to a text string based a given radix
  1053.       *
  1054.       * @param toFormat The beginning of the input string to convert
  1055.       * @param toFill The buffer that will hold the output on return. The
  1056.       *        size of this buffer should at least be 'maxChars + 1'.
  1057.       * @param maxChars The maximum number of output characters that can be
  1058.       *         accepted. If the result will not fit, it is an error.
  1059.       * @param radix The radix of the input data, based on which the conversion
  1060.       * will be done
  1061.       */
  1062.     static void binToText
  1063.     (
  1064.         const   long            toFormat
  1065.         ,       XMLCh* const    toFill
  1066.         , const unsigned int    maxChars
  1067.         , const unsigned int    radix
  1068.     );
  1069.     /** Converts binary data to a text string based a given radix
  1070.       *
  1071.       * @param toFormat The beginning of the input string to convert
  1072.       * @param toFill The buffer that will hold the output on return. The
  1073.       *        size of this buffer should at least be 'maxChars + 1'.
  1074.       * @param maxChars The maximum number of output characters that can be
  1075.       *         accepted. If the result will not fit, it is an error.
  1076.       * @param radix The radix of the input data, based on which the conversion
  1077.       * will be done
  1078.       */
  1079.     static void binToText
  1080.     (
  1081.         const   int             toFormat
  1082.         ,       char* const     toFill
  1083.         , const unsigned int    maxChars
  1084.         , const unsigned int    radix
  1085.     );
  1086.     /** Converts binary data to a text string based a given radix
  1087.       *
  1088.       * @param toFormat The beginning of the input string to convert
  1089.       * @param toFill The buffer that will hold the output on return. The
  1090.       *        size of this buffer should at least be 'maxChars + 1'.
  1091.       * @param maxChars The maximum number of output characters that can be
  1092.       *         accepted. If the result will not fit, it is an error.
  1093.       * @param radix The radix of the input data, based on which the conversion
  1094.       * will be done
  1095.       */
  1096.     static void binToText
  1097.     (
  1098.         const   int             toFormat
  1099.         ,       XMLCh* const    toFill
  1100.         , const unsigned int    maxChars
  1101.         , const unsigned int    radix
  1102.     );
  1103.     /**
  1104.       * Converts a string of decimal chars to a binary value
  1105.       *
  1106.       * Note that leading and trailng whitespace is legal and will be ignored
  1107.       * but the remainder must be all decimal digits.
  1108.       *
  1109.       * @param toConvert The string of digits to convert
  1110.       * @param toFill    The unsigned int value to fill with the converted
  1111.       *                  value.
  1112.       */
  1113.     static bool textToBin
  1114.     (
  1115.         const   XMLCh* const    toConvert
  1116.         ,       unsigned int&   toFill
  1117.     );
  1118.     /**
  1119.       * Converts a string of decimal chars to a binary value
  1120.       *
  1121.       * Note that leading and trailng whitespace is legal and will be ignored,
  1122.       *
  1123.       * Only one and either of (+,-) after the leading whitespace, before
  1124.       * any other characters are allowed.
  1125.       *
  1126.       * but the remainder must be all decimal digits.
  1127.       *
  1128.       * @param toConvert The string of digits to convert
  1129.       */
  1130.     static int parseInt
  1131.     (
  1132.         const   XMLCh* const    toConvert
  1133.     );
  1134.     /** Cut leading chars from a string
  1135.       *
  1136.       * @param toCutFrom The string to cut chars from
  1137.       * @param count     The count of leading chars to cut
  1138.       */
  1139.     static void cut
  1140.     (
  1141.                 XMLCh* const    toCutFrom
  1142.         , const unsigned int    count
  1143.     );
  1144.     /** Transcodes a string to native code-page
  1145.       *
  1146.       * NOTE: The returned buffer is dynamically allocated and is the
  1147.       * responsibility of the caller to delete it when not longer needed.
  1148.       * You can call XMLString::release to release this returned buffer.
  1149.       *
  1150.       * @param toTranscode The string to be transcoded
  1151.       * @return Returns the transcoded string
  1152.       * @see   XMLString::release(XMLCh**)
  1153.       */
  1154.     static char* transcode
  1155.     (
  1156.         const   XMLCh* const    toTranscode
  1157.     );
  1158.     static char* transcode
  1159.     (
  1160.         const   XMLCh* const         toTranscode
  1161.         ,       MemoryManager* const manager
  1162.     );
  1163.     /** Transcodes a string to native code-page
  1164.       *
  1165.       * Be aware that when transcoding to an external encoding, that each
  1166.       * Unicode char can create multiple output bytes. So you cannot assume
  1167.       * a one to one correspondence of input chars to output bytes.
  1168.       *
  1169.       * @param toTranscode The string tobe transcoded
  1170.       * @param toFill The buffer that is filled with the transcoded value.
  1171.       *        The size of this buffer should atleast be 'maxChars + 1'.
  1172.       * @param maxChars The maximum number of bytes that the output
  1173.       *         buffer can hold (not including the null, which is why
  1174.       *         toFill should be at least maxChars+1.).
  1175.       * @return Returns true if successful, false if there was an error
  1176.       */
  1177.     static bool transcode
  1178.     (
  1179.         const   XMLCh* const    toTranscode
  1180.         ,       char* const     toFill
  1181.         , const unsigned int    maxChars
  1182.     );
  1183.     /** Transcodes a string to native code-page
  1184.       *
  1185.       * NOTE: The returned buffer is dynamically allocated and is the
  1186.       * responsibility of the caller to delete it when not longer needed.
  1187.       * You can call XMLString::release to release this returned buffer.
  1188.       *
  1189.       * @param toTranscode The string to be transcoded
  1190.       * @return Returns the transcoded string
  1191.       * @see   XMLString::release(char**)
  1192.       */
  1193.     static XMLCh* transcode
  1194.     (
  1195.         const   char* const     toTranscode
  1196.     );
  1197.     static XMLCh* transcode
  1198.     (
  1199.         const   char* const          toTranscode
  1200.         ,       MemoryManager* const manager
  1201.     );
  1202.     /** Transcodes a string to native code-page
  1203.       * @param toTranscode The string tobe transcoded
  1204.       * @param toFill The buffer that is filled with the transcoded value.
  1205.       *        The size of this buffer should atleast be 'maxChars + 1'.
  1206.       * @param maxChars The maximum number of characters that the output
  1207.       *         buffer can hold (not including the null, which is why
  1208.       *         toFill should be at least maxChars+1.).
  1209.       * @return Returns true if successful, false if there was an error
  1210.       */
  1211.     static bool transcode
  1212.     (
  1213.         const   char* const     toTranscode
  1214.         ,       XMLCh* const    toFill
  1215.         , const unsigned int    maxChars
  1216.     );
  1217.     /** Trims off extra space characters from the start and end of the string,
  1218.       * moving the non-space string content back to the start.
  1219.       * @param toTrim The string to be trimmed. On return this contains the
  1220.       * trimmed string
  1221.       */
  1222.     static void trim(char* const toTrim);
  1223.     /** Trims off extra space characters from the start and end of the string,
  1224.       * moving the non-space string content back to the start.
  1225.       * @param toTrim The string to be trimmed. On return this contains
  1226.       * the trimmed string
  1227.       */
  1228.     static void trim(XMLCh* const toTrim);
  1229.     /** Break a string into tokens with space as delimiter, and
  1230.       * stored in a string vector.  The caller owns the string vector
  1231.       * that is returned, and is responsible for deleting it.
  1232.       * @param tokenizeSrc String to be tokenized
  1233.       * @return a vector of all the tokenized string
  1234.       */
  1235.     static BaseRefVectorOf<XMLCh>* tokenizeString(const XMLCh* const tokenizeSrc);
  1236.     //@}
  1237.     /** @name Formatting functions */
  1238.     //@{
  1239.     /** Creates a UName from a URI and base name. It is in the form
  1240.       * {url}name, and is commonly used internally to represent fully
  1241.       * qualified names when namespaces are enabled.
  1242.       *
  1243.       * @param pszURI The URI part of the name
  1244.       * @param pszName The base part of the name
  1245.       * @return Returns the complete formatted UName
  1246.       */
  1247.     static XMLCh* makeUName
  1248.     (
  1249.         const   XMLCh* const    pszURI
  1250.         , const XMLCh* const    pszName
  1251.     );
  1252.     /**
  1253.       * Internal function to perform token replacement for strings.
  1254.       *
  1255.       * @param errText The text (NULL terminated) where the replacement
  1256.       *        is to be done. The size of this buffer should be
  1257.       *        'maxChars + 1' to account for the final NULL.
  1258.       * @param maxChars The size of the output buffer, i.e. the maximum
  1259.       *         number of characters that it will hold. If the result is
  1260.       *         larger, it will be truncated.
  1261.       * @param text1 Replacement text-one
  1262.       * @param text2 Replacement text-two
  1263.       * @param text3 Replacement text-three
  1264.       * @param text4 Replacement text-four
  1265.       * @return Returns the count of characters that are outputted
  1266.       */
  1267.     static unsigned int replaceTokens
  1268.     (
  1269.                 XMLCh* const    errText
  1270.         , const unsigned int    maxChars
  1271.         , const XMLCh* const    text1
  1272.         , const XMLCh* const    text2
  1273.         , const XMLCh* const    text3
  1274.         , const XMLCh* const    text4
  1275.     );
  1276.     /** Converts a string to uppercase
  1277.       * @param toUpperCase The string which needs to be converted to uppercase.
  1278.       *        On return, this buffer also holds the converted uppercase string
  1279.       */
  1280.     static void upperCase(XMLCh* const toUpperCase);
  1281. /** Converts a string to lowercase
  1282.       * @param toLowerCase The string which needs to be converted to lowercase.
  1283.       *        On return, this buffer also holds the converted lowercase string
  1284.       */
  1285.     static void lowerCase(XMLCh* const toLowerCase);
  1286. /** Check if string is WhiteSpace:replace
  1287.       * @param toCheck The string which needs to be checked.
  1288.       */
  1289.     static bool isWSReplaced(const XMLCh* const toCheck);
  1290. /** Check if string is WhiteSpace:collapse
  1291.       * @param toCheck The string which needs to be checked.
  1292.       */
  1293.     static bool isWSCollapsed(const XMLCh* const toCheck);
  1294. /** Replace whitespace
  1295.       * @param toConvert The string which needs to be whitespace replaced.
  1296.       *        On return , this buffer also holds the converted string
  1297.       */
  1298.     static void replaceWS(XMLCh* const toConvert);
  1299. /** Collapse whitespace
  1300.       * @param toConvert The string which needs to be whitespace collapsed.
  1301.       *        On return , this buffer also holds the converted string
  1302.       */
  1303.     static void collapseWS(XMLCh* const toConvert);
  1304.     /** Remove whitespace
  1305.       * @param toConvert The string which needs to be whitespace removed.
  1306.       *        On return , this buffer also holds the converted string
  1307.       */
  1308.     static void removeWS(XMLCh* const toConvert);
  1309.     /**
  1310.      * Fixes a platform dependent absolute path filename to standard URI form.
  1311.      * 1. Windows: fix 'x:' to 'file:///x:' and convert any backslash to forward slash
  1312.      * 2. UNIX: fix '/blah/blahblah' to 'file:///blah/blahblah'
  1313.      * @param str    The string that has the absolute path filename
  1314.      * @param target The target string pre-allocated to store the fixed uri
  1315.      */
  1316.     static void fixURI(const XMLCh* const str, XMLCh* const target);
  1317.     //@}
  1318.     /** @name String Memory Management functions */
  1319.     //@{
  1320.     /**
  1321.      * Release the parameter char string that was allocated by the implementation (i.e.the parser).
  1322.      *   The implementation will call operator delete[] and then turn the string to a null pointer.
  1323.      *
  1324.      * @param buf  The string to be deleted and become a null pointer.
  1325.      */
  1326.     static void release(char** buf);
  1327.     /**
  1328.      * Release the parameter XMLCh string that was allocated by the implementation (i.e.the parser).
  1329.      *   The implementation will call operator delete[] and then turn the string to a null pointer.
  1330.      *
  1331.      * @param buf  The string to be deleted and become a null pointer.
  1332.      */
  1333.     static void release(XMLCh** buf);
  1334.     /**
  1335.      * Release the parameter XMLByte string that was allocated by the implementation (i.e.the parser).
  1336.      *   The implementation will call operator delete[] and then turn the string to a null pointer.
  1337.      *
  1338.      * @param buf  The string to be deleted and become a null pointer.
  1339.      */
  1340.     static void release(XMLByte** buf);
  1341.     //@}
  1342. private :
  1343.     /** @name Constructors and Destructor */
  1344.     //@{
  1345.     /** Unimplemented default constructor */
  1346.     XMLString();
  1347.     /** Unimplemented destructor */
  1348.     ~XMLString();
  1349.     //@}
  1350.     /** @name Initialization */
  1351.     //@{
  1352.     /** Init/Term methods called from XMLPlatformUtils class */
  1353.     static void initString(XMLLCPTranscoder* const defToUse,
  1354.                            MemoryManager* const manager);
  1355.     static void termString();
  1356.     //@}
  1357. /**
  1358.   * Called by regionMatches/regionIMatches to validate that we
  1359.   * have a valid input
  1360.   */
  1361. static bool validateRegion(const XMLCh* const str1, const int offset1,
  1362. const XMLCh* const str2, const int offset2,
  1363. const unsigned int charCount);
  1364.     static MemoryManager* fgMemoryManager;
  1365.     friend class XMLPlatformUtils;
  1366. };
  1367. // ---------------------------------------------------------------------------
  1368. //  Inline some methods that are either just passthroughs to other string
  1369. //  methods, or which are key for performance.
  1370. // ---------------------------------------------------------------------------
  1371. inline void XMLString::moveChars(       XMLCh* const targetStr
  1372.                                 , const XMLCh* const srcStr
  1373.                                 , const unsigned int count)
  1374. {
  1375.     memcpy(targetStr, srcStr, count * sizeof(XMLCh));
  1376. }
  1377. inline unsigned int XMLString::stringLen(const XMLCh* const src)
  1378. {
  1379.     if (src == 0 || *src == 0)
  1380.     {
  1381.         return 0;
  1382.    }
  1383.     else
  1384.    {
  1385.         const XMLCh* pszTmp = src + 1;
  1386.         while (*pszTmp)
  1387.             ++pszTmp;
  1388.         return (unsigned int)(pszTmp - src);
  1389.     }
  1390. }
  1391. inline bool XMLString::startsWith(  const   XMLCh* const    toTest
  1392.                                     , const XMLCh* const    prefix)
  1393. {
  1394.     return (compareNString(toTest, prefix, stringLen(prefix)) == 0);
  1395. }
  1396. inline bool XMLString::startsWithI( const   XMLCh* const    toTest
  1397.                                     , const XMLCh* const    prefix)
  1398. {
  1399.     return (compareNIString(toTest, prefix, stringLen(prefix)) == 0);
  1400. }
  1401. inline bool XMLString::endsWith(const XMLCh* const toTest,
  1402.                                 const XMLCh* const suffix)
  1403. {
  1404.     unsigned int suffixLen = XMLString::stringLen(suffix);
  1405.     return regionMatches(toTest, XMLString::stringLen(toTest) - suffixLen,
  1406.                          suffix, 0, suffixLen);
  1407. }
  1408. inline XMLCh* XMLString::replicate(const XMLCh* const toRep)
  1409. {
  1410.     // If a null string, return a null string!
  1411.     XMLCh* ret = 0;
  1412.     if (toRep)
  1413.     {
  1414.         const unsigned int len = stringLen(toRep);
  1415.         ret = new XMLCh[len + 1];
  1416.         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
  1417.     }
  1418.     return ret;
  1419. }
  1420. inline XMLCh* XMLString::replicate(const XMLCh* const toRep,
  1421.                                    MemoryManager* const manager)
  1422. {
  1423.     // If a null string, return a null string!
  1424.     XMLCh* ret = 0;
  1425.     if (toRep)
  1426.     {
  1427.         const unsigned int len = stringLen(toRep);
  1428.         ret = (XMLCh*) manager->allocate((len+1) * sizeof(XMLCh)); //new XMLCh[len + 1];
  1429.         memcpy(ret, toRep, (len + 1) * sizeof(XMLCh));
  1430.     }
  1431.     return ret;
  1432. }
  1433. inline bool XMLString::validateRegion(const XMLCh* const str1,
  1434.   const int offset1,
  1435.   const XMLCh* const str2,
  1436.   const int offset2,
  1437.   const unsigned int charCount)
  1438. {
  1439. if (offset1 < 0 || offset2 < 0 ||
  1440. (offset1 + charCount) > XMLString::stringLen(str1) ||
  1441. (offset2 + charCount) > XMLString::stringLen(str2) )
  1442. return false;
  1443. return true;
  1444. }
  1445. inline bool XMLString::equals(   const XMLCh* const    str1
  1446.                                , const XMLCh* const    str2)
  1447. {
  1448.     const XMLCh* psz1 = str1;
  1449.     const XMLCh* psz2 = str2;
  1450.     if (psz1 == 0 || psz2 == 0) {
  1451.         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
  1452.             return false;
  1453.         else
  1454.             return true;
  1455.     }
  1456.     while (*psz1 == *psz2)
  1457.     {
  1458.         // If either has ended, then they both ended, so equal
  1459.         if (!*psz1)
  1460.             return true;
  1461.         // Move upwards for the next round
  1462.         psz1++;
  1463.         psz2++;
  1464.     }
  1465.     return false;
  1466. }
  1467. inline bool XMLString::equals(   const char* const    str1
  1468.                                , const char* const    str2)
  1469. {
  1470.     const char* psz1 = str1;
  1471.     const char* psz2 = str2;
  1472.     if (psz1 == 0 || psz2 == 0) {
  1473.         if ((psz1 != 0 && *psz1) || (psz2 != 0 && *psz2))
  1474.             return false;
  1475.         else
  1476.             return true;
  1477.     }
  1478.     while (*psz1 == *psz2)
  1479.     {
  1480.         // If either has ended, then they both ended, so equal
  1481.         if (!*psz1)
  1482.             return true;
  1483.         // Move upwards for the next round
  1484.         psz1++;
  1485.         psz2++;
  1486.     }
  1487.     return false;
  1488. }
  1489. XERCES_CPP_NAMESPACE_END
  1490. #endif