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