version 1.9, 2001/02/26 04:33:28
|
version 1.103.8.1, 2014/06/14 22:08:13
|
|
|
//BEGIN_LICENSE |
//%LICENSE//////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// Licensed to The Open Group (TOG) under one or more contributor license |
|
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
|
// this work for additional information regarding copyright ownership. |
|
// Each contributor licenses this file to you under the OpenPegasus Open |
|
// Source License; you may not use this file except in compliance with the |
|
// License. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a | // Permission is hereby granted, free of charge, to any person obtaining a |
// copy of this software and associated documentation files (the "Software"), | // copy of this software and associated documentation files (the "Software"), |
|
|
// and/or sell copies of the Software, and to permit persons to whom the | // and/or sell copies of the Software, and to permit persons to whom the |
// Software is furnished to do so, subject to the following conditions: | // Software is furnished to do so, subject to the following conditions: |
// | // |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// The above copyright notice and this permission notice shall be included |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// in all copies or substantial portions of the Software. |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
|
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
|
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
|
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
|
// DEALINGS IN THE SOFTWARE. |
|
// | // |
//END_LICENSE |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
//BEGIN_HISTORY |
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. |
|
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY |
|
// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, |
|
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE |
|
// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
// | // |
// Author: |
////////////////////////////////////////////////////////////////////////// |
// | // |
// $Log$ |
//%///////////////////////////////////////////////////////////////////////////// |
// Revision 1.9 2001/02/26 04:33:28 mike |
|
// Fixed many places where cim names were be compared with operator==(String,String). |
|
// Changed all of these to use CIMName::equal() |
|
// |
|
// Revision 1.8 2001/02/20 14:05:24 karl |
|
// Comments for Document |
|
// |
|
// Revision 1.7 2001/02/11 17:19:30 mike |
|
// added reverseFind() method |
|
// |
|
// Revision 1.6 2001/02/11 05:42:33 mike |
|
// new |
|
// |
|
// Revision 1.5 2001/01/30 08:00:43 karl |
|
// DOC++ Documentation update for header files |
|
// |
|
// Revision 1.4 2001/01/28 07:05:18 mike |
|
// added instance name/reference converters |
|
// |
|
// Revision 1.3 2001/01/28 04:11:03 mike |
|
// fixed qualifier resolution |
|
// |
|
// Revision 1.2 2001/01/24 16:16:38 karl |
|
// Incorporate Doc++ Comments as documentation into .h files |
|
// |
|
// Revision 1.1.1.1 2001/01/14 19:53:15 mike |
|
// Pegasus import |
|
// |
|
// |
|
//END_HISTORY |
|
| |
#ifndef Pegasus_String_h | #ifndef Pegasus_String_h |
#define Pegasus_String_h | #define Pegasus_String_h |
| |
|
#ifdef PEGASUS_OS_HPUX |
|
# ifdef HPUX_IA64_NATIVE_COMPILER |
|
# include <iostream> |
|
# else |
|
# include <iostream.h> |
|
# endif |
|
#else |
#include <iostream> | #include <iostream> |
#include <cstring> |
#endif |
#include <Pegasus/Common/Config.h> | #include <Pegasus/Common/Config.h> |
#include <Pegasus/Common/Char16.h> | #include <Pegasus/Common/Char16.h> |
#include <Pegasus/Common/Array.h> |
#include <Pegasus/Common/Linkage.h> |
|
#include <cstdarg> |
| |
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
|
class String; |
|
struct StringRep; |
|
|
/** | /** |
The Pegasus String C++ Class implements the CIM string type |
The CString class provides access to an 8-bit String representation. |
*/ | */ |
class PEGASUS_COMMON_LINKAGE String |
class PEGASUS_COMMON_LINKAGE CString |
{ | { |
public: | public: |
| |
/// Default constructor. |
/** |
String(); |
Constructs a CString object with a null string value. |
|
*/ |
|
CString(); |
| |
/// Copy constructor. |
/** |
String(const String& x); |
Constructs an independent copy of a CString object. |
|
@param cstr The CString instance to copy. |
|
*/ |
|
CString(const CString& cstr); |
| |
/// Initialize with first n characters from x. |
/** |
String(const String& x, Uint32 n); |
Destructs a CString object. |
|
*/ |
|
~CString(); |
| |
/// Initialize with x. |
/** |
String(const Char16* x); |
Copies the value of another CString object. |
|
@param cstr The CString object from which to copy the value. |
|
@return A reference to the target CString object with its newly |
|
assigned value. |
|
*/ |
|
CString& operator=(const CString& cstr); |
| |
/// Initialize with first n characters of x. |
/** |
String(const Char16* x, Uint32 n); |
Gets the CString's data as a C string pointer. IMPORTANT: The |
|
returned pointer refers to memory owned by the CString object. The |
|
caller must not free this memory. The returned pointer is valid only |
|
until the CString object is destructed or reassigned. Use of this |
|
operator on a temporary CString object may result in a memory error. |
|
For example, this usage is invalid: |
| |
/// Initialize from a plain old C-String: |
const char* cstr = String("Hello").getCString(); |
String(const char* x); |
printf(cstr); |
| |
/// Initialize from the first n characters of a plain old C-String: |
@return Returns a const char pointer to the CString's data. |
String(const char* x, Uint32 n); |
*/ |
|
operator const char*() const; |
|
|
|
private: |
| |
/// Release all resources. |
CString(char* cstr); |
~String() |
|
|
friend class String; |
|
|
|
char* _rep; |
|
}; |
|
|
|
/** |
|
This class implements the CIM string type. The intrinsic string format |
|
is UTF-16, which is a superset of the UCS-2 characters allowed in CIM |
|
strings. Facilities are provided for converting to and from UTF-8 |
|
character strings. |
|
|
|
Many of the method interfaces refer to a number of characters. In all |
|
cases, these characters are counted as 8- or 16-bit memory chunks rather |
|
than logical UTF-8 or UTF-16 character chains. |
|
*/ |
|
class PEGASUS_COMMON_LINKAGE String |
{ | { |
} |
public: |
| |
/// Assign this string with x. |
/** |
String& operator=(const String& x) { _rep = x._rep; return *this; } |
Represents an empty string. This value may be used as a convenience |
|
to avoid construction of an empty String object. |
|
*/ |
|
static const String EMPTY; |
| |
/// Assign this string with x. |
/** |
String& operator=(const Char16* x) { assign(x); return *this; } |
Constructs an empty String. |
|
*/ |
|
String(); |
| |
/// Assign this string with x. |
/** |
String& assign(const String& x) { _rep = x._rep; return *this; } |
Constructs a String with the value of another String. |
|
@param str The String from which to copy the value. |
|
*/ |
|
String(const String& str); |
| |
/// Assign this string with x. |
/** |
String& assign(const Char16* x); |
Constructs a String with a specified number of characters of the |
|
value of another String. |
|
@param str The String from which to copy the value. |
|
@param n A Uint32 specifying the number of characters to copy. |
|
@exception IndexOutOfBoundsException If the specified String does not |
|
contain the specified number of characters. |
|
@exception bad_alloc If the construction fails because of a memory |
|
allocation failure. |
|
*/ |
|
String(const String& str, Uint32 n); |
| |
/// Assign this string with first n characters of x. |
/** |
String& assign(const Char16* x, Uint32 n); |
Constructs a String with the value from a Char16 buffer. |
|
@param str The Char16 buffer from which to copy the value. |
|
@exception NullPointer If the buffer pointer is NULL. |
|
@exception bad_alloc If the construction fails because of a memory |
|
allocation failure. |
|
*/ |
|
String(const Char16* str); |
| |
/// Assign this string with the plain old C-String x. |
/** |
String& assign(const char* x); |
Constructs a String with a specified number of characters of the |
|
value from a Char16 buffer. |
|
@param str The Char16 buffer from which to copy the value. |
|
@param n A Uint32 specifying the number of characters to copy. |
|
@exception NullPointer If the buffer pointer is NULL. |
|
@exception bad_alloc If the construction fails because of a memory |
|
allocation failure. |
|
*/ |
|
String(const Char16* str, Uint32 n); |
| |
/// Assign this string with first n characters of the plain old C-String x. |
/** |
String& assign(const char* x, Uint32 n); |
Constructs a String with the value from a C string in UTF-8 format. |
|
@param str The C string from which to copy the value. |
|
@exception NullPointer If the C string pointer is NULL. |
|
@exception bad_alloc If the construction fails because of a memory |
|
allocation failure. |
|
@exception Exception If the C string contains invalid UTF-8. |
|
*/ |
|
String(const char* str); |
| |
/// Clear this string. After calling clear(), getLength() will return 0. |
/** |
void clear() { _rep.clear(); _rep.append('\0'); } |
Constructs a String with a specified number of characters of the |
|
value from a C string in UTF-8 format. |
|
@param str The C string from which to copy the value. |
|
@param n A Uint32 specifying the number of characters to copy. |
|
@exception NullPointer If the C string pointer is NULL. |
|
@exception bad_alloc If the construction fails because of a memory |
|
allocation failure. |
|
@exception Exception If the C string contains invalid UTF-8. |
|
*/ |
|
String(const char* str, Uint32 n); |
| |
/** Reserves memory for capacity characters. Notice that this does not |
/** |
change the size of the string (getSize() returns what it did before). |
Destructs a String object. |
If the capacity of the string is already greater or equal to the |
|
capacity argument, this method has no effect. After calling reserve(), |
|
getCapicty() returns a value which is greater or equal to the |
|
capacity argument. |
|
*/ | */ |
void reserve(Uint32 capacity) { _rep.reserve(capacity + 1); } |
~String(); |
| |
/// Returns the length of the string. |
/** |
Uint32 getLength() const { return _rep.getSize() - 1; } |
Assigns the value of a String to the value of another String. |
|
@param str The String from which to copy the value. |
|
@return A reference to the target String object with its newly |
|
assigned value. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
|
*/ |
|
String& operator=(const String& str); |
| |
/// Returns a pointer to the first character in the string string. |
/** |
const Char16* getData() const { return _rep.getData(); } |
Assigns the value of a String to the value of another String. |
|
@param str The String from which to copy the value. |
|
@return A reference to the target String object with its newly |
|
assigned value. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
|
*/ |
|
String& assign(const String& str); |
| |
/** Allocates an 8 bit representation of this string. The user is |
/** |
responsible for freeing the result. If any characters are truncated, |
Assigns the value of a String to the value in a Char16 buffer. |
a TruncatedCharacter exception is thrown. This exception may |
@param str The Char16 buffer from which to copy the value. |
be suppressed by passing true as the noThrow argument. Extra |
@return A reference to the target String object with its newly |
characters may be allocated at the end of the new string by |
assigned value. |
passing a non-zero value to the extraBytes argument. |
@exception NullPointer If the buffer pointer is NULL. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
*/ | */ |
char* allocateCString(Uint32 extraBytes = 0, Boolean noThrow = false) const; |
String& assign(const Char16* str); |
| |
/** Append the given string to a C-string. If the length is not Uint32(-1), |
/** |
then the lesser of the the length argument and the length of this |
Assigns the value of a String with a specified number of characters |
string is truncated. Otherwise, the entire string is trunctated. The |
of the value from a Char16 buffer. |
TruncatedCharacter exception is thrown if any characters are truncated. |
@param str The Char16 buffer from which to copy the value. |
|
@param n A Uint32 specifying the number of characters to copy. |
|
@return A reference to the target String object with its newly |
|
assigned value. |
|
@exception NullPointer If the buffer pointer is NULL. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
*/ | */ |
void appendToCString( |
String& assign(const Char16* str, Uint32 n); |
char* str, |
|
Uint32 length = Uint32(-1), |
|
Boolean noThrow = false) const; |
|
| |
/// Returns the Ith character of the string. |
/** |
Char16& operator[](Uint32 i); |
Assigns the value of a String to the value from a C string in UTF-8 |
|
format. |
|
@param str The C string from which to copy the value. |
|
@return A reference to the target String object with its newly |
|
assigned value. |
|
@exception NullPointer If the C string pointer is NULL. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
|
@exception Exception If the C string contains invalid UTF-8. |
|
*/ |
|
String& assign(const char* str); |
| |
/// Returns the Ith character of the string (const version). |
/** |
const Char16 operator[](Uint32 i) const; |
Assigns the value of a String with a specified number of characters |
|
of the value from a C string in UTF-8 format. |
|
@param str The C string from which to copy the value. |
|
@param n A Uint32 specifying the number of characters to copy. |
|
@return A reference to the target String object with its newly |
|
assigned value. |
|
@exception NullPointer If the C string pointer is NULL. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
|
@exception Exception If the C string contains invalid UTF-8. |
|
*/ |
|
String& assign(const char* str, Uint32 n); |
| |
/// Append the given character to the string. |
/** |
String& append(const Char16& c) |
Sets a String value to the empty String. |
{ |
*/ |
_rep.insert(_rep.getSize() - 1, c); |
void clear(); |
return *this; |
|
} |
|
| |
/// Append n characters from str to this string. |
/** |
String& append(const Char16* str, Uint32 n); |
Reserves memory for a specified number of (16-bit) characters. |
|
This method does not change the size() of the string or any other |
|
external behavior. If the capacity of the string is already greater |
|
than or equal to the specified size, this method has no effect. The |
|
capacity of a String is set only for performance reasons. |
|
@param capacity A Uint32 specifying the number of characters the |
|
String should be prepared to hold. |
|
*/ |
|
void reserveCapacity(Uint32 capacity); |
| |
/// Append the characters of str to this string. |
/** |
String& append(const String& str) |
Returns the number of characters in a String value. No termination |
{ |
character is included in the count. For example, String("abcd").size() |
return append(str.getData(), str.getLength()); |
returns 4. |
} |
*/ |
|
Uint32 size() const; |
| |
/// Append the characters of str to this string. |
/** |
String& operator+=(const String& x) |
Gets a null-terminated Char16 buffer containing the String value. |
{ |
The buffer is valid until the original String object is modified or |
return append(x); |
destructed. |
} |
@return A pointer to a null-terminated Char16 buffer containing the |
|
String value. |
|
*/ |
|
const Char16* getChar16Data() const; |
| |
/// Append the character given by c to this string. |
/** |
String& operator+=(Char16 c) |
Gets a CString object containing the String value in UTF-8 format. |
{ |
Important: A character pointer extracted from a CString object is |
return append(c); |
only valid while the CString object exists and is unmodified. (See |
} |
the CString documentation.) Thus, in the following example, the |
|
variable p holds a dangling (invalid) pointer: |
|
<pre> |
|
const char * p = (const char *)test.getCString(); |
|
</pre> |
|
This situation can be corrected by declaring a CString variable in |
|
the same scope. |
|
|
|
@return A CString object containing the String value in UTF-8 format. |
|
@exception bad_alloc If the operation fails because of a memory |
|
allocation failure. |
|
*/ |
|
CString getCString() const; |
| |
/// Append the character given by c to this string. |
/** |
String& operator+=(char c) |
Gets a specified character from the String value. |
{ |
@param index Index of the character to access. |
return append(Char16(c)); |
@return The Char16 character at the specified index. |
} |
@exception IndexOutOfBoundsException If the String does not contain a |
|
character at the specified index. |
|
*/ |
|
Char16& operator[](Uint32 index); |
|
|
|
/** |
|
Gets a specified character from the String value. |
|
@param index Index of the character to access. |
|
@return The Char16 character at the specified index. |
|
@exception IndexOutOfBoundsException If the String does not contain a |
|
character at the specified index. |
|
*/ |
|
const Char16 operator[](Uint32 index) const; |
|
|
|
/** |
|
Appends a character to the String. |
|
@param c The Char16 character to append. |
|
@return A reference to the String object containing the newly appended |
|
character. |
|
@exception bad_alloc If the append fails because of a memory |
|
allocation failure. |
|
*/ |
|
String& append(const Char16& c); |
|
|
|
/** |
|
Appends a specified number of characters to the String from a Char16 |
|
buffer. |
|
@param str The Char16 buffer from which to append the characters. |
|
@param n A Uint32 specifying the number of characters to append from |
|
the buffer. |
|
@return A reference to the String object containing the newly appended |
|
characters. |
|
@exception NullPointer If the buffer pointer is NULL. |
|
@exception bad_alloc If the append fails because of a memory |
|
allocation failure. |
|
*/ |
|
String& append(const Char16* str, Uint32 n); |
|
|
|
/** |
|
Appends a String value to the String. |
|
@param str The String to append. |
|
@return A reference to the String object containing the newly appended |
|
characters. |
|
@exception bad_alloc If the append fails because of a memory |
|
allocation failure. |
|
*/ |
|
String& append(const String& str); |
| |
/** Remove size characters from the string starting at the given |
/** |
position. If size is -1, then all characters after pos are removed. |
Removes a specified number of characters from the String starting at a |
|
given index. If the number of characters to remove is specified as |
|
PEG_NOT_FOUND, then all characters from the index to the end of the |
|
String are removed. |
|
@param index Uint32 position in String from which to remove characters. |
|
@param size A Uint32 specifying the number of characters to remove. |
|
The default value is PEG_NOT_FOUND, which means all characters |
|
from the index to the end of the String are to be removed. |
|
@exception IndexOutOfBoundsException If the index plus the size (if not |
|
PEG_NOT_FOUND) is greater than the number of characters in the |
|
String. |
*/ | */ |
void remove(Uint32 pos, Uint32 size = Uint32(-1)); |
void remove(Uint32 index, Uint32 size = PEG_NOT_FOUND); |
| |
/** Return a new string which is initialzed with <TT>length</TT> |
/** |
characters from this string starting at <TT>pos</TT>. |
Creates a new String containing up to the specified number of |
@param <TT>pos</TT> is the positon in string to start getting the |
characters from the specified index in the String. |
substring. |
@param index A Uint32 specifying the index at which to copy characters |
@param <TT>length</TT> is the number of characters to get. If length |
into the new String. |
is -1, then all characters after pos are added to the new string. |
@param n A Uint32 specifying the maximum number of characters to copy |
@return String with the defined substring. |
into the new String. If the value is PEG_NOT_FOUND or is greater |
|
than the number of characters from the index to the end of the |
|
String, the new String contains all characters from the index to |
|
the end of the String. |
|
@return A new String containing up to the specified number of |
|
characters from the specified index in the String. |
|
@exception bad_alloc If the operation fails because of a memory |
|
allocation failure. |
*/ | */ |
String subString(Uint32 pos, Uint32 length = Uint32(-1)) const; |
String subString(Uint32 index, Uint32 n = PEG_NOT_FOUND) const; |
| |
/** Find the position of the first occurence of the character c. |
/** |
If the character is not found, -1 is returned. |
Finds the index of the first occurrence of a specified character in |
|
the String. If the character is not found, PEG_NOT_FOUND is returned. |
|
@param c The Char16 value to find in the String. |
|
@return The Uint32 index of the character in the String if found, |
|
PEG_NOT_FOUND otherwise. |
*/ | */ |
Uint32 find(Char16 c) const; | Uint32 find(Char16 c) const; |
| |
/** Same as find() but start looking in reverse (last character first). |
/** |
|
Finds the index of the first occurrence of a specified character in |
|
the String beginning at a specified index. If the character is not |
|
found, PEG_NOT_FOUND is returned. |
|
@param c The Char16 value to find in the String. |
|
@param index The Uint32 index at which to start the search. |
|
@return The Uint32 index of the character in the String if found, |
|
PEG_NOT_FOUND otherwise. |
*/ | */ |
Uint32 reverseFind(Char16 c) const; |
Uint32 find(Uint32 index, Char16 c) const; |
| |
/** Compare the first n characters of the two strings. Return -1 if s1 |
/** |
is lexographically less than s2. If they are equavalent return 0. |
Finds the index of the first occurrence of a specified String value in |
Otherwise return 1. |
the String. If the String value is not found, PEG_NOT_FOUND is |
|
returned. |
|
@param s The String value to find in the String. |
|
@return The Uint32 index of the beginning of the String value if found, |
|
PEG_NOT_FOUND otherwise. |
*/ | */ |
static int compare(const Char16* s1, const Char16* s2, Uint32 n); |
Uint32 find(const String& s) const; |
| |
/** Compare the two null-terminated strings. If s1 is less than s2, |
/** |
return -1; if equal return 0; otherwise, return 1. |
Finds the index of the last occurrence of a specified character in |
|
the String. If the character is not found, PEG_NOT_FOUND is returned. |
|
@param c The Char16 value to find in the String. |
|
@return The Uint32 index of the character in the String if found, |
|
PEG_NOT_FOUND otherwise. |
*/ | */ |
static int compare(const Char16* s1, const Char16* s2); |
Uint32 reverseFind(Char16 c) const; |
| |
/// Return true if the two strins are equal. |
/** |
static Boolean equal(const String& x, const String& y); |
Converts all characters in the String to lower case. |
|
*/ |
|
void toLower(); |
| |
/// Return true if the two strins are equal. |
/** |
static Boolean equal(const String& x, const Char16* y); |
Constructs a String based on printf specifications. For some |
|
compilers the PEGASUS_FORMAT generates warning messages if |
|
the format string does not match the input arguments. |
|
@param format const char * The format specification as defined |
|
for printf. The format specification corresponds to the |
|
standard C++ printf format specification |
|
@param ... The list of arguments that will be formated. |
|
*/ |
|
PEGASUS_FORMAT(2,3) |
|
void appendPrintf(const char* format, ...); |
| |
/// Return true if the two strins are equal. |
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
static Boolean equal(const Char16* x, const String& y); |
/** |
|
<I><B>Experimental Interface</B></I><BR> |
|
Converts all characters in the String to upper case. |
|
*/ |
|
void toUpper(); |
|
#endif |
| |
/// Return true if the two strins are equal. |
/** |
static Boolean equal(const String& x, const char* y); |
Compares the first n characters of two String objects. |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@param n The maximum number of characters to compare. |
|
@return A negative integer if the first n characters of s1 are |
|
lexographically less than s2, 0 if the first n characters of s1 |
|
and s2 are equal, and a positive integer otherwise. |
|
*/ |
|
static int compare(const String& s1, const String& s2, Uint32 n); |
| |
/// Return true if the two strins are equal. |
/** |
static Boolean equal(const char* x, const String& y); |
Compares two String objects. (Note: Use the comparison |
|
operators < <= > >= to compare String objects.) |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return A negative integer if s1 is lexographically less than s2, |
|
0 if s1 and s2 are equal, and a positive integer otherwise. |
|
*/ |
|
static int compare(const String& s1, const String& s2); |
| |
/// Convert the plain old C-string to lower case: |
/** |
static void toLower(char* str); |
Compares two String objects, ignoring case differences. |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return A negative integer if s1 is lexographically less than s2, |
|
0 if s1 and s2 are equal, and a positive integer otherwise. |
|
(Case differences are ignored in all cases.) |
|
*/ |
|
static int compareNoCase(const String& s1, const String& s2); |
| |
/** | /** |
This member is used to represent empty strings. Using this member |
Compares two String objects for equality. For example, |
avoid an expensive construction of an empty string (e.g., String()). |
<pre> |
|
String s1 = "Hello World"; |
|
String s2 = s1; |
|
assert(String::equal(s1, s2)); |
|
</pre> |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return True if the two strings are equal, false otherwise. |
*/ | */ |
static const String EMPTY; |
static Boolean equal(const String& s1, const String& s2); |
| |
private: |
/** |
|
Compares two strings and returns true if they are equal independent of |
|
the case of the characters. |
|
@param ... Variable arguments as defined for printf |
|
*/ |
|
static Boolean equalNoCase(const String& s1, const String& s2); |
| |
static Uint32 _min(Uint32 x, Uint32 y) { return x < y ? x : y; } |
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
| |
Array<Char16> _rep; |
String(const String& s1, const String& s2); |
}; |
|
| |
inline Boolean operator==(const String& x, const String& y) |
String(const String& s1, const char* s2); |
{ |
|
return String::equal(x, y); |
|
} |
|
| |
inline Boolean operator==(const String& x, const char* y) |
String(const char* s1, const String& s2); |
{ |
|
return String::equal(x, y); |
|
} |
|
| |
inline Boolean operator==(const char* x, const String& y) |
String& operator=(const char* str); |
{ |
|
return String::equal(x, y); |
|
} |
|
| |
inline Boolean operator!=(const String& x, const String& y) |
Uint32 find(const char* s) const; |
{ |
|
return !String::equal(x, y); |
|
} |
|
| |
PEGASUS_COMMON_LINKAGE std::ostream& operator<<( |
static Boolean equal(const String& s1, const char* s2); |
std::ostream& os, |
|
const String& x); |
|
| |
inline String operator+(const String& x, const String& y) |
static int compare(const String& s1, const char* s2); |
{ |
|
return String(x).append(y); |
|
} |
|
| |
inline Boolean operator<(const String& x, const String& y) |
String& append(const char* str); |
{ |
|
return String::compare(x.getData(), y.getData()) < 0; |
|
} |
|
| |
inline Boolean operator<=(const String& x, const String& y) |
String& append(const char* str, Uint32 size); |
{ |
|
return String::compare(x.getData(), y.getData()) <= 0; |
|
} |
|
| |
inline Boolean operator>(const String& x, const String& y) |
static Boolean equalNoCase(const String& s1, const char* s2); |
{ |
|
return String::compare(x.getData(), y.getData()) > 0; |
|
} |
|
| |
inline Boolean operator>=(const String& x, const String& y) |
#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */ |
{ |
|
return String::compare(x.getData(), y.getData()) >= 0; |
private: |
} |
|
|
StringRep* _rep; |
|
}; |
|
|
|
/** |
|
Compares two String objects for equality. |
|
@param str1 The first String to compare. |
|
@param str2 The second String to compare. |
|
@return True if the strings are equal, false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator==( |
|
const String& str1, |
|
const String& str2); |
| |
/** Return a version of this string whose characters have been shifted |
/** |
to lower case. |
Compares a String and a C string for equality. |
|
@param str1 The String to compare. |
|
@param str2 The C string to compare. |
|
@return True if the strings are equal, false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator==(const String& str1, const char* str2); |
|
|
|
/** |
|
Compares a String and a C string for equality. |
|
@param str1 The C string to compare. |
|
@param str2 The String to compare. |
|
@return True if the strings are equal. false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator==(const char* str1, const String& str2); |
|
|
|
/** |
|
Compares two String objects for inequality. |
|
@param str1 The first String to compare. |
|
@param str2 The second String to compare. |
|
@return False if the strings are equal, true otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator!=( |
|
const String& str1, |
|
const String& str2); |
|
|
|
/** |
|
Writes a String value to an output stream. Characters with a zero value or |
|
with a non-zero high-order byte are written in a hexadecimal encoding. |
|
@param os The output stream to which the String value is written. |
|
@param str The String to write to the output stream. |
|
@return A reference to the output stream. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( |
|
PEGASUS_STD(ostream)& os, |
|
const String& str); |
|
|
|
/** |
|
Concatenates String objects. For example, |
|
<pre> |
|
String t1 = "abc"; |
|
String t2; |
|
t2 = t1 + "def" |
|
assert(t2 == "abcdef"); |
|
</pre> |
|
@param str1 The first String to concatenate. |
|
@param str2 The second String to concatenate. |
|
@return The concatenated String. |
*/ | */ |
PEGASUS_COMMON_LINKAGE String ToLower(const String& str); |
PEGASUS_COMMON_LINKAGE String operator+(const String& str1, const String& str2); |
|
|
|
/** |
|
Compares two String objects. |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return True if s1 is lexographically less than s2, false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator<( |
|
const String& str1, |
|
const String& str2); |
|
|
|
/** |
|
Compares two String objects. |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return True if s1 is lexographically less than or equal to s2, |
|
false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator<=( |
|
const String& str1, |
|
const String& str2); |
|
|
|
/** |
|
Compares two String objects. |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return True if s1 is lexographically greater than s2, false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator>( |
|
const String& str1, |
|
const String& str2); |
|
|
|
/** |
|
Compares two String objects. |
|
@param s1 The first String to compare. |
|
@param s2 The second String to compare. |
|
@return True if s1 is lexographically greater than or equal to s2, |
|
false otherwise. |
|
*/ |
|
PEGASUS_COMMON_LINKAGE Boolean operator>=( |
|
const String& str1, |
|
const String& str2); |
|
|
|
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2); |
| |
|
PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator==(const char* s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator!=(const char* s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator<(const char* s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator>(const char* s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator<=(const char* s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE Boolean operator>=(const char* s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const String& s2); |
|
|
|
PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const char* s2); |
|
|
|
PEGASUS_COMMON_LINKAGE String operator+(const char* s1, const String& s2); |
|
|
|
#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */ |
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |
#endif /* Pegasus_String_h */ |
#if defined(PEGASUS_INTERNALONLY) |
|
# include "StringInline.h" |
|
#endif |
| |
|
#endif /* Pegasus_String_h */ |