Xbase64 4.0.1
C++ Library for handling Xbase (DBF) format type files
|
Class for handling string data. More...
#include <xbstring.h>
Public Member Functions | |
xbString (xbUInt32 size) | |
Constructor. More... | |
xbString (char c) | |
Constructor. More... | |
xbString (const char *s, xbUInt32 lMaxLen) | |
Constructor. More... | |
xbString (const xbString &s) | |
Constructor. More... | |
xbString (const char *="") | |
Constructor. More... | |
xbString (xbDouble d) | |
Constructor. More... | |
~xbString () | |
Destructor. More... | |
xbString & | operator= (const xbString &s) |
Set operator =. More... | |
xbString & | operator= (const char *s) |
Set operator =. More... | |
operator const char * () const | |
Operator const char *. More... | |
char & | operator[] (xbUInt32 n) const |
operator [] More... | |
char & | operator[] (xbInt32 n) const |
operator [] More... | |
xbString & | operator+= (const xbString &s) |
Append operator +=. More... | |
xbString & | operator+= (const char *s) |
Append operator +=. More... | |
xbString & | operator+= (char c) |
Append operator +=. More... | |
xbString & | operator-= (const xbString &s) |
Append operator -=. More... | |
xbString & | operator-= (const char *s) |
Append operator -=. More... | |
xbString & | operator-= (char c) |
Append operator -=. More... | |
xbBool | operator== (const xbString &) const |
operator == More... | |
xbBool | operator== (const char *) const |
operator == More... | |
xbBool | operator!= (const xbString &) const |
operator != More... | |
xbBool | operator!= (const char *) const |
operator != More... | |
xbBool | operator< (const xbString &) const |
operator < More... | |
xbBool | operator> (const xbString &) const |
operator > More... | |
xbBool | operator<= (const xbString &) const |
operator <= More... | |
xbBool | operator>= (const xbString &) const |
operator >= More... | |
xbString | operator- (const xbString &s) |
Concatonate operator -. More... | |
xbString | operator+ (const char *s) |
Concatonate operator +. More... | |
xbString | operator+ (const xbString &s) |
Concatonate operator +. More... | |
xbString | operator+ (const char c) |
Concatonate operator +. More... | |
xbString & | AddBackSlash (char c) |
Add a prefixing back slash to specified characters in the string. More... | |
xbString & | Append (const xbString &s) |
Append data to string. More... | |
xbString & | Append (const char *s) |
Append data to string. More... | |
xbString & | Append (const char *s, xbUInt32 iByteCount) |
Append data to string. More... | |
xbString & | Append (char c) |
Append data to string. More... | |
xbString & | Assign (const char *srcStr, xbUInt32 lStartPos, xbUInt32 lCopyLen) |
Assign portion of string. More... | |
xbString & | Assign (const char *srcStr, xbUInt32 lStartPos) |
Assign portion of string. More... | |
xbString & | Assign (const xbString &s, xbUInt32 pos, xbUInt32 lCopyLen) |
Assign portion of string. More... | |
xbString & | Assign (const xbString &s, xbUInt32 lCopyLen) |
Assign portion of string. More... | |
xbString | Copy () const |
Copy a string. More... | |
xbUInt32 | CountChar (char c) const |
Count the number of characters in the string. More... | |
xbUInt32 | CountChar (char c, xbInt16 iOpt) const |
Count the number of characters in the string. More... | |
xbInt16 | CvtHexChar (char &cOut) |
Convert hex character to string. More... | |
xbInt16 | CvtHexString (xbString &sOut) |
Convert string of hex characters to string. More... | |
xbInt16 | CvtULongLong (xbUInt64 &ullOut) |
Convert string to xbUInt64 number. More... | |
xbInt16 | CvtLongLong (xbInt64 &llOut) |
Convert string to xbInt64 number. More... | |
xbString & | ExtractElement (const char *src, char delim, xbUInt32 iCnt, xbInt16 iOpt=0) |
Extract an element out of a delimited string. More... | |
char | GetCharacter (xbUInt32 lPos) const |
Get a character by position. More... | |
xbUInt32 | GetLastPos (char c) const |
Get the position of the last occurrence of a given character. More... | |
xbUInt32 | GetLastPos (const char *s) const |
Get the position of the last occurrence of a given string. More... | |
char | GetPathSeparator () const |
Get the path separator out of the string. More... | |
xbUInt32 | GetSize () const |
Retrieve the size of the string buffer. More... | |
xbBool | HasAlphaChars () const |
Determine if the string has any alpha characters. More... | |
xbBool | IsEmpty () const |
Determine if string is empty. More... | |
xbBool | IsNull () const |
Determine if string is NULL. More... | |
xbString & | Left (xbUInt32 ulLen) |
Retain left part of string, drop rightmost characters. More... | |
xbUInt32 | Len () const |
Retrieve length of current string. More... | |
xbString & | Ltrim () |
Left trim white space from string. More... | |
xbString & | Ltrunc (xbUInt32 ulCnt) |
Left truncate string. More... | |
xbString & | Mid (xbUInt32 ulPos, xbUInt32 lLen) |
Extract portion of data from string. More... | |
xbString & | PadLeft (char c, xbUInt32 ulLen) |
Left pad string. More... | |
xbString & | PadRight (char c, xbUInt32 ulLen) |
Right pad string. More... | |
xbUInt32 | Pos (char c, xbUInt32 ulStartPos) const |
Determine position of a given character. More... | |
xbUInt32 | Pos (char c) const |
Determine position of a given character. More... | |
xbUInt32 | Pos (const char *s) const |
Determine position of a given substring. More... | |
xbString & | PutAt (xbUInt32 ulPos, char c) |
Insert character into string. More... | |
xbString & | Remove (xbUInt32 ulPos, xbUInt32 ulN) |
Remove portion of string. More... | |
xbString & | Replace (const char *sReplace, const char *sReplaceWith, xbInt16 iOpt=0) |
Replace a value within a string with another value. More... | |
xbString & | Resize (xbUInt32 lSize) |
Resize a string. More... | |
xbString & | Rtrim () |
Right trim the string. More... | |
xbString & | Set (const char *s) |
Set the value of the string. More... | |
xbString & | Set (const xbString &s) |
Set the value of the string. More... | |
xbString & | Set (const char *s, xbUInt32 ulSize) |
Set the value of the string. More... | |
xbString & | SetNum (xbInt32 lNum) |
Set the string to long integer numeric value. More... | |
xbString & | Sprintf (const char *format,...) |
Printf routine for formatting a string. More... | |
const char * | Str () const |
Return string data. More... | |
char * | strncpy (char *cDest, xbUInt32 n) const |
Copy all or part of string to character array. More... | |
xbString & | SwapChars (char from, char to) |
Swap characters. More... | |
xbString & | ToLowerCase () |
Replace all upper case charaters with lower case characters. More... | |
xbString & | ToUpperCase () |
Replace all lower case charaters with lower case characters. More... | |
xbString & | Trim () |
Trim all leading and trailing white space from string. More... | |
xbBool | ValidLogicalValue () const |
Check for valid logical field data. More... | |
xbBool | ValidNumericValue () const |
This function returns true if the data is valid numeric data. More... | |
xbString & | ZapChar (char c) |
Remove every instance of a character from a string. More... | |
xbString & | ZapLeadingChar (char c) |
Remove leading character from a string. More... | |
xbString & | ZapTrailingChar (char c) |
Remove trailing character from a string. More... | |
Friends | |
std::ostream & | operator<< (std::ostream &os, const xbString &s) |
Stream insertion operator <<. More... | |
Class for handling string data.
This class defines a basic string class with all the functions one would expect in a string class.
For purposes of the xbString class, a string is defined as a variable sized array of one byte characters terminated with a null (0x00 or \0) byte.
This version of the xbString class does not support wide (wchar_t) characters. Perhaps you would be interested in creating a class for supporting wide characters.
This string class handle strings in a 1-based (not 0 based) fashion. Any string routines taking an offset use a 1-based value. That is, the first position of the string is position 1, not 0.
Position 1 (not 0) is considered the first position in a string.
A return of 0 would indicate a not found condition. A return of 1, would be the first byte.
xb::xbString::xbString | ( | xbUInt32 | ulSize | ) |
Constructor.
ulSize | - Allocation size. The allocation size is normally handled internally by the class, but it can be set in this constructor. |
xb::xbString::xbString | ( | char | c | ) |
Constructor.
c | - Initialize string to c. |
xb::xbString::xbString | ( | const char * | s, |
xbUInt32 | ulMaxLen | ||
) |
Constructor.
s | Initialize string to s. |
ulMaxLen | Maximum length of string. Truncate any characters greater than ulMaxLen. |
xb::xbString::xbString | ( | const xbString & | s | ) |
Constructor.
s | Initialize string to s. |
xb::xbString::xbString | ( | const char * | s = "" | ) |
Constructor.
s | - Initialize string to s. |
xb::xbString::xbString | ( | xbDouble | d | ) |
Constructor.
d | - Initiailize string to d. |
xb::xbString::~xbString | ( | ) |
Destructor.
xbString & xb::xbString::AddBackSlash | ( | char | c | ) |
Add a prefixing back slash to specified characters in the string.
c | Character to prefix with a backslash. |
xbString & xb::xbString::Append | ( | char | c | ) |
Append data to string.
c | String data to append. |
xbString & xb::xbString::Append | ( | const char * | s | ) |
Append data to string.
s | String data to append. |
xbString & xb::xbString::Append | ( | const char * | s, |
xbUInt32 | ulByteCount | ||
) |
Append data to string.
s | String data to append. |
ulByteCount | Maximum number of bytes to append. |
Append data to string.
s | String data to append. |
xbString & xb::xbString::Assign | ( | const char * | sStr, |
xbUInt32 | ulStartPos | ||
) |
Assign portion of string.
sStr | - Source string for copy operation. sStr needs to be a Null terminated string. |
ulStartPos | - Starting position within source string. |
xbString & xb::xbString::Assign | ( | const char * | sStr, |
xbUInt32 | ulStartPos, | ||
xbUInt32 | ulCopyLen | ||
) |
Assign portion of string.
sStr | - Source string for copy operation. sStr needs to be a Null terminated string. |
ulStartPos | - Starting position within source string. |
ulCopyLen | - Length of data to copy. |
Assign portion of string.
sStr | - Source string for copy operation. sStr needs to be a Null terminated string. |
ulStartPos | - Starting position within source string. |
Assign portion of string.
sStr | - Source string for copy operation. sStr needs to be a Null terminated string. |
ulStartPos | - Starting position within source string. |
ulCopyLen | - Length of data to copy. |
xbUInt32 xb::xbString::CountChar | ( | char | c | ) | const |
Count the number of characters in the string.
c | Character to count. |
xbUInt32 xb::xbString::CountChar | ( | char | c, |
xbInt16 | iOpt | ||
) | const |
Count the number of characters in the string.
c | Character to count. |
iOpt | 0 - Count the number of characters. 1 - Count the number of characters not between single or double quotes. |
xbInt16 xb::xbString::CvtHexChar | ( | char & | cOut | ) |
Convert hex character to string.
This routine converts a four byte string in the format of 0x00 to a one byte char value. The first four bytes of the string must be in the format 0x00. Anything past the first four bytes is disregarded.
cOut | Output character. |
xbInt16 xb::xbString::CvtHexString | ( | xbString & | sOut | ) |
Convert string of hex characters to string.
This routine converts a string of four byte format of 0x00 to a string of one byte chars.
sOut | Output string of converted characters. |
xbInt16 xb::xbString::CvtLongLong | ( | xbInt64 & | llOut | ) |
Convert string to xbInt64 number.
llOut | - output long long. |
xbInt16 xb::xbString::CvtULongLong | ( | xbUInt64 & | ullOut | ) |
Convert string to xbUInt64 number.
ullOut | - output unsigned long long. |
xbString & xb::xbString::ExtractElement | ( | const char * | pSrc, |
char | cDelim, | ||
xbUInt32 | lSkipCnt, | ||
xbInt16 | iOpt = 0 |
||
) |
Extract an element out of a delimited string.
pSrc | Source string. |
cDelim | Delimiter. |
lSkipCnt | Number of delimiters to skip. |
iOpt | 0 - ignore single and double quotes. 1 - ignore delimiters between single or double quotes. |
char xb::xbString::GetCharacter | ( | xbUInt32 | n | ) | const |
Get a character by position.
n | - Position in string to extract. First position is 1 (not 0). |
xbUInt32 xb::xbString::GetLastPos | ( | char | c | ) | const |
Get the position of the last occurrence of a given character.
c | - Character to search for. |
xbUInt32 xb::xbString::GetLastPos | ( | const char * | s | ) | const |
Get the position of the last occurrence of a given string.
s | - String to search for. |
char xb::xbString::GetPathSeparator | ( | ) | const |
Get the path separator out of the string.
xbUInt32 xb::xbString::GetSize | ( | ) | const |
Retrieve the size of the string buffer.
xbBool xb::xbString::HasAlphaChars | ( | ) | const |
Determine if the string has any alpha characters.
xbBool xb::xbString::IsEmpty | ( | ) | const |
Determine if string is empty.
xbBool xb::xbString::IsNull | ( | ) | const |
Determine if string is NULL.
xbString & xb::xbString::Left | ( | xbUInt32 | ulLen | ) |
Retain left part of string, drop rightmost characters.
ulLen | New string length, truncate rightmost excess. |
xbUInt32 xb::xbString::Len | ( | ) | const |
Retrieve length of current string.
xbString & xb::xbString::Ltrim | ( | ) |
Left trim white space from string.
xbString & xb::xbString::Ltrunc | ( | xbUInt32 | ulCnt | ) |
Left truncate string.
ulCnt | Number of bytes to remove from the left. |
xbString & xb::xbString::Mid | ( | xbUInt32 | ulStartPos, |
xbUInt32 | ulTargLen | ||
) |
Extract portion of data from string.
ulStartPos | Starting position |
ulTargLen | Length |
xb::xbString::operator const char * | ( | ) | const |
Operator const char *.
xbBool xb::xbString::operator!= | ( | const char * | s | ) | const |
operator !=
s | String to compare |
operator !=
s | String to compare |
xbString xb::xbString::operator+ | ( | const char * | s1 | ) |
Concatonate operator +.
Concatonate left string with right string returning reference to new string.
s1 | Right string operator. |
xbString xb::xbString::operator+ | ( | const char | c | ) |
Concatonate operator +.
Concatonate left string with right string returning reference to new string.
c | Right string operator. |
Concatonate operator +.
Concatonate left string with right string returning reference to new string.
s1 | Right string operator. |
xbString & xb::xbString::operator+= | ( | char | c | ) |
Append operator +=.
c | - Append c to the string. |
xbString & xb::xbString::operator+= | ( | const char * | s | ) |
Append operator +=.
s | - Append s to the string. |
Append operator +=.
s | - Append s to the string. |
Concatonate operator -.
Concatonate left string with right string returning reference to new string. Both strings are trimmed.
s1 | Right string operator. |
xbString & xb::xbString::operator-= | ( | char | c | ) |
Append operator -=.
Append c to the right of this string, trimming right space on this string first.
c | - Append s to the right of the string value. |
xbString & xb::xbString::operator-= | ( | const char * | s | ) |
Append operator -=.
Append s to the right of this string, right trimming both strings.
s | - Append s to the right of the string value. |
Append operator -=.
Append s to the right of this string, right trimming both strings.
s | - Append s to the right of the string value. |
operator <
s | String to compare |
operator <=
s | String to compare |
xbString & xb::xbString::operator= | ( | const char * | s | ) |
Set operator =.
s | - Set the string to the string on the right of the equal sign. |
Set operator =.
s | - Set the string to the string on the right of the equal sign. |
xbBool xb::xbString::operator== | ( | const char * | s | ) | const |
operator ==
s | String to compare |
operator ==
s | String to compare |
operator >
s | String to compare |
operator >=
s | String to compare |
char & xb::xbString::operator[] | ( | xbInt32 | n | ) | const |
operator []
n | - Offset into the string of the byte to retrieve. |
char & xb::xbString::operator[] | ( | xbUInt32 | n | ) | const |
operator []
n | - Offset into the string of the byte to retrieve. |
xbString & xb::xbString::PadLeft | ( | char | c, |
xbUInt32 | ulNewLen | ||
) |
Left pad string.
c | Padding character. |
ulNewLen | New string length. |
xbString & xb::xbString::PadRight | ( | char | c, |
xbUInt32 | ulNewLen | ||
) |
Right pad string.
c | Padding character. |
ulNewLen | New string length. |
xbUInt32 xb::xbString::Pos | ( | char | c | ) | const |
Determine position of a given character.
c | Seek character |
xbUInt32 xb::xbString::Pos | ( | char | c, |
xbUInt32 | ulStartPos | ||
) | const |
Determine position of a given character.
c | Seek character |
ulStartPos | starting position for search, first position is 1 |
xbUInt32 xb::xbString::Pos | ( | const char * | s | ) | const |
Determine position of a given substring.
s | Substring |
xbString & xb::xbString::PutAt | ( | xbUInt32 | ulPos, |
char | c | ||
) |
Insert character into string.
ulPos | Insertion position. |
c | Character to insert. |
xbString & xb::xbString::Remove | ( | xbUInt32 | ulStartPos, |
xbUInt32 | ulDelSize | ||
) |
Remove portion of string.
ulStartPos | Starting position for removal operation. |
ulDelSize | Size of deletion. |
xbString & xb::xbString::Replace | ( | const char * | sReplace, |
const char * | sReplaceWith, | ||
xbInt16 | iOption = 0 |
||
) |
Replace a value within a string with another value.
sReplace | - Character string to replace. |
sReplaceWith | - Character string to replace with |
iOption | - 0 = All occurrences, 1 = first occurrence |
xbString & xb::xbString::Resize | ( | xbUInt32 | ulSize | ) |
Resize a string.
ulSize | - New string size, including null termination byte. |
xbString & xb::xbString::Rtrim | ( | ) |
Right trim the string.
This routine removes any trailing white space on the string.
xbString & xb::xbString::Set | ( | const char * | s | ) |
Set the value of the string.
Note: This routine fails if you try to set the string to itself or some part of itself.
s | Value to set the string. |
xbString & xb::xbString::Set | ( | const char * | s, |
xbUInt32 | ulSize | ||
) |
Set the value of the string.
Note: This routine fails if you try to set the string to itself or some part of itself.
s | Value to set the string. |
ulSize | Maximum size of resultant string. |
Set the value of the string.
s | Value to set the string. |
xbString & xb::xbString::SetNum | ( | xbInt32 | lNum | ) |
Set the string to long integer numeric value.
lNum | Value to set the string |
xbString & xb::xbString::Sprintf | ( | const char * | sFormat, |
... | |||
) |
Printf routine for formatting a string.
See documentation on the standard C printf function for how to use this.
MyString.Sprintf( "a number %d some text %s", 100, "test text data" );
sFormat | A format specifier |
const char * xb::xbString::Str | ( | ) | const |
Return string data.
char * xb::xbString::strncpy | ( | char * | cDest, |
xbUInt32 | n | ||
) | const |
Copy all or part of string to character array.
cDest | pointer to destination buffer. |
n | Number of bytest to copy. It is the responsibility of the application to verify the buffer is large enough to hold the string contents. |
xbString & xb::xbString::SwapChars | ( | char | cFrom, |
char | cTo | ||
) |
Swap characters.
cFrom | character to replace. |
cTo | character to replace with. |
xbString & xb::xbString::ToLowerCase | ( | ) |
Replace all upper case charaters with lower case characters.
xbString & xb::xbString::ToUpperCase | ( | ) |
Replace all lower case charaters with lower case characters.
xbString & xb::xbString::Trim | ( | ) |
Trim all leading and trailing white space from string.
xbBool xb::xbString::ValidLogicalValue | ( | ) | const |
Check for valid logical field data.
Valid logical data is one 'T', 'F', 'N' or 'Y'.
xbBool xb::xbString::ValidNumericValue | ( | ) | const |
This function returns true if the data is valid numeric data.
xbString & xb::xbString::ZapChar | ( | char | c | ) |
Remove every instance of a character from a string.
c | character to remove from string. |
xbString & xb::xbString::ZapLeadingChar | ( | char | c | ) |
Remove leading character from a string.
c | character to remove from beginning of string. |
xbString & xb::xbString::ZapTrailingChar | ( | char | c | ) |
Remove trailing character from a string.
c | character to remove from ending of string. |
|
friend |
Stream insertion operator <<.
std::cout << MyString << std::endl;
os | Output stream |
s | String to send to output stream |