version 1.73, 2002/10/07 17:42:04
|
version 1.102, 2008/12/01 17:49:56
|
|
|
//%///////////////////////////////////////////////////////////////////////////// |
//%LICENSE//////////////////////////////////////////////////////////////// |
// |
|
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
|
// The Open Group, Tivoli Systems |
|
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// Licensed to The Open Group (TOG) under one or more contributor license |
// of this software and associated documentation files (the "Software"), to |
// agreements. Refer to the OpenPegasusNOTICE.txt file distributed with |
// deal in the Software without restriction, including without limitation the |
// this work for additional information regarding copyright ownership. |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// Each contributor licenses this file to you under the OpenPegasus Open |
// sell copies of the Software, and to permit persons to whom the Software is |
// Source License; you may not use this file except in compliance with the |
// furnished to do so, subject to the following conditions: |
// License. |
// | // |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// Permission is hereby granted, free of charge, to any person obtaining a |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// copy of this software and associated documentation files (the "Software"), |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// to deal in the Software without restriction, including without limitation |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// and/or sell copies of the Software, and to permit persons to whom the |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// Software is furnished to do so, subject to the following conditions: |
// 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. |
|
// | // |
//============================================================================== |
// The above copyright notice and this permission notice shall be included |
|
// in all copies or substantial portions of the Software. |
// | // |
// Author: Mike Brasher (mbrasher@bmc.com) |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
|
// 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. |
// | // |
// Modified By: Karl Schopmeyer(k.schopmeyer@opengroup.org) |
////////////////////////////////////////////////////////////////////////// |
// Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com) |
|
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
| |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
class String; | class String; |
class StringRep; |
struct StringRep; |
| |
/** The CString class provides access to an 8-bit String representation. |
/** |
|
The CString class provides access to an 8-bit String representation. |
*/ | */ |
class PEGASUS_COMMON_LINKAGE CString | class PEGASUS_COMMON_LINKAGE CString |
{ | { |
public: | public: |
| |
|
/** |
|
Constructs a CString object with a null string value. |
|
*/ |
CString(); | CString(); |
| |
|
/** |
|
Constructs an independent copy of a CString object. |
|
@param cstr The CString instance to copy. |
|
*/ |
CString(const CString& cstr); | CString(const CString& cstr); |
| |
|
/** |
|
Destructs a CString object. |
|
*/ |
~CString(); | ~CString(); |
| |
|
/** |
|
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); | CString& operator=(const CString& cstr); |
| |
|
/** |
|
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: |
|
|
|
const char* cstr = String("Hello").getCString(); |
|
printf(cstr); |
|
|
|
@return Returns a const char pointer to the CString's data. |
|
*/ |
operator const char*() const; | operator const char*() const; |
| |
private: | private: |
|
|
| |
friend class String; | friend class String; |
| |
void* _rep; |
char* _rep; |
}; | }; |
| |
/** | /** |
The Pegasus String C++ Class implements the CIM string type. |
This class implements the CIM string type. The intrinsic string format |
This class is based on the general handle/representation pattern |
is UTF-16, which is a superset of the UCS-2 characters allowed in CIM |
defined for all the Pegasus objects. However, it differes from |
strings. Facilities are provided for converting to and from UTF-8 |
most in that it implements "copy on assign" all of the others implement |
character strings. |
"no copy on assign" semantics. The string class uses the Array class and |
|
implements an array of characters. |
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 | class PEGASUS_COMMON_LINKAGE String |
{ | { |
public: | public: |
| |
/** EMPTY - Represent an empty string. |
/** |
This member is used to represent empty strings. Using this member |
Represents an empty string. This value may be used as a convenience |
avoids an expensive construction of an empty string (e.g., String()). |
to avoid construction of an empty String object. |
*/ | */ |
static const String EMPTY; | static const String EMPTY; |
| |
/** Default constructor without parameters. This constructor creates a |
/** |
null string |
Constructs an empty String. |
<pre> |
|
String test; |
|
</pre> |
|
*/ | */ |
String(); | String(); |
| |
/// Copy constructor. |
/** |
|
Constructs a String with the value of another String. |
|
@param str The String from which to copy the value. |
|
*/ |
String(const String& str); | String(const String& str); |
| |
/// Initialize with first n characters from str. |
/** |
|
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); | String(const String& str, Uint32 n); |
| |
/// Initialize with str. |
/** |
|
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); | String(const Char16* str); |
| |
/// Initialize with first n characters of str. |
/** |
|
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); | String(const Char16* str, Uint32 n); |
| |
/// Initialize from a plain old C-String: |
/** |
|
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); | String(const char* str); |
| |
/// Initialize from the first n characters of a plain old C-String: |
/** |
|
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); | String(const char* str, Uint32 n); |
| |
/// String destructor. Used by the representation of the String object |
/** |
|
Destructs a String object. |
|
*/ |
~String(); | ~String(); |
| |
/** Assign this string with str. |
/** |
<pre> |
Assigns the value of a String to the value of another String. |
String t1 = "abc"; |
@param str The String from which to copy the value. |
String t2 = t1; |
@return A reference to the target String object with its newly |
</pre> |
assigned value. |
|
@exception bad_alloc If the assignment fails because of a memory |
|
allocation failure. |
*/ | */ |
String& operator=(const String& str); | String& operator=(const String& str); |
| |
/** Assign this string with String str |
/** |
@param str String to assign |
Assigns the value of a String to the value of another String. |
@return Returns the 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); | String& assign(const String& str); |
| |
/// Assign this string with str. |
/** |
|
Assigns the value of a String to the value in a Char16 buffer. |
|
@param str The Char16 buffer from which to copy the value. |
|
@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. |
|
*/ |
String& assign(const Char16* str); | String& assign(const Char16* str); |
| |
/// Assign this string with first n characters of str. |
/** |
|
Assigns the value of 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. |
|
@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. |
|
*/ |
String& assign(const Char16* str, Uint32 n); | String& assign(const Char16* str, Uint32 n); |
| |
/// Assign this string with the plain old C-String str. |
/** |
|
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); | String& assign(const char* str); |
| |
/// Assign this string with first n characters of the plain old C-String str. |
/** |
|
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); | String& assign(const char* str, Uint32 n); |
| |
/** clear - Clear this string. After calling clear(), size() will return 0. |
/** |
<pre> |
Sets a String value to the empty String. |
String test = "abc"; |
|
test.clear(); // String test is now NULL (length == 0) |
|
</pre> |
|
*/ | */ |
void clear(); | void clear(); |
| |
|
/** |
/** reserveCapacity - Reserves memory for capacity characters. Notice |
Reserves memory for a specified number of (16-bit) characters. |
that this does not change the size of the string (size() returns |
This method does not change the size() of the string or any other |
what it did before). If the capacity of the string is already |
external behavior. If the capacity of the string is already greater |
greater or equal to the capacity argument, this method has no |
than or equal to the specified size, this method has no effect. The |
effect. The capacity of a String object has no bearing on its |
capacity of a String is set only for performance reasons. |
external behavior. The capacity of a String is set only for |
@param capacity A Uint32 specifying the number of characters the |
performance reasons. |
String should be prepared to hold. |
@param capacity defines the capacity in characters to reserve. |
|
*/ | */ |
void reserveCapacity(Uint32 capacity); | void reserveCapacity(Uint32 capacity); |
| |
/** Returns the length of the String object. |
/** |
@return Length of the string in characters. |
Returns the number of characters in a String value. No termination |
<pre> |
character is included in the count. For example, String("abcd").size() |
String s = "abcd"; |
returns 4. |
assert(s.size() == 4); |
|
</pre> |
|
*/ | */ |
Uint32 size() const; | Uint32 size() const; |
| |
/** getChar16Data Returns a pointer to the first character in the |
/** |
null-terminated Char16 buffer of the String object. |
Gets a null-terminated Char16 buffer containing the String value. |
@return Pointer to the first character of the String object |
The buffer is valid until the original String object is modified or |
<pre> |
destructed. |
String t1 = "abc"; |
@return A pointer to a null-terminated Char16 buffer containing the |
const Char16* q = t1.getChar16Data(); |
String value. |
</pre> |
|
*/ | */ |
const Char16* getChar16Data() const; | const Char16* getChar16Data() const; |
| |
/** getCString - Create an 8-bit representation of this String object. |
/** |
|
Gets a CString object containing the String value in UTF-8 format. |
@param truncatedCharacters Output parameter specifying whether any |
Important: A character pointer extracted from a CString object is |
characters were truncated in the conversion. |
only valid while the CString object exists and is unmodified. (See |
|
the CString documentation.) Thus, in the following example, the |
@return CString object that provides access to the 8-bit String |
variable p holds a dangling (invalid) pointer: |
representation |
<pre> |
|
const char * p = (const char *)test.getCString(); |
<pre> |
</pre> |
String test = "abc"; |
This situation can be corrected by declaring a CString variable in |
printf("test = %s\n", (const char*)test.getCString()); |
the same scope. |
</pre> |
|
|
@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; | CString getCString() const; |
| |
/** Returns the specified character of the String object. |
/** |
@param index Index of the character to access |
Gets a specified character from the String value. |
@exception IndexOutOfBoundsException if the index |
@param index Index of the character to access. |
is outside the bounds of the String. |
@return The Char16 character at the specified index. |
<pre> |
@exception IndexOutOfBoundsException If the String does not contain a |
String t1 = "abc; |
character at the specified index. |
Char16 c = t1[1]; // character b |
|
</pre> |
|
*/ | */ |
Char16& operator[](Uint32 index); | Char16& operator[](Uint32 index); |
| |
/** Returns the specified character of the String object (const version). |
/** |
@param index Index of the character to access |
Gets a specified character from the String value. |
@exception IndexOutOfBoundsException if the index |
@param index Index of the character to access. |
is outside the bounds of the String. |
@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; | const Char16 operator[](Uint32 index) const; |
| |
/** Append the given character to this String. |
/** |
@param c Character to append. |
Appends a character to the String. |
@return This String |
@param c The Char16 character to append. |
<pre> |
@return A reference to the String object containing the newly appended |
String t1 = "abc"; |
character. |
t1.append (Char16('d')); |
@exception bad_alloc If the append fails because of a memory |
assert(t1 == "abcd"); |
allocation failure. |
</pre> |
|
*/ | */ |
String& append(const Char16& c); | String& append(const Char16& c); |
| |
/// Append n characters from str to this String. |
/** |
|
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); | String& append(const Char16* str, Uint32 n); |
| |
/** Append the given String to this String. |
/** |
@param str String to append. |
Appends a String value to the String. |
@return This String |
@param str The String to append. |
<pre> |
@return A reference to the String object containing the newly appended |
String test = "abc"; |
characters. |
test.append("def"); |
@exception bad_alloc If the append fails because of a memory |
assert(test == "abcdef"); |
allocation failure. |
</pre> |
|
*/ | */ |
String& append(const String& str); | String& append(const String& str); |
| |
/** Remove size characters from the string starting at the given |
/** |
index. If size is PEG_NOT_FOUND, then all characters after index are |
Removes a specified number of characters from the String starting at a |
removed. |
given index. If the number of characters to remove is specified as |
@param index Position in string to start remove |
PEG_NOT_FOUND, then all characters from the index to the end of the |
@param size Number of characters to remove. Default is PEG_NOT_FOUND |
String are removed. |
which causes all characters after index to be removed |
@param index Uint32 position in String from which to remove characters. |
<pre> |
@param size A Uint32 specifying the number of characters to remove. |
String s; |
The default value is PEG_NOT_FOUND, which means all characters |
s = "abc"; |
from the index to the end of the String are to be removed. |
s.remove(0, 1); |
@exception IndexOutOfBoundsException If the index plus the size (if not |
assert(String::equal(s, "bc")); |
PEG_NOT_FOUND) is greater than the number of characters in the |
assert(s.size() == 2); |
String. |
s.remove(0); |
|
assert(String::equal(s, "")); |
|
assert(s.size() == 0); |
|
</pre> |
|
@exception IndexOutOfBoundsException if size is greater than |
|
length of String plus starting index for remove. |
|
*/ | */ |
void remove(Uint32 index, Uint32 size = PEG_NOT_FOUND); | 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>index</TT>. |
Creates a new String containing up to the specified number of |
@param <TT>index</TT> is the index 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 PEG_NOT_FOUND, then all characters after index are added to the new |
@param n A Uint32 specifying the maximum number of characters to copy |
string. |
into the new String. If the value is PEG_NOT_FOUND or is greater |
@return String with the defined substring. |
than the number of characters from the index to the end of the |
<pre> |
String, the new String contains all characters from the index to |
s = "abcdefg"; |
the end of the String. |
s.remove(3); |
@return A new String containing up to the specified number of |
assert(String::equal(s, "abc")); |
characters from the specified index in the String. |
</pre> |
@exception bad_alloc If the operation fails because of a memory |
|
allocation failure. |
*/ | */ |
String subString(Uint32 index, Uint32 length = PEG_NOT_FOUND) const; |
String subString(Uint32 index, Uint32 n = PEG_NOT_FOUND) const; |
| |
/** Find the index of the first occurence of the character c. |
/** |
If the character is not found, PEG_NOT_FOUND is returned. |
Finds the index of the first occurrence of a specified character in |
@param c Char to be found in the String |
the String. If the character is not found, PEG_NOT_FOUND is returned. |
@return Position of the character in the string or PEG_NOT_FOUND if not |
@param c The Char16 value to find in the String. |
found. |
@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 above but starts searching from the given index. */ |
/** |
|
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 find(Uint32 index, Char16 c) const; | Uint32 find(Uint32 index, Char16 c) const; |
| |
/** Find the index of the first occurence of the string object. |
/** |
This function finds one string inside another |
Finds the index of the first occurrence of a specified String value in |
If the matching substring is not found, PEG_NOT_FOUND is returned. |
the String. If the String value is not found, PEG_NOT_FOUND is |
@param s String object to be found in the String |
returned. |
@return Position of the substring in the String or PEG_NOT_FOUND if not |
@param s The String value to find in the String. |
found. |
@return The Uint32 index of the beginning of the String value if found, |
|
PEG_NOT_FOUND otherwise. |
*/ | */ |
Uint32 find(const String& s) const; | Uint32 find(const String& s) const; |
| |
/** reverseFind - Same as find() but start looking in reverse (last |
/** |
character first). |
Finds the index of the last occurrence of a specified character in |
@param c Char16 character to find in String. |
the String. If the character is not found, PEG_NOT_FOUND is returned. |
@Seealso find |
@param c The Char16 value to find in the String. |
@return Position of the character in the string or PEG_NOT_FOUND if not |
@return The Uint32 index of the character in the String if found, |
found. |
PEG_NOT_FOUND otherwise. |
|
|
NOTE: This function is defined only for char* input, not for |
|
String. |
|
*/ | */ |
Uint32 reverseFind(Char16 c) const; | Uint32 reverseFind(Char16 c) const; |
| |
/** Converts all characters in this string to lower case. |
/** |
|
Converts all characters in the String to lower case. |
*/ | */ |
void toLower(); | void toLower(); |
| |
/** Compare the first n characters of the two strings.. |
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
@param s1 First null-terminated string for the comparison. |
/** |
@param s2 Second null-terminated string for the comparison. |
<I><B>Experimental Interface</B></I><BR> |
@param n Number of characters to compare. |
Converts all characters in the String to upper case. |
@return Return -1 if s1 is lexographically less than s2. If they are |
|
equavalent return 0. Otherwise return 1. |
|
*/ | */ |
static int compare(const String& s1, const String& s2, Uint32 n); |
void toUpper(); |
|
#endif |
| |
/** Compare two null-terminated strings. |
/** |
@param s1 First null-terminated string for the comparison. |
Compares the first n characters of two String objects. |
@param s2 Second null-terminated string for the comparison. |
@param s1 The first String to compare. |
@return If s1 is less than s2, return -1; if equal return 0; |
@param s2 The second String to compare. |
otherwise, return 1. |
@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); |
| |
NOTE: Use the comparison operators <,<= > >= to compare |
/** |
String objects. |
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); | static int compare(const String& s1, const String& s2); |
| |
/** Just like one above except ignores case differences. |
/** |
|
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); | static int compareNoCase(const String& s1, const String& s2); |
| |
/** Compare two String objects for equality. |
/** |
@param s1 First <TT>String</TT> for comparison. |
Compares two String objects for equality. For example, |
@param s2 Second <TT>String</TT> for comparison. |
|
|
|
@return Boolean true if the two strings are equal. |
|
<pre> | <pre> |
String s1 = "Hello World"; | String s1 = "Hello World"; |
String s2 = s1; | String s2 = s1; |
String s3(s2); |
assert(String::equal(s1, s2)); |
assert(String::equal(s1, s3)); |
|
</pre> | </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 Boolean equal(const String& str1, const String& str2); |
static Boolean equal(const String& s1, const String& s2); |
| |
/** equalNoCase - Compares two strings and returuns true if they |
/** |
are equal indpedent of case of the characters. |
Compares two strings and returns true if they are equal independent of |
@param str1 First String parameter |
the case of the characters. |
@param str2 Second String parameter |
@param s1 The first String to compare. |
@return true if strings are equal independent of case. |
@param s2 The second String to compare. |
|
@return true if the strings are equal independent of case, false |
|
otherwise. |
*/ | */ |
static Boolean equalNoCase(const String& str1, const String& str2); |
static Boolean equalNoCase(const String& s1, const String& s2); |
|
|
|
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
|
|
|
String(const String& s1, const String& s2); |
|
|
|
String(const String& s1, const char* s2); |
|
|
|
String(const char* s1, const String& s2); |
|
|
|
String& operator=(const char* str); |
|
|
|
Uint32 find(const char* s) const; |
|
|
|
static Boolean equal(const String& s1, const char* s2); |
|
|
|
static int compare(const String& s1, const char* s2); |
|
|
|
String& append(const char* str); |
|
|
|
String& append(const char* str, Uint32 size); |
|
|
|
static Boolean equalNoCase(const String& s1, const char* s2); |
|
|
|
#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */ |
| |
private: | private: |
| |
StringRep* _rep; | StringRep* _rep; |
}; | }; |
| |
/** String operator ==. Test for equality between two strings of any of the |
/** |
types String or char*. |
Compares two String objects for equality. |
@return Boolean - True if the strings are equal |
@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==( | PEGASUS_COMMON_LINKAGE Boolean operator==( |
const String& str1, | const String& str1, |
const String& str2); | const String& str2); |
| |
/** String operator ==. Test for equality between two strings |
/** |
|
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); | PEGASUS_COMMON_LINKAGE Boolean operator==(const String& str1, const char* str2); |
| |
/** String operator ==. Test for equality between two strings |
/** |
|
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); | PEGASUS_COMMON_LINKAGE Boolean operator==(const char* str1, const String& str2); |
| |
/** String operator ==. Test for equality between two strings |
/** |
|
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!=( | PEGASUS_COMMON_LINKAGE Boolean operator!=( |
const String& str1, | const String& str1, |
const String& str2); | 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_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( |
PEGASUS_STD(ostream)& os, | PEGASUS_STD(ostream)& os, |
const String& str); | const String& str); |
| |
/** overload operator + - Concatenates String objects. |
/** |
|
Concatenates String objects. For example, |
<pre> | <pre> |
String t1 = "abc"; | String t1 = "abc"; |
String t2; | String t2; |
t2 = t1 + "def" | t2 = t1 + "def" |
assert(t2 == "abcdef"); | assert(t2 == "abcdef"); |
</pre> | </pre> |
|
@param str1 The first String to concatenate. |
|
@param str2 The second String to concatenate. |
|
@return The concatenated String. |
*/ | */ |
PEGASUS_COMMON_LINKAGE String operator+(const String& str1, const String& str2); | PEGASUS_COMMON_LINKAGE String operator+(const String& str1, const String& str2); |
| |
/** overload operator < - Compares String obects. |
/** |
<pre> |
Compares two String objects. |
String t1 = "def"; |
@param s1 The first String to compare. |
String t2 = "a"; |
@param s2 The second String to compare. |
assert (t2 < t1); |
@return True if s1 is lexographically less than s2, false otherwise. |
</pre> |
|
*/ | */ |
PEGASUS_COMMON_LINKAGE Boolean operator<( | PEGASUS_COMMON_LINKAGE Boolean operator<( |
const String& str1, | const String& str1, |
const String& str2); | const String& str2); |
| |
/** overload operator <= compares String objects. |
/** |
|
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<=( | PEGASUS_COMMON_LINKAGE Boolean operator<=( |
const String& str1, | const String& str1, |
const String& str2); | const String& str2); |
| |
/** Overload operator > compares String objects |
/** |
|
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>( | PEGASUS_COMMON_LINKAGE Boolean operator>( |
const String& str1, | const String& str1, |
const String& str2); | const String& str2); |
| |
/** overload operator >= - Compares String objects |
/** |
|
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>=( | PEGASUS_COMMON_LINKAGE Boolean operator>=( |
const String& str1, | const String& str1, |
const String& str2); | const String& str2); |
| |
#ifndef PEGASUS_REMOVE_DEPRECATED |
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
/** Compare two strings but ignore any case differences. |
|
*/ |
PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2); |
PEGASUS_COMMON_LINKAGE int CompareNoCase(const char* s1, const char* s2); |
|
#endif |
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 |
| |
|
#if defined(PEGASUS_INTERNALONLY) |
|
# include "StringInline.h" |
|
#endif |
|
|
#endif /* Pegasus_String_h */ | #endif /* Pegasus_String_h */ |