Topics
:Overview
Conditional Directives
Type Definitions
EnumerationsEnumerations
FunctionsFunctions
The vbString class is supplied with the VBSocket library to be used in place of null-terminated C strings. C/C++ does not have a built-in string data type, but provides library support for null-terminated character arrays. The null termination is used as a marker to signal that the end of the array has been reached. The character array format does not support binary strings since the null termination ('\0') is not a valid binary number. The vbString class is a user-defined string class used to create and manipulate non null-terminated resizable, variable-length strings of binary data. vbString objects are implemented as a concrete data type, just like the built-in data types: char, int, long, float, and double. The vbString class supports concatenation, find, fill, and sub-string creation and includes several routines useful in parsing operations.
The following conditional directives are use to define non-portable string routines that need to be ported between UNIX and WIN32 platforms.
__DOS__ - Directive used for all DOS compilers
__UNIX__ - Directive used for all UNIX compilers
__WIN32__ - Directive used for all WIN32 compilers
The "vbstring.h" is uses the following type definition to define the type used for the vbString class. By default the UString class is used:
typedef UString vbString;
This type definition allows you to substitute another string class for the UString class if needed.
enum { // UString enumerated constants UString::NoMatch = -1, // Value returned if a match is not found UString::DefSize = 16, // Default string size UString::DefInc = 16 // Default grow by increment size };
UString::UString()
UString::~UString()
UString::Cat()
UString::ChgGrowByInc()
UString::Copy()
UString::DeleteAfter()
UString::DeleteAfterIncluding()
UString::DeleteAfterLast()
UString::DeleteAfterLastIncluding()
UString::DeleteAt()
UString::DeleteBefore()
UString::DeleteBeforeIncluding()
UString::DeleteBeforeLast()
UString::DeleteBeforeLastIncluding()
UString::Fill()
UString::FilterChar()
UString::FilterString()
UString::Find()
UString::FindLast()
UString::FreeExtra()
UString::GetDimLen()
UString::GetLength()
UString::GetTextPtr()
UString::Grow()
UString::IFind()
UString::InsertAt()
UString::IsNull()
UString::Left()
UString::Mid()
UString::NullTermStr()
UString::ReplaceAt()
UString::ReplaceChar()
UString::ReplaceString()
UString::Resize()
UString::Right()
UString::SetLength()
UString::StrDup()
UString::ToLower()
UString::ToUpper()
UString::TrimLeadingSpaces()
UString::TrimTrailingSpaces()
UString::c_str()
UString::is_null()
UString::length()
UString::resize()
UString Overloaded Operators
UString::UString(unsigned Bytes = DefSize, int GB = DefInc)
- Class constructor used to allocate a specified number of bytes in memory for a string, with a specified grow by increment. The "DefSize" and "DefInc" integer constants are defined within the UString class by an anonymous enumeration. The "grow by" value is used to grow the string in specified increments. If "GB" is set to zero the string will not be allowed to grow.UString::UString(const char *s, int GB = DefInc)
- Class constructor used to allocate memory for a string and copy the string into memory. The number of bytes allocated depends on the length of the string. The "DefInc" integer constant is defined within the UString class by an anonymous enumeration. The "grow by" value is used to grow the string in specified increments. If "GB" is set to zero the string will not be allowed to grow.UString::UString(const char *s, unsigned Bytes, int GB = DefInc)
- Class constructor used to allocate a specified number of bytes for string "s" and copy string "s" into memory based on the number of bytes specified. The "DefInc" integer constant is defined within the UString class by an anonymous enumeration. The "grow by" value is used to grow the string in specified increments. If "GB" is set to zero the string will not be allowed to grow.UString::UString(const UString &s,unsigned Offset, unsigned Bytes, int GB = DefInc)
- Class constructor used to create a sub-string of string "s." The sub-string shares its data with "s", starting at the specified offset and allocating the specific number of bytes. The "DefInc" integer constant is defined within the UString class by an anonymous enumeration. The "grow by" value is used to grow the string in specified increments. If "GB" is set to zero the string will not be allowed to grow.UString::UString(const UString &s)
- Class copy constructor used to copy construct an object using share semantics. This copy constructor does not actually copy the string data. Instead the new string is bound to the same data that object "s" is bound to. - Class destructor responsible for unbinding the string from any shared text and deleting the text if necessary.void UString::Cat(const char *s, unsigned Bytes)
- Public member function used to concatenate a specified number of bytes from a null-terminated C string to the end of the object that invoked the call.void UString::Cat(const char *s)
- Public member function used to concatenate a null-terminated C string to the end of the object that invoked the call.void UString::ChgGrowByInc(int GB)
- Public member function used to change the default grow by increment to a specified size.void UString::Copy(const char *s)
- Public member function used to copy data from a null-terminated C string into this object.void UString::Copy(const UString &s)
- Public member function used to copy string data from object "s" into this object.int UString::DeleteAfter(const char *s)
- Public member function used to delete everything after the specified string. Returns true if successful.int UString::DeleteAfterIncluding(const char *s)
- Public member function used to delete everything after the specified string including the string itself. Returns true if successful.int UString::DeleteAfterLast(const char *s)
- Public member function used to delete everything after the last occurrence of the specified string. Returns true if the any characters were deleted.int UString::DeleteAfterLastIncluding(const char *s)
- Public member function used to delete everything after the last occurrence of the specified string including the string itself. Returns true if the any characters were deleted.unsigned UString::DeleteAt(unsigned Pos, unsigned Bytes)
- Public member function used to delete a specified number of bytes, starting at position Pos. Returns the number of bytes deleted.int UString::DeleteBefore(const char *s)
- Public member function used to delete everything before the specified string. Returns true if successful.int UString::DeleteBeforeIncluding(const char *s)
- Public member function used to delete everything before the specified string including the string itself. Returns true if successful.int UString::DeleteBeforeLast(const char *s)
- Public member function used to delete everything before the last occurrence of the specified string. Returns true if the any characters were deleted.int UString::DeleteBeforeLastIncluding(const char *s)
- Public member function used to delete everything before the last occurrence of the specified string including the string itself. Returns true if the any characters were deleted.void UString::Fill(const char *p, unsigned Bytes, unsigned Offset=0, unsigned Ln=0)
- Public member function used to fill in a specified number of bytes, with null-terminated C string "s", up to length "Ln", starting at the specified offset. If length "Ln" equals zero, the dimensioned length of this object is used instead of the logical length. This function will not cause this object to grow.void UString::Fill(const char c, unsigned Offset=0, unsigned Ln=0)
- Public member function used to fill in this object with a single character, up to length "Ln", starting at the specified offset. If length "Ln" equals zero, the dimensioned length of this object is used instead of the logical length. This function will not cause this object to grow.void UString::Fill(const char *s, unsigned Offset=0, unsigned Ln=0)
- Public member function used to fill in this object with a pattern of raw bytes, up to length "Ln", starting at the specified offset. If length "Ln" equals zero, the dimensioned length of this object is used instead of the logical length. This function will not cause this object to grow.void UString::Fill(const UString &s, unsigned Offset=0, unsigned Ln=0)
- Public member function used to fill in this object with a object "s", up to length "Ln", starting at the specified offset. If length "Ln" equals zero, the dimensioned length of this object is used instead of the logical length. This function will not cause this object to grow.unsigned UString::FilterChar(const char c, unsigned Offset = 0)
- Public member function used to filter the specified character from the object. Returns the number of characters filtered from the object.unsigned UString::FilterString(const char *s, unsigned Offset = 0)
- Public member function used to filter the specified string from the object. Returns the number of strings filtered from the object.unsigned UString::FilterString(char *s, unsigned Offset = 0)
- Public member function used to filter the specified string from the object. Returns the number of strings filtered from the object.unsigned UString::Find(char *s, unsigned Offset = 0)
- Public member function used to find an occurrence of pattern "s" in this object. The search starts at the specified offset that will default to zero. Returns the index of the first occurrence or Ustring::NoMatch if the string is not found.unsigned UString::Find(char *s, unsigned Bytes, unsigned Offset = 0)
- Public member function used to find an occurrence of a sequence of bytes, represented by a null-terminated C string, in this object. The search starts at the specified offset with will default to zero. Returns the index of the first occurrence or Ustring::NoMatch if the string is not found.unsigned UString::Find(const UString &s, unsigned Offset = 0)
- Public member function used to find an occurrence object "s" in this object. The search starts at the specified offset that will default to zero. Returns the index of the first occurrence or Ustring::NoMatch if the string is not found.unsigned UString::FindLast(const char *s)
- Public member function that returns the index of the last occurrence of string "s." Returns UString::NoMatch if the pattern not found.unsigned UString::FindLast(char *s)
- Public member function that returns the index of the last occurrence of string "s." Returns UString::NoMatch if the pattern not found. - Public member function used to shrink the bytes allocated for this object by reallocating the number bytes used. This function uses the actual length of the string and not the dimensioned length to shrink the string. - Public member function that returns the dimensioned length of this object's string. The dimensioned length refers to the total number of bytes that have been allocated in memory for this string and the logical length refers to the actual length of the string. - Public member function that returns the logical length of this object's string. The logical length refers to the actual length of the string and the dimensioned length refers to the total number of bytes that have been allocated in memory for this string. - Public member function that returns a pointer to the start of this object's string. - Public member function use to grow this object's string by the "grow by" value set when this object was constructed or the current grow by value.unsigned UString::IFind(char *s, unsigned Offset = 0)
- Public member function that returns the index of first occurrence of pattern "s" starting at specified offset using a case insensitive compare. Returns UString::NoMatch if the pattern not found.unsigned UString::IFind(char *s, unsigned Bytes, unsigned Offset = 0)
- Public member function that returns the index of first occurrence of pattern "s" starting at specified offset using a case insensitive compare. Returns UString::NoMatch if the pattern not found.unsigned UString::IFind(const UString &s, unsigned Offset = 0)
- Public member function that returns the index of first occurrence of object "s" starting at specified offset using a case insensitive compare. Returns UString::NoMatch if the pattern not found.unsigned UString::InsertAt(unsigned Pos, const char *s, unsigned Bytes)
- Public member function used to insert a specified number of bytes starting at position Pos, with string "s". Returns the number of bytes inserted.unsigned UString::InsertAt(unsigned Pos, const char *s)
- Public member function used to insert bytes starting at position Pos, with the null-terminated C string "s". The length of string "s" determines the number of bytes that will be inserted. Returns the number of bytes inserted.unsigned UString::InsertAt(unsigned Pos, const UString &s)
- Public member function used to insert bytes starting at position Pos, with the data pointed to by object "s". The length of object "s" determines the number of bytes that will be inserted. Returns the number of bytes inserted. - Public member function that returns true if this object's string is null.UString UString::Left(unsigned Ln)
- Public member function that returns the left sub-string of this object, of the specified length.UString UString::Mid(unsigned Index, unsigned Bytes)
- Public member function that returns a sub-string of this object, starting at the specified index, for a specified number of bytes.const char *UString::NullTermStr()
- Public member function used to make this object's string a null-terminated C string by making sure a null byte is inserted at the end of the string. If a null byte has to be added, the string is grown if necessary. If the string needs to grow but can't, the last character is replaced, and the logical length of the string shrinks.unsigned UString::ReplaceAt(unsigned Pos, const char *s, unsigned Bytes)
- Public member function used to replace a specified number of bytes, starting at position Pos, with string "s". Returns the number of bytes replaced.unsigned UString::ReplaceAt(unsigned Pos, const char *s)
- Public member function used to replace the bytes starting at position Pos, with the null-terminated C string "s". The length of string "s" determines the number of bytes that will be replaced. Returns the number of bytes replaced.unsigned UString::ReplaceAt(unsigned Pos, const UString &s)
- Public member function used to replace the bytes starting at position Pos, with the data pointed to by object "s". The length of object "s" determines the number of bytes that will be replaced. Returns the number of bytes replaced.unsigned UString::ReplaceChar(const char c, const char replacement,unsigned Offset = 0)
- Public member function used to replace every occurrence of the specified character starting at the specified offset. Returns the number of characters replaced in the string.unsigned UString::ReplaceString(const char *s, const char *replacement,unsigned Offset = 0)
- Public member function used to replace every occurrence of the specified string starting at the specified offset. Returns the number of strings replaced.unsigned UString::ReplaceString(char *s, char *replacement, unsigned Offset = 0)
- Public member function used to replace every occurrence of the specified string starting at the specified offset. Returns the number of strings replaced.int UString::Resize(unsigned Bytes)
- Public member function used to resize the number of bytes allocated for this object's string.UString UString::Right(unsigned Ln)
- Public member function that returns the right sub-string of this object, of the specified length.void UString::SetLength(unsigned Bytes)
- Public member function used to set the logical length of this object's string to a specified number of bytes. The maximum length of the string is its dimensioned length. - Public member function used to create a duplicate copy of this object. Returns a pointer to the newly constructed UString object or a null value if memory could not be allocated for the string data. - Public member function used to change all characters in the string to lower case. Returns true if successful. - Public member function used to change all characters in the string to upper case. Returns true if successful.unsigned UString::TrimLeadingSpaces()
- Public member function used to filter all leading spaces from a string. Returns the number of spaces filtered.unsigned UString::TrimTrailingSpaces()
- Public member function used to filter all trailing spaces from a string. Returns the number of spaces filtered. - Public member function that returns a null-terminated C string that represents this object string.int UString::is_null()
- Public member function that returns true if this object's string is null. - Public member function that returns the logical length of this object's string. The logical length refers to the actual length of the string and the dimensioned length refers to the total number of bytes that have been allocated in memory for this string. - Public member function Public member function that returns a pointer to the start of this object's string.int UString::resize(unsigned Bytes , int keep = 0)
- Public member function used to resize the logical length of this string object. If the "keep" variable is true the old data will be copied into the new space. By default the old data will be deleted. Returns false if the buffer's logical length cannot be changed. :void UString::operator+=(const UString &s)
- Overloaded member operator used to concatenate the string data of object "s" to the end of the object that invoked the call.void UString::operator+=(const char *s)
- Overloaded member operator used to concatenate a null-terminated C string to the end of the object that invoked the callvoid UString::operator+=(const char c)
- Overloaded member operator used to concatenate the a single character to the end of the object that invoked the callfriend ostream &operator<<(ostream &os, const UString &s)
- Overloaded operator used to convert a UString type into an ostream type.friend istream &operator>>(istream &os, UString &s)
- Overloaded operator used to convert a UString type into an istream type.friend UString operator+(const UString &a, const UString &b)
- Overloaded operator used to add two UString objects together.friend int operator==(const UString &a, const UString &b)
- Overloaded operator that returns true if its operands are equal to each other.friend int operator!=(const UString &a, const UString &b)
- Overloaded operator that returns true if its operands are not equal to each other.friend int operator>(const UString &a, const UString &b)
- Overloaded operator that returns true if its operand "a" is greater then "b."friend int operator>=(const UString &a, const UString &b)
- Overloaded operator that returns true if its operand "a" is greater then or equal to "b."friend int operator<(const UString &a, const UString &b)
- Overloaded operator that returns true if its operand "a" is less then "b."friend int operator<=(const UString &a, const UString &b)
- Overloaded operator that returns true if its operand "a" is less then or equal to "b."
End Of Document |