version 1.89.2.4, 2005/09/29 02:22:39
|
version 1.96, 2006/01/30 16:17:08
|
|
|
//%2005//////////////////////////////////////////////////////////////////////// |
//%2006//////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development | // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development |
// Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. | // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems. |
|
|
// IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. | // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group. |
// Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; | // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
// EMC Corporation; VERITAS Software Corporation; The Open Group. | // EMC Corporation; VERITAS Software Corporation; The Open Group. |
|
// Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.; |
|
// EMC Corporation; Symantec Corporation; The Open Group. |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a copy | // Permission is hereby granted, free of charge, to any person obtaining a copy |
// of this software and associated documentation files (the "Software"), to | // of this software and associated documentation files (the "Software"), to |
|
|
#include <Pegasus/Common/Char16.h> | #include <Pegasus/Common/Char16.h> |
#include <Pegasus/Common/Linkage.h> | #include <Pegasus/Common/Linkage.h> |
| |
// Locale constants |
|
// These constants need to be defined as follows: |
|
// lower case language; underscore; Uppercase Country |
|
const char ENGLISH_US[] = "en_US"; |
|
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
class String; | class String; |
|
|
| |
/** Initialize with first <TT>n</TT> characters from <TT>str</TT>. | /** Initialize with first <TT>n</TT> characters from <TT>str</TT>. |
@param str Specifies the name of the String instance. | @param str Specifies the name of the String instance. |
@param n Specifies the Uint32 size to use for the length of the string object. |
@param n Specifies Uint32 size to use for the length of the string object. |
@exception bad_alloc Thrown if there is insufficient memory. | @exception bad_alloc Thrown if there is insufficient memory. |
*/ | */ |
String(const String& str, Uint32 n); | String(const String& str, Uint32 n); |
|
|
String test = "abc"; | String test = "abc"; |
printf("test = %s\n", (const char*)test.getCString()); | printf("test = %s\n", (const char*)test.getCString()); |
| |
NOTE: Do not do the following: |
USAGE WARNING: Do not do the following: |
|
|
const char * p = (const char *)test.getCString(); | const char * p = (const char *)test.getCString(); |
|
|
The pointer p will be invalid. This is because | The pointer p will be invalid. This is because |
the CString object is destructed, which deletes |
the Compiler casues the CString object to be created on the |
the heap space for p. |
callers stack as a temporary object. The deletion is therefore |
|
also the responsibility of the Compiler. The Compiler may cause |
|
it to be deleted at anytime after the return. Typically it is |
|
done at the closeof the next scope. When it is deleted the |
|
"const char *p" above will become a dangling pointer. |
|
|
|
The correct usage to achieve the "const char * p" is |
|
as follows: |
|
|
|
String str = "hello"; |
|
... |
|
CString cstr = str.getCString(); |
|
|
|
const char* p = (const char*)cstr; |
|
|
|
This tells the compiler to create a CString object on the callers |
|
stack that is the deleted at the discretion of the caller rather |
|
than the compiler. The "const char *p" above will be good until |
|
the caller explicity deletes the CString object. |
|
|
|
|
</pre> | </pre> |
@exception bad_alloc Thrown if there is insufficient memory. | @exception bad_alloc Thrown if there is insufficient memory. |
*/ | */ |
|
|
void toUpper(); | void toUpper(); |
#endif | #endif |
| |
/** Compare the first n characters of the two 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. |
@param n Number of characters to compare. |
@param s2 The second String to compare. |
@return Return -1 If s1 is lexographically less than s2; if they are |
@param n The maximum number of characters to compare. |
equivalent return 0; otherwise return 1. |
@return Returns 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); | static int compare(const String& s1, const String& s2, Uint32 n); |
| |
/** Compare two null-terminated strings. |
/** |
@param s1 First null-terminated string for the comparison. |
Compares two String objects. |
@param s2 Second null-terminated string for the comparison. |
@param s1 The first String to compare. |
@return Return -1 if s1 is less than s2; if equal return 0; |
@param s2 The second String to compare. |
otherwise return 1. |
@return Returns a negative integer if s1 is lexographically less |
|
than s2, 0 if s1 and s2 are equal, and a positive integer otherwise. |
| |
NOTE: Use the comparison operators <,<= > >= to compare | NOTE: Use the comparison operators <,<= > >= to compare |
String objects. | String objects. |
*/ | */ |
static int compare(const String& s1, const String& s2); | static int compare(const String& s1, const String& s2); |
| |
/** Compare two null-terminated strings but ignore case. |
/** |
@param s1 First null-terminated string for the comparison. |
Compares two String objects, ignoring case differences. |
@param s2 Second null-terminated string for the comparison. |
@param s1 The first String to compare. |
@return Return -1 if s1 is less than s2; if equal return 0; |
@param s2 The second String to compare. |
otherwise return 1. |
@return Returns a negative integer if s1 is lexographically less |
|
than s2, 0 if s1 and s2 are equal, and a positive integer otherwise. |
NOTE: Use the comparison operators <,<= > >= to compare |
(Case differences are ignored in all cases.) |
String objects. |
|
*/ | */ |
static int compareNoCase(const String& s1, const String& s2); | static int compareNoCase(const String& s1, const String& s2); |
| |
|
|
*/ | */ |
static Boolean equalNoCase(const String& str1, const String& str2); | static Boolean equalNoCase(const String& str1, const String& str2); |
| |
//// |
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
//// {New interfaces start here: |
|
//// |
|
|
|
enum ASCII7Tag { ASCII7 }; |
|
| |
String(const String& s1, const String& s2); | String(const String& s1, const String& s2); |
| |
|
|
| |
String(const char* s1, const String& s2); | String(const char* s1, const String& s2); |
| |
String(const char* str, ASCII7Tag tag); |
|
|
|
String(const char* str, size_t n, ASCII7Tag tag); |
|
|
|
String& operator=(const char* str); | String& operator=(const char* str); |
| |
String& assignASCII7(const char* str); |
|
|
|
String& assignASCII7(const char* str, Uint32 n); |
|
|
|
Uint32 find(const char* s) const; | Uint32 find(const char* s) const; |
| |
Uint32 find(char c) const; |
|
|
|
static Boolean equal(const String& s1, const char* s2); | static Boolean equal(const String& s1, const char* s2); |
| |
static int compare(const String& s1, const char* s2); | static int compare(const String& s1, const char* s2); |
| |
String& append(char c); |
|
|
|
String& append(const char* str); | String& append(const char* str); |
| |
String& append(const char* str, Uint32 size); | String& append(const char* str, Uint32 size); |
| |
static Boolean equalNoCase(const String& s1, const char* s2); | static Boolean equalNoCase(const String& s1, const char* s2); |
| |
private: |
#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */ |
|
|
void _append_char_aux(); |
|
|
|
static Boolean equalNoCase_aux(const String& str1, const String& str2); |
|
|
|
//// |
|
//// }New interfaces end here: |
|
//// |
|
| |
private: | private: |
| |
Uint32 _find_aux(const Char16* s, Uint32 n) const; |
|
|
|
StringRep* _rep; | StringRep* _rep; |
}; | }; |
| |
|
|
const String& str1, | const String& str1, |
const String& str2); | const String& str2); |
| |
//// |
#ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES |
//// {New functions start here. |
|
//// |
|
| |
PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2); | PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2); |
| |
|
|
| |
PEGASUS_COMMON_LINKAGE String operator+(const char* s1, const String& s2); | PEGASUS_COMMON_LINKAGE String operator+(const char* s1, const String& s2); |
| |
//// |
#endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */ |
//// }New functions end here. |
|
//// |
|
| |
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |
#ifdef PEGASUS_INTERNALONLY |
#if defined(PEGASUS_INTERNALONLY) && !defined(PEGASUS_DISABLE_INTERNAL_INLINES) |
# define PEGASUS_STRING_INLINE inline |
|
# include "StringInline.h" | # include "StringInline.h" |
# undef PEGASUS_STRING_INLINE |
|
#endif | #endif |
| |
#endif /* Pegasus_String_h */ | #endif /* Pegasus_String_h */ |