CkString C++ Class Reference (Visual C++)

CkString

* This is a freeware class/component/library.

Properties

bool get_Utf8(void) const;
void put_Utf8(bool b);

When set to true, all "const char *" arguments are expected to be utf-8 strings. If set to false, the "const char *" arguments are expected to be ANSI strings.

Methods

void append(const char * s);

The inStr is appended to this string (the caller).

void appendAnsi(const char * s);

Appends an ANSI string to the existing contents of the CkString object.

void appendChar(char c);

Appends a single ANSI character to the string.

void appendCurrentDateRfc822();

To be documented soon...

void appendEnc(const char * s, const char * encoding);

Appends a string in any character encoding to the existing contents of the CkString object. Examples of character encodings are: Shift_JIS, windows-1255, iso-8859-2, gb2312, etc.

void appendHexData(const unsigned char * data, int dataLen);

Convert the binary data to a hex string representation and append.

void appendInt(int n);

Appends an integer to the string.

void appendLastWindowsError();

For many Win32 SDK functions, such as CreateFile, error informationmust be retrieved by using the Win32 functions GetLastError and FormatMessage.This method calls these Win32 functions to format the error and append itto the string.

void appendN(const char * s, int numBytes);

Appends N characters to the string.

void appendNU(const wchar_t * unicode, int numChars);

Append N Unicode characters to a string.

void appendStr(const CkString & str);

Appends the contents of another CkString.

void appendU(const wchar_t * unicode);

Append a Unicode string to the CkString object.

void appendUtf8(const char * s);

Appends a UTF-8 string to the existing contents of the CkString object.

void base64Decode(const char * charset);

In-place base64 decodes the string and inteprets the results according to the character encoding specified.

void base64Encode(const char * charset);

In-place base64 encodes the string. Internally, the string is first converted to the character encoding specified and then base-64 encoded.

bool beginsWith(const char * sSubstr);

Returns 1 if the string begins with substr. Otherwise returns 0.

bool beginsWithStr(CkString & s);

Returns true if the string begins with the specified substring.

Returns true for success, false for failure.

char charAt(int idx);

Returns the ANSI character at a specified index.The first character is at index 0.

wchar_t charAtU(int idx);

Return the Nth character as a Unicode character.

void chopAtFirstChar(char c1);

Replace the first occurance of a specified ANSI character with a null terminator.

void chopAtStr(CkString & str);

Finds the first occurance of a substring and chops it at that point. The result is that the substring and all subsequent characters are removed from the string.

Returns true for success, false for failure.

void clear();

Clears the string. After calling this method, the string has 0 characters.

CkString * clone();

Creates a copy of the string.

Returns a null on failure

int compareStr(const CkString & str);

Compare two strings. A return value = 0 means they are equal. Return value = 1 indicates that calling object is less than argument. Return value = -1 indicates that calling object is greater than argument.

bool containsSubstring(const char * pattern);

Returns true if the string contains the specified substring. The substring may be a wildcarded pattern containing the '*' character which matches 0 or more of any character. The matching is case-sensitive.

bool containsSubstringNoCase(const char * pattern);

Same as containsSubstring except the matching is case insensitive.

int countCharOccurances(char ch);

To be documented soon.

void decodeXMLSpecial();

Decodes XML special characters.Example: < is converted to '<'

double doubleValue();

Return the string converted to a double.

void eliminateChar(char ansiChar, int startIndex);

Eliminate all occurances of a particular ANSI character.

void encodeXMLSpecial();

Encodes XML special characters.Example: '<' is converted to <

bool endsWith(const char * s);

Returns 1 if the string ends with subStr (case-sensitive). Otherwise returns 0.

bool endsWithStr(CkString & s);

Returns true if the string ends with the specified substring.

Returns true for success, false for failure.

void entityDecode();

Decodes any HTML entities found within the string, replacing them with the characters represented.

void entityEncode();

HTML encodes any characters that are special to HTML or cannot be represented by 7-bit us-ascii.

bool equals(const char * s);

Returns true if the strings are equal. (case-sensitive)

bool equalsIgnoreCase(const char * s);

Returns true if the strings are equal. (case-insensitive)

bool equalsIgnoreCaseStr(CkString & s);

Returns true if the strings are equal. (case-insensitive)

Returns true for success, false for failure.

bool equalsStr(CkString & s);

Returns true if the strings are equal. (case-sensitive)

Returns true for success, false for failure.

const char * getAnsi();

Return a pointer to the memory containing the string in the ANSI character encoding.

CkString * getChar(int idx);

Returns a new CkString object containing the Nth character. (Note, it does not contain the Nth byte, but the Nth character.) For languages such as Chinese, Japanese, etc. individual characters are represented by multiple or varying number of bytes.

Returns a null on failure

const char * getEnc(const char * encoding);

Returns the string converted to any multi-byte character encoding. Examples of character encodings include Shift_JIS, iso-8859-7, windows-1256, etc.

int getNumChars();

Returns the number of characters in the string.

int getSizeAnsi();

Returns the size, in bytes, of the ANSI representation of the string.

int getSizeUnicode();

Returns the size, in bytes, of the Unicode representation of the string.

int getSizeUtf8();

Returns the size, in bytes, of the utf-8 representation of the string.

const char * getString();

Returns a pointer to the memory containing the string. The caller should not delete this memory.

const wchar_t * getUnicode();

Return a pointer to memory containing the string in Unicode.

