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