Character strings in the Softimage SDK are represented with the CString class.
CString consist of a variable-length sequence of characters. The CString class can store either wide characters (16-bit values) or ASCII ("char") characters (8-bit values).
Using wide characters allows unicode strings to be represented
in the SDK. Therefore you must use the L
character
before a character or a string constant to designate the wide
character type constant.
The string type of a CString object is generally immutable. Once you create a CString object as wide, the type remains as such until an assignment operation is performed with an ASCII string; likewise when creating an ASCII CString object. The CString class provides methods to perform wide and ASCII operations. Mixing wide and ASCII operations is possible but would trigger internal string conversions on the method arguments which could lead to performance issues.
L
character to designate the
wide-character type constant
using namespace XSI; CString myString(L"Mystring");
using namespace XSI; CString myWideString(); myWideString = L"Wide String"; // This will change the CString type from wide to ASCII. myWideString = "ASCII String";
using namespace XSI; CString myAsciiString( "MyString" ); // This will change the CString type from ASCII to wide. myAsciiString = L"Wide String";
Definition at line 76 of file xsi_string.h.
#include <xsi_string.h>
Classes |
|
struct | StringData |
Private class used for holding the
CString data. |
|
Public Member Functions |
|
CString () | |
Default constructor. |
|
virtual | ~CString () |
Default destructor. |
|
CString (const CString &in_str) | |
Constructs a
CString object from another
CString object. |
|
CString (const wchar_t *in_str) | |
Constructs a
CString object from a null-terminated wide character string.
|
|
CString (const wchar_t *in_str, ULONG in_nCount) | |
Constructs a
CString object by copying the first in_nCount
characters from a null-terminated wide character string. |
|
CString (const char *in_str) | |
Constructs a
CString object from a null-terminated ASCII character string.
|
|
CString (const char *in_str, ULONG in_nCount) | |
Constructs a
CString object by copying the first in_nCount
characters from a null-terminated ascii character string. |
|
CString (const CValue &in_val) | |
Constructs a
CString object from a
CValue object. |
|
const wchar_t * | GetWideString () const |
Accessor to a null-terminated, wide
character representation of the string. |
|
const char * | GetAsciiString () const |
Accessor to a null-terminated, ASCII
character representation of the string. |
|
CStatus | PutAsciiString (const char *in_pszStr) |
Sets the
CString object with a null-terminated ASCII character string.
|
|
ULONG | Length () const |
Returns the number of characters in the
string. |
|
bool | IsEmpty () const |
Tests whether the string is empty. |
|
void | Clear () |
Clears the string's contents. |
|
CString & | operator= (const CString &in_rhs) |
Assignment operator. |
|
CString & | operator= (const wchar_t *in_rhs) |
Assignment operator The contents of the
string are duplicated. |
|
CString & | operator= (const char *in_rhs) |
Assignment operator The contents of the
string are duplicated. |
|
bool | operator== (const CString &in_refStr) const |
Equality operator. |
|
bool | operator== (const wchar_t *in_pwstr) const |
Equality operator. |
|
bool | operator== (const char *in_pstr) const |
Equality operator. |
|
bool | IsEqualNoCase (const CString &in_rhs) const |
Case-insensitive comparison. |
|
bool | IsEqualNoCase (const wchar_t *in_pwstr) const |
Case insensitive comparison. |
|
bool | IsEqualNoCase (const char *in_pstr) const |
Case insensitive comparison. |
|
CStringArray | Split (const CString &in_strDel) const |
Parses the string and returns the
sub-strings delimited by a given string. |
|
bool | operator!= (const CString &in_refStr) const |
Inequality operator. |
|
bool | operator!= (const wchar_t *in_pwstr) const |
Inequality operator. |
|
bool | operator!= (const char *in_pstr) const |
Inequality operator. |
|
CString & | operator+= (const CString &in_refStr) |
Concatenation operator. |
|
CString & | operator+= (const wchar_t *in_pwstr) |
Concatenation operator. |
|
CString & | operator+= (const char *in_pstr) |
Concatenation operator. |
|
CString & | operator+= (const wchar_t in_wchar) |
Concatenation operator. |
|
CString & | operator+= (const char in_char) |
Concatenation operator. |
|
CString | operator+ (const CString &in_refStr) const |
Addition operator. |
|
CString | operator+ (const wchar_t *in_pwstr) const |
Addition operator. |
|
CString | operator+ (const char *in_pstr) const |
Addition operator. |
|
CString | operator+ (const wchar_t in_wchar) const |
Addition operator. |
|
CString | operator+ (const char in_char) const |
Addition operator. |
|
wchar_t | operator[] (ULONG in_index) const |
Array element operator. |
|
char | GetAt (ULONG in_index) const |
Returns a single ASCII character contained
in the string at a given position. |
|
bool | operator< (const CString &in_str) const |
Less-than operator. |
|
bool | operator> (const CString &in_str) const |
Greater-than operator. |
|
ULONG | FindString (const CString &in_str, ULONG in_nOffset=0) const |
Searches this string instance in the forward
direction for the first occurrence of the specified string.
|
|
ULONG | ReverseFindString (const CString &in_str, ULONG in_nOffset=UINT_MAX) const |
Searches this string instance in the
backward direction for the first occurrence of the specified
string. |
|
CString | GetSubString (ULONG in_nOffset=0, ULONG in_nCount=UINT_MAX) const |
Returns a sub-string from this instance
beginning at a specified character position. |
|
void | Lower () |
Convert this string to a lower-case
character string. |
|
void | Upper () |
Convert this string to an upper-case
character string. |
virtual ~CString | ( | ) | [virtual] |
Default destructor.
CString | ( | const wchar_t * | in_str | ) |
CString | ( | const wchar_t * | in_str, |
ULONG | in_nCount | ||
) |
Constructs a
CString object by copying the first in_nCount
characters from a null-terminated wide character string.
in_str | constant wchar_t* reference pointer. |
in_nCount | Number of characters to copy from the in_str
argument starting from position 0. |
CString | ( | const char * | in_str | ) |
CString | ( | const char * | in_str, |
ULONG | in_nCount | ||
) |
Constructs a
CString object by copying the first in_nCount
characters from a null-terminated ascii character string.
in_str | constant char* reference pointer. |
in_nCount | Number of characters to copy from the in_str
argument starting from position 0. |
const wchar_t* GetWideString | ( | ) | const |
Accessor to a null-terminated, wide character representation of the string.
This buffer cannot be modified.
using namespace XSI; CString q( L"Data" ) ; // Get read-only access to the internal string buffer const wchar_t* l_pBuffer = q.GetWideString() ; // We can now call normal C runtime library string functions if ( 0==wcscmp( l_pBuffer, L"Data" ) ) { // As expected }
const char* GetAsciiString | ( | ) | const |
Accessor to a null-terminated, ASCII character representation of the string.
This buffer is temporary and cannot be modified. It should not be accessed after the content of the original CString object changes or is destroyed.
using namespace XSI; CString q( L"Data" ) ; // Get read-only access to the internal string buffer const char* l_pBuffer = q.GetAsciiString() ; // We can now call normal C runtime library string functions if ( 0==strcmp( l_pBuffer, "Data" ) ) { // As expected }
CStatus PutAsciiString | ( | const char * | in_pszStr | ) |
Sets the CString object with a null-terminated ASCII character string.
The contents of the specified string is duplicated inside the CString.
CString( const char* )
to create an ASCII-character
CString object or CString::operator
= (const char* )
to assign an ASCII string.in_pszStr | constant char* reference pointer. The string is set to an empty string if the input string is empty or NULL. |
using namespace XSI; CString q; q.PutAsciiString( "Data" ) ; // Get read-only access to the internal string buffer const char* l_pBuffer = q.GetAsciiString() ; // We can now call normal C runtime library string functions if ( 0==strcmp( l_pBuffer, "Data" ) ) { // As expected }
ULONG Length | ( | ) | const |
Returns the number of characters in the string.
Does not include the null-termination character. This is not the number of bytes required to hold a wide-character string because each character is 2 bytes long.
bool IsEmpty | ( | ) | const |
Tests whether the string is empty.
void Clear | ( | ) |
Clears the string's contents.
CString& operator= | ( | const wchar_t * | in_rhs | ) |
Assignment operator The contents of the string are duplicated.
This operation can change the type of this CString.
in_rhs | wide character string that we want to assign. |
CString& operator= | ( | const char * | in_rhs | ) |
Assignment operator The contents of the string are duplicated.
This operation can change the type of this CString.
in_rhs | ASCII character string that we want to assign. |
bool operator== | ( | const CString & | in_refStr | ) | const |
Equality operator.
Tests whether one string has the same contents as another.
in_refStr | CString with which we want to compare. |
bool operator== | ( | const wchar_t * | in_pwstr | ) | const |
Equality operator.
Tests whether the CString has the same contents as a wide character string.
in_pwstr | Pointer to a string with which we want to compare. |
bool operator== | ( | const char * | in_pstr | ) | const |
Equality operator.
Tests whether the CString has the same contents as an ASCII character string.
in_pstr | Pointer to a string with which we want to compare. |
bool IsEqualNoCase | ( | const CString & | in_rhs | ) | const |
Case-insensitive comparison.
in_rhs | CString with which we want to compare. |
bool IsEqualNoCase | ( | const wchar_t * | in_pwstr | ) | const |
Case insensitive comparison.
Tests whether one string has the same contents as another without regard to the case.
in_pwstr | Wide character string we want to compare. |
bool IsEqualNoCase | ( | const char * | in_pstr | ) | const |
Case insensitive comparison.
Tests whether this CString object has the same contents as an ASCII character string without regard to the case.
in_pstr | ASCII character string we want to compare. |
CStringArray Split | ( | const CString & | in_strDel | ) | const |
Parses the string and returns the sub-strings delimited by a given string.
If the delimiter is empty the space character is used. If the string is empty, the function returns an empty array.
in_strDel | String delimiter. |
bool operator!= | ( | const CString & | in_refStr | ) | const |
Inequality operator.
Tests whether two CStrings have different contents.
in_refStr | Pointer to a string with which we want to compare. |
bool operator!= | ( | const wchar_t * | in_pwstr | ) | const |
Inequality operator.
Tests whether a CString has different contents than a wide character string.
in_pwstr | Pointer to a string with which we want to compare. |
bool operator!= | ( | const char * | in_pstr | ) | const |
Inequality operator.
Tests whether a CString has different contents than an ASCII character string.
in_pstr | Pointer to a string with which we want to compare. |
CString& operator+= | ( | const wchar_t * | in_pwstr | ) |
Concatenation operator.
in_pwstr | Wide character string that we want to append. |
CString& operator+= | ( | const char * | in_pstr | ) |
Concatenation operator.
in_pstr | ASCII character string that we want to append. |
CString& operator+= | ( | const wchar_t | in_wchar | ) |
Concatenation operator.
in_wchar | concatenate a single character at the end. |
CString& operator+= | ( | const char | in_char | ) |
Concatenation operator.
in_char | concatenate a single ASCII character at the end. |
Addition operator.
in_refStr | string to add together with this string |
CString operator+ | ( | const wchar_t * | in_pwstr | ) | const |
Addition operator.
in_pwstr | wide character string to add together with this string |
CString operator+ | ( | const char * | in_pstr | ) | const |
Addition operator.
in_pstr | ASCII character string to add together with this string |
CString operator+ | ( | const wchar_t | in_wchar | ) | const |
Addition operator.
in_wchar | a single wide character to add together with this string |
CString operator+ | ( | const char | in_char | ) | const |
Addition operator.
in_char | a single ASCII character to add together with this string |
wchar_t operator[] | ( | ULONG | in_index | ) | const |
Array element operator.
Returns a single wide character contained in the string at a given position.
in_index | 0-based position in the array. |
char GetAt | ( | ULONG | in_index | ) | const |
Returns a single ASCII character contained in the string at a given position.
in_index | position in the 0-based array. |
bool operator< | ( | const CString & | in_str | ) | const |
bool operator> | ( | const CString & | in_str | ) | const |
ULONG FindString | ( | const CString & | in_str, |
ULONG | in_nOffset =
0 |
||
) | const |
Searches this string instance in the forward direction for the first occurrence of the specified string.
in_str | The string to look for. |
in_nOffset | Index of the position at which the search is to begin. The
default position is 0 . |
UINT_MAX
.CString str( "0123456789" ) ; // Returns 0 for an exact match ULONG npos = str.FindString( str ); // Returns 0 for an empty string npos = str.FindString( CString() ); // Returns 1 if "12" is found npos = str.FindString( CString("12") ); // Returns UINT_MAX if "777" is not found npos = str.FindString( CString("777") ); // Returns UINT_MAX if "12" is not found npos = str.FindString( CString("12"), str.Length() ); // Returns the specified search position (i.e. 10) for an empty string npos = str.FindString( CString(), 10 ); // Returns UINT_MAX if the specified search position exceeds the string size npos = str.FindString( CString("12"), str.Length()+1 );
ULONG ReverseFindString | ( | const CString & | in_str, |
ULONG | in_nOffset =
UINT_MAX |
||
) | const |
Searches this string instance in the backward direction for the first occurrence of the specified string.
in_str | The string to look for. |
in_nOffset | Index of the position at which the search is to begin. The
default position is UINT_MAX which is equivalent to
the position of the last character in this string. |
UINT_MAX
.CString str( "0123456789" ) ; // Returns 0 for an exact match ULONG npos = str.ReverseFindString( str ); // Returns str length (i.e. 10) for an empty string npos = str.ReverseFindString( CString() ); // Returns 1 if "12" is found npos = str.ReverseFindString( CString("12") ); // Returns UINT_MAX if "777" is not found npos = str.ReverseFindString( CString("777") ); // Returns UINT_MAX if "12" is not found npos = str.ReverseFindString( CString("12"), 0 ); // Returns str length if the specified search position exceeds the string size npos = str.ReverseFindString( CString("12"), str.Length()+10 );
CString GetSubString | ( | ULONG | in_nOffset = 0 , |
ULONG | in_nCount =
UINT_MAX |
||
) | const |
Returns a sub-string from this instance beginning at a specified character position.
If no arguments are passed, the function returns a copy of this CString.
in_nOffset | Index of the position at which the search is to begin. The
default position is 0 . This function returns an empty
string if the index position exceeds this CString size. |
in_nCount | The number of characters to copy. The default value is
UINT_MAX , which is equivalent to the number of
characters for this
CString. This parameter is set to UINT_MAX if the
value exceeds the number of characters for this CString. |
CString str( "0123456789" ) ; // Returns "0123456789" by default CString substr = str.GetSubString( ); // Returns "01234" substr = str.GetSubString( 0, 5 ); // Returns empty string if the search position exeeds the str length substr = str.GetSubString( str.Length() + 10, 5 ); // Returns "6789". str length is used as 2nd argument if the requested number of characters exeeds str length. substr = str.GetSubString( 7, str.Length() + 10 );
void Lower | ( | ) |
void Upper | ( | ) |