const char * getUtf8();

Return a pointer to memory containing the string in utf-8.

void hexDecode(const char * charset);

Hex decodes a string and inteprets the bytes according to the character encoding specified.

void hexEncode(const char * charset);

Converts the string to the character encoding specified and replaces the string contents with the hex encoding of the character data.

int indexOf(const char * s);

Returns the index of the first occurance of a substring. Returns -1 if not found.

int indexOfStr(CkString & s);

Returns the index of the first occurance of a substring. Returns -1 if not found.

Returns true for success, false for failure.

int intValue();

Returns the string converted to an integer value.

char lastChar();

Returns the last ANSI character in the string.

bool loadFile(const char * fileName, const char * charset);

Loads an entire text file into the string object. The character encoding of the text file is specified by charset. This method allows for text files in any charset to be loaded: utf-8, Unicode, Shift_JIS, iso-8859-1, etc.

bool matches(const char * s);

Returns 1 if the string matches the pattern, which may contain one or more asterisk wildcard characters. Case-sensitivity is controlled by , where 1 = case sensitive, 0 = case insensitive.

ASP String Patttern Matching

bool matchesStr(CkString & str);

Returns true if the string matches a pattern. The pattern may contain any number of wildcard '*' characters which represent 0 or more occurances of any character.

Returns true for success, false for failure.

void minimizeMemory();

To be documented soon...

void prepend(const char * s);

Prepends inStr to the string (i.e. to the caller).

void qpDecode(const char * charset);

Quoted-printable decodes the string and interprets the resulting character data according to the charset (character encoding) specified. The result is that the quoted-printable string is in-place decoded.

void qpEncode(const char * charset);

Quoted-printable encodes the string. The string is first converted to the charset specified, and those bytes are QP-encoded. The contents of the string are replaced with the QP-encoded result.

int removeAll(CkString & str);

Removes all occurances of a substring.

Returns true for success, false for failure.

void removeCharOccurances(char c);

Removes all occurances of a specific character from the string.

void removeChunk(int charStartPos, int numChars);

Removes a chunk of characters specified by starting index and length.

bool removeFirst(CkString & str);

Removes the first occurance of a substring.

Returns true for success, false for failure.

int replaceAll(CkString & str, CkString & replacement);

Replaces all occurances of substr with replacement. (case sensitive)

Returns true for success, false for failure.

int replaceAllOccurances(const char * pattern, const char * replacement);

Replaces all occurances of a substring with another substring. If the replacement substring can be empty or differ in length.

void replaceChar(char c1, char c2);

Replaces all occurances of a specified ANSI character with another.

bool replaceFirst(CkString & str, CkString & replacement);

Replaces the first occurance of substr with replacement. (case sensitive)

Returns true for success, false for failure.

bool replaceFirstOccurance(const char * pattern, const char * replacement);

Replaces the first occurance of a substring with another.

bool saveToFile(const char * filename, const char * charset);

Saves the string to a file, using the character encoding specified by charset. This method allows for the string to be saved using character encodings such as "utf-8", "Unicode", "Shift-JIS", or anything else...

void setStr(CkString & s);

Replaces the contents of the string with another.

Returns true for success, false for failure.

void setString(const char * s);

Same as clearing the string and appending.

void setStringAnsi(const char * s);

Set the CkString object from an ANSI string.

void setStringU(const wchar_t * unicode);

Set the CkString object from a Unicode string.

void setStringUtf8(const char * s);

Set the string object from a utf-8 string.

void shorten(int n);

Removes the final numChars from the string.

CkStringArray * split(char splitChar, bool exceptDoubleQuoted, bool exceptEscaped, bool keepEmpty);

Splits a string into an array of strings using a delimiter character. If "exceptEscaped" is true, then escaped (with a backslash) delimiter chars are ignored. If "exceptDoubleQuoted" is true, then delimiter chars inside quotes are ignored. If keepEmpty is false, then empty strings are excluded from the array.

CkStringArray * split2(const char * splitCharSet, bool exceptDoubleQuoted, bool exceptEscaped, bool keepEmpty);

Same as "split", except a set of characters can be used for delimiters.

CkStringArray * splitAtWS();

Equivalent to split2(" \t\r\n",true,true,false)

CkString * substring(int startCharIdx, int numChars);

Returns a substring specified by starting character position and number of characters.

Returns a null on failure

void toCRLF();

Make all end of lines a CRLF ("\r\n")

void toLF();

Make all end of lines a "\n"

void toLowerCase();

Converts the string to lowercase.

void toUpperCase();

Converts the string to uppercase.

CkStringArray * tokenize(char * punctuation);

Tokenizes a string. The string is split at whitespace characters, and any single punctuation character is returned as a separate token. For example, this string:
CkStringArray *CkString::tokenize(char *punctuation) const

is tokenized to

CkStringArray
*
CkString
:
:
tokenize
(
*
punctuation
)
const

void trim();

Trim SPACE and Tab characters from both ends of the string.

void trim2();

Trim SPACE, Tab, CR, and LF characters from both ends of the string.

void trimInsideSpaces();

Finds and replaces all SPACE chracter runs to single SPACE characters.

void urlDecode(const char * charset);

URL decodes the string and interprets the resulting byte data in the charset specified.

void urlEncode(const char * charset);

URL encodes the string. The string is first converted to the charset specified, and those bytes are URL-encoded. The contents of the string are replaced with the URL-encoded result.