Loading...
Searching...
No Matches
String Class Reference

## Public Member Functions

| String (int startsize=0)
| String (const char *s)
| String (const String &s)
| String (char ch, int count=1)
String & | Clear ()
String & | Copy (const String &s)
String & | Copy (const String &s, int start, int count)
String & | Copy (const char *s)
bool | IsEmpty () const
String & | ToUpper ()
String & | ToLower ()
String | AsUpper ()
String | AsLower ()
String | Capitalize ()
String & | Reverse ()
String & | LeftClip (int clipAmount)
String & | RightClip (int clipAmount)
String & | operator= (char ch)
String | operator+ (char ch) const
String & | operator+= (char ch)
String & | operator= (const String &rhs)
String | operator+ (const String &rhs) const
String & | operator+= (const String &rhs)
String & | operator= (const char *rhs)
String | operator+ (const char *rhs) const
String & | operator+= (const char *rhs)
String & | operator= (int rhs)
String | operator+ (int rhs) const
String & | operator+= (int rhs)
String & | operator= (double rhs)
String | operator+ (double rhs) const
String & | operator+= (double rhs)
void | appendFullFloat (float rhs)
String & | operator= (unsigned int rhs)
String | operator+ (unsigned int rhs) const
String & | operator+= (unsigned int rhs)
String | operator* (unsigned int rhs) const
String & | operator*= (unsigned int rhs)
int | Compare (const String &rhs) const
int | FastCompare (const String &rhs) const
int | SlowCompare (const String &rhs) const
int | Compare (const char *rhs) const
int | FastCompare (const char *rhs) const
int | SlowCompare (const char *rhs) const
int | CompareToStem (const String &stem) const
int | FastCompareToStem (const String &stem) const
int | SlowCompareToStem (const String &stem) const
int | CompareToStem (const char *stem) const
int | FastCompareToStem (const char *stem) const
int | SlowCompareToStem (const char *stem) const
int | MatchesBeginningOf (const String &stem) const
int | FastMatchesBeginningOf (const String &stem) const
int | SlowMatchesBeginningOf (const String &stem) const
int | MatchesBeginningOf (const char *stem) const
int | FastMatchesBeginningOf (const char *stem) const
int | SlowMatchesBeginningOf (const char *stem) const
int | operator== (const String &rhs) const
int | operator!= (const String &rhs) const
int | operator< (const String &rhs) const
int | operator> (const String &rhs) const
int | operator>= (const String &rhs) const
int | operator<= (const String &rhs) const
int | operator== (const char *rhs) const
int | operator!= (const char *rhs) const
int | operator< (const char *rhs) const
int | operator> (const char *rhs) const
int | operator<= (const char *rhs) const
int | operator>= (const char *rhs) const
| operator const char * () const
const char * | c_str () const
| operator char * ()
| operator int () const
| operator double () const
| operator long double () const
char | operator[] (int i) const
char & | operator[] (int i)
char & | Last ()
char & | First ()
void | Grow (int newSize)
void | Swap (String &s)
char * | LockBuffer (int size=-1)
String & | UnlockBuffer ()
String & | Read ()
int | ReadLine ()
void | WriteLine ()
void | Write ()
String & | Read (FILE *f)
int | ReadLine (FILE *f)
void | WriteLine (FILE *f)
void | Write (FILE *f)
String & | Read (IFILE &f)
int | ReadLine (IFILE &f)
String | Left (int count) const
String | Right (int count) const
String | Mid (int start, int end) const
String | SubStr (int start, int count) const
String | SubStr (int start) const
int | FindChar (char ch, int start=0) const
int | FastFindChar (char ch, int start=0) const
int | SlowFindChar (char ch, int start=0) const
int | FindLastChar (char ch) const
int | FastFindLastChar (char ch) const
int | SlowFindLastChar (char ch) const
int | Find (char ch, int start=0) const
int | Find (const String &str, int start=0) const
int | FastFind (const String &str, int start=0) const
int | SlowFind (const String &str, int start=0) const
String & | Filter (const String &s)
String & | Filter (const char *s)
String & | ExcludeCharacters (const String &s)
String & | ExcludeCharacters (const char *s)
int | Length () const
int | BufferSize () const
int | SetLength (int newlen)
int | Dimension (int newlen)
String & | Add (const String &s)
String & | Add (char ch)
String | RightToLeft ()
String & | Invert ()
String & | Invert (const String &s)
String & | Trim ()
String & | Trim (char character)
vector< String > * | Split (char splitChar)
long | AsInteger () const
bool | AsInteger (long &intValue) const
bool | AsInteger (int &intValue) const
double | AsDouble () const
long double | AsLongDouble () const
int | printf (const char *format,...)
int | vprintf (const char *format, va_list arglist)
int | catprintf (const char *format,...)
int | vcatprintf (const char *format, va_list arglist)
bool | IsNumber ()
const unsigned char * | uchar () const
const signed char * | schar () const
void | Fill (char ch, int length=-1)

## Static Public Member Functions

static int | my_snprintf (char *buffer, int bufsize, const char *format,...)
static int | my_vsnprintf (char *buffer, int bufsize, const char *format, va_list args)
static void | my_vsnprintf_close_file ()
static void | check_vsnprintf ()

## Static Public Attributes

static int | alloc = 8
static bool | caseSensitive = true
static FILE * | my_vsnprintf_file = NULL

## Protected Attributes

char * | buffer
int | len
int | size

## Detailed Description

Definition at line 38 of file StringBasics.h.

## Constructor & Destructor Documentation

## String() [1/4]

String::String | ( | int | startsize = 0 | ) |

inline explicit

Definition at line 51 of file StringBasics.h.

{
NewString(startsize);
}

## String() [2/4]

String::String | ( | const char * | s | ) |

Definition at line 54 of file StringBasics.cpp.

{
int clen = s == NULL ? 0 : strlen(s);
NewString(clen);
if (clen)
{
len = clen;
memcpy(buffer, s, len + 1);
}
}

## String() [3/4]

String::String | ( | const String & | s | ) |

Definition at line 73 of file StringBasics.cpp.

{
len = s.len;
size = (s.len + alloc) / alloc * alloc;;
buffer = new char [size];
memcpy(buffer, s.buffer, len + 1);
}

## String() [4/4]

String::String | ( | char | ch,
|  | int | count = 1 )

explicit

Definition at line 65 of file StringBasics.cpp.

{
NewString(count);
memset(buffer, ch, count);
buffer[count] = 0;
len = count;
}

## ~String()

String::~String | ( |  | ) |

inline

Definition at line 59 of file StringBasics.h.

{
if(buffer != NULL)
delete [] buffer;
}

## Member Function Documentation

## Add() [1/2]

String & String::Add | ( | char | ch | ) |

inline

Definition at line 306 of file StringBasics.h.

{
return *this += ch;
}

## Add() [2/2]

String & String::Add | ( | const String & | s | ) |

inline

Definition at line 302 of file StringBasics.h.

{
return *this += s;
}

## appendFullFloat()

void String::appendFullFloat | ( | float | rhs | ) |

Definition at line 383 of file StringBasics.cpp.

{
std::ostringstream os;
os << rhs;
*this += os.str().c_str();
}

## AsDouble()

double String::AsDouble | ( |  | ) | const

inline

Definition at line 322 of file StringBasics.h.

{
return (double) *this;
}

## AsInteger() [1/3]

long String::AsInteger | ( |  | ) | const

Definition at line 1002 of file StringBasics.cpp.

{
long returnValue = 0;
if(!AsInteger(returnValue))
{
// This is not an integer, but nothing to do but return a value.
}
return(returnValue);
}

## AsInteger() [2/3]

bool String::AsInteger | ( | int & | intValue | ) | const

Definition at line 1073 of file StringBasics.cpp.

{
int integer = 0;
int base = 10;
int pos = 0;
int sign = 1;
bool isInt = true;
// If this is no value for this integer, return false.
if (pos == len)
{
return(false);
}
if (buffer[pos] == '-')
{
sign = -1, pos++;
}
if ((len > pos + 2) && (buffer[pos] == '0') &&
((buffer[pos+1] == 'x') || (buffer[pos+1] == 'X')))
{
base = 16, pos += 2;
}
// If this is no value for this integer, return false.
if (pos == len)
{
return(false);
}
for (; pos < len; pos++)
{
char digit = (char) toupper(buffer[pos]);
if (digit >= '0' && digit <= '9')
{
integer = integer * base + digit - '0';
}
else if (digit >= 'A' && digit <= 'F' && base == 16)
{
integer = integer * base + digit - 'A' + 10;
}
else
{
isInt = false;
break;
}
}
intValue = sign*integer;
return(isInt);
}

## AsInteger() [3/3]

bool String::AsInteger | ( | long & | intValue | ) | const

Definition at line 1015 of file StringBasics.cpp.

{
long integer = 0;
int base = 10;
int pos = 0;
int sign = 1;
bool isInt = true;
// If this is no value for this integer, return false.
if (pos == len)
{
return(false);
}
if (buffer[pos] == '-')
{
sign = -1, pos++;
}
if ((len > pos + 2) && (buffer[pos] == '0') &&
((buffer[pos+1] == 'x') || (buffer[pos+1] == 'X')))
{
base = 16, pos += 2;
}
// If this is no value for this integer, return false.
if (pos == len)
{
return(false);
}
for (; pos < len; pos++)
{
char digit = (char) toupper(buffer[pos]);
if (digit >= '0' && digit <= '9')
{
integer = integer * base + digit - '0';
}
else if (digit >= 'A' && digit <= 'F' && base == 16)
{
integer = integer * base + digit - 'A' + 10;
}
else
{
isInt = false;
break;
}
}
intValue = sign*integer;
return(isInt);
}

## AsLongDouble()

long double String::AsLongDouble | ( |  | ) | const

inline

Definition at line 326 of file StringBasics.h.

{
return (long double) *this;
}

## AsLower()

String String::AsLower | ( |  | ) |

Definition at line 175 of file StringBasics.cpp.

{
String temp;
temp = *this;
return temp.ToLower();
}

## AsUpper()

String String::AsUpper | ( |  | ) |

Definition at line 168 of file StringBasics.cpp.

{
String temp;
temp = *this;
return temp.ToUpper();
}

## BufferSize()

int String::BufferSize | ( |  | ) | const

inline

Definition at line 291 of file StringBasics.h.

{
return size;
}

## c_str()

const char * String::c_str | ( |  | ) | const

inline

Definition at line 195 of file StringBasics.h.

{
return (const char *) buffer;
}

## Capitalize()

String String::Capitalize | ( |  | ) |

Definition at line 182 of file StringBasics.cpp.

{
String temp;
temp = *this;
temp.buffer[0] = (char) toupper(temp.buffer[0]);
return temp;
}

## catprintf()

int String::catprintf | ( | const char * | format,
|  |  | ... )

Definition at line 1346 of file StringBasics.cpp.

{
va_list ap;
va_start(ap, format);
vcatprintf(format, ap);
va_end(ap);
return len;
}

## check_vsnprintf()

void String::check_vsnprintf | ( |  | ) |

static

Definition at line 1391 of file StringBasics.cpp.

{
if (vsnprintfChecked == VSNPRINTF_NOT_CHECKED)
{
char temp[100];
memset(temp, 0, 100);
int check = snprintf(temp, 5, "%5s", "VSNPRINTF");
if (temp[6] != 0 || temp[7] != 0 || (check != 9 && check != -1))
/*
error("This program requires a working version of vsnprintf\n"
"However, vsnprintf in the current library seems buggy\n\n"
"Recompiling this program with the -D__REPLACE_SNPRINTF__ flag\n"
"may solve this problem.\n\n");
*/
vsnprintfChecked = VSNPRINTF_NOT_OK;
else
vsnprintfChecked = VSNPRINTF_IS_OK;
}
}

## Clear()

String & String::Clear | ( |  | ) |

inline

Definition at line 65 of file StringBasics.h.

{
len = buffer[0] = 0;
return *this;
}

## Compare() [1/2]

int String::Compare | ( | const char * | rhs | ) | const

Definition at line 413 of file StringBasics.cpp.

{
return caseSensitive ? FastCompare(s) : SlowCompare(s);
}

## Compare() [2/2]

int String::Compare | ( | const String & | rhs | ) | const

Definition at line 405 of file StringBasics.cpp.

{
if (caseSensitive)
return String::FastCompare(s);
else
return String::SlowCompare(s);
}

## CompareToStem() [1/2]

int String::CompareToStem | ( | const char * | stem | ) | const

Definition at line 1199 of file StringBasics.cpp.

{
if (caseSensitive)
return String::FastCompareToStem(stem);
else
return String::SlowCompareToStem(stem);
}

## CompareToStem() [2/2]

int String::CompareToStem | ( | const String & | stem | ) | const

Definition at line 1153 of file StringBasics.cpp.

{
if (caseSensitive)
return String::FastCompareToStem(stem);
else
return String::SlowCompareToStem(stem);
}

## Copy() [1/3]

String & String::Copy | ( | const char * | s | ) |

Definition at line 137 of file StringBasics.cpp.

{
if (s == NULL)
{
len = 0;
buffer[0] = 0;
}
else
{
int clen = strlen(s);
Grow(clen);
len = clen;
memcpy(buffer, s, len + 1);
}
return *this;
}

## Copy() [2/3]

String & String::Copy | ( | const String & | s | ) |

Definition at line 119 of file StringBasics.cpp.

{
Grow(s.len);
len = s.len;
memcpy(buffer, s.buffer, len + 1);
return *this;
}

## Copy() [3/3]

String & String::Copy | ( | const String & | s,
|  | int | start,
|  | int | count )

Definition at line 127 of file StringBasics.cpp.

{
if (s.len <= start) return Clear();
if (s.len < start + n) n = s.len - start;
Grow(n);
memcpy(buffer, s.buffer + start, n);
buffer[len = n] = 0;
return *this;
}

## Dimension()

int String::Dimension | ( | int | newlen | ) |

inline

Definition at line 297 of file StringBasics.h.

{
return SetLength(newlen);
}

## ExcludeCharacters() [1/2]

String & String::ExcludeCharacters | ( | const char * | s | ) |

Definition at line 966 of file StringBasics.cpp.

{
String excluded(s);
return ExcludeCharacters(excluded);
}

## ExcludeCharacters() [2/2]

String & String::ExcludeCharacters | ( | const String & | s | ) |

Definition at line 956 of file StringBasics.cpp.

{
int to = 0;
for (int from = 0; from < len; from++)
if (s.FindChar(buffer[from]) == -1)
buffer[to++] = buffer[from];
buffer[len = to] = 0;
return *this;
}

## FastCompare() [1/2]

int String::FastCompare | ( | const char * | rhs | ) | const

Definition at line 437 of file StringBasics.cpp.

{
if (s == NULL)
return -len;
for (int i = 0; i <= len; i++)
if (buffer[i] - s[i])
{
#ifdef NATURAL_ORDERING
int d = i;
while (isdigit(buffer[d]) && isdigit(s[d]))
d++;
if (isdigit(buffer[d]))
return 1;
if (isdigit(s[d]))
return -1;
#endif
return buffer[i] - s[i];
}
return 0;
}

## FastCompare() [2/2]

int String::FastCompare | ( | const String & | rhs | ) | const

Definition at line 418 of file StringBasics.cpp.

{
for (int i = 0; i <= len; i++)
if (buffer[i] - s.buffer[i])
{
#ifdef NATURAL_ORDERING
int d = i;
while (isdigit(buffer[d]) && isdigit(s.buffer[d]))
d++;
if (isdigit(buffer[d]))
return 1;
if (isdigit(s.buffer[d]))
return -1;
#endif
return buffer[i] - s.buffer[i];
}
return 0;
}

## FastCompareToStem() [1/2]

int String::FastCompareToStem | ( | const char * | stem | ) | const

Definition at line 1207 of file StringBasics.cpp.

{
for (int i = 0; stem[i] != 0; i++)
if (buffer[i] - stem[i])
return buffer[i] - stem[i];
return 0;
}

## FastCompareToStem() [2/2]

int String::FastCompareToStem | ( | const String & | stem | ) | const

Definition at line 1161 of file StringBasics.cpp.

{
for (int i = 0; i < stem.len; i++)
if (buffer[i] - stem.buffer[i])
{
#ifdef NATURAL_ORDERING
int d = i;
while (isdigit(buffer[d]) && isdigit(stem.buffer[d]) && d < stem.len)
d++;
if (isdigit(buffer[d]) && d < stem.len)
return 1;
if (isdigit(stem.buffer[d]))
return -1;
#endif
return buffer[i] - stem.buffer[i];
}
return 0;
}

## FastFind()

int String::FastFind | ( | const String & | str,
|  | int | start = 0 ) const

Definition at line 901 of file StringBasics.cpp.

{
for (int i ; start <= len - pattern.Length(); start++)
if (buffer[start] == pattern[0])
{
for (i = 1; i < pattern.Length(); i++)
if (pattern[i] != buffer[start + i])
break;
if (i == pattern.Length()) return start;
}
return -1;
}

## FastFindChar()

int String::FastFindChar | ( | char | ch,
|  | int | start = 0 ) const

Definition at line 855 of file StringBasics.cpp.

{
for (; start < len; start++)
if (buffer[start] == ch)
return start;
return -1;
}

## FastFindLastChar()

int String::FastFindLastChar | ( | char | ch | ) | const

Definition at line 877 of file StringBasics.cpp.

{
for (int start = len-1; start >= 0; start--)
if (buffer[start] == ch)
return start;
return -1;
}

## FastMatchesBeginningOf() [1/2]

int String::FastMatchesBeginningOf | ( | const char * | stem | ) | const

Definition at line 1255 of file StringBasics.cpp.

{
for (int i = 0; i < len; i++)
if (buffer[i] - stem[i])
return buffer[i] - stem[i];
return 0;
}

## FastMatchesBeginningOf() [2/2]

int String::FastMatchesBeginningOf | ( | const String & | stem | ) | const

Definition at line 1231 of file StringBasics.cpp.

{
for (int i = 0; i < len; i++)
if (buffer[i] - stem.buffer[i])
return buffer[i] - stem.buffer[i];
return 0;
}

## Fill()

void String::Fill | ( | char | ch,
|  | int | length = -1 )

Definition at line 1538 of file StringBasics.cpp.

{
if (length >= 0)
SetLength(length);
for (int i = 0; i < len; i++)
buffer[i] = ch;
}

## Filter() [1/2]

String & String::Filter | ( | const char * | s | ) |

Definition at line 950 of file StringBasics.cpp.

{
String filter(s);
return Filter(filter);
}

## Filter() [2/2]

String & String::Filter | ( | const String & | s | ) |

Definition at line 940 of file StringBasics.cpp.

{
int to = 0;
for (int from = 0; from < len; from++)
if (s.FindChar(buffer[from]) != -1)
buffer[to++] = buffer[from];
buffer[len = to] = 0;
return *this;
}

## Find() [1/2]

int String::Find | ( | char | ch,
|  | int | start = 0 ) const

inline

Definition at line 273 of file StringBasics.h.

{
return(FindChar(ch, start));
}

## Find() [2/2]

int String::Find | ( | const String & | str,
|  | int | start = 0 ) const

Definition at line 894 of file StringBasics.cpp.

{
return caseSensitive ? FastFind(pattern, start) : SlowFind(pattern, start);
}

## FindChar()

int String::FindChar | ( | char | ch,
|  | int | start = 0 ) const

Definition at line 850 of file StringBasics.cpp.

{
return caseSensitive ? FastFindChar(ch, start) : SlowFindChar(ch, start);
}

## FindLastChar()

int String::FindLastChar | ( | char | ch | ) | const

Definition at line 872 of file StringBasics.cpp.

{
return caseSensitive ? FastFindLastChar(ch) : SlowFindLastChar(ch);
}

## First()

char & String::First | ( |  | ) |

inline

Definition at line 227 of file StringBasics.h.

{
return buffer[0];
}

## Grow()

void String::Grow | ( | int | newSize | ) |

Definition at line 81 of file StringBasics.cpp.

{
if (newSize >= size)
{
if ((newSize >> 1) >= size)
size = (newSize + alloc) / alloc * alloc;
else
{
size = alloc;
while (size <= newSize)
size *= 2;
}
char * tmp = new char [size];
// // len + 1 due to terminating NUL which is not counted in len
// memcpy(tmp, buffer, len + 1);
memcpy(tmp, buffer, len);
tmp[len] = '\0';
delete [] buffer;
buffer = tmp;
}
}

## Invert() [1/2]

String & String::Invert | ( |  | ) |

Definition at line 1129 of file StringBasics.cpp.

{
for (int i = 0, j = len - 1; i < j; i++, j--)
{
char tmp = buffer[i];
buffer[i] = buffer[j];
buffer[j] = tmp;
}
return *this;
}

## Invert() [2/2]

String & String::Invert | ( | const String & | s | ) |

Definition at line 1147 of file StringBasics.cpp.

{
Copy(s);
return Invert();
}

## IsEmpty()

bool String::IsEmpty | ( |  | ) | const

inline

Definition at line 75 of file StringBasics.h.

{
return len == 0;
}

## IsNumber()

bool String::IsNumber | ( |  | ) |

Definition at line 1494 of file StringBasics.cpp.

{
int pos = 0;
bool digits = false;
// Skip leading sign
if (buffer[pos] == '-' || buffer[pos] == '+')
pos++;
// Check integer portion
while (buffer[pos] >= '0' && buffer[pos] <= '9')
pos++, digits = true;
// Skip decimal point
if (buffer[pos] == '.')
{
pos++;
// Check fractional portion
while (buffer[pos] >= '0' && buffer[pos] <= '9')
pos++, digits = true;
}
if (!digits) return false;
// Check exponent
if (buffer[pos] == 'E' || buffer[pos] == 'e')
{
pos++;
// Skip leading sign
if (buffer[pos] == '-' || buffer[pos] == '+')
pos++;
digits = false;
// Check exponent digits
while (buffer[pos] >= '0' && buffer[pos] <= '9')
pos++, digits = true;
}
return (pos == len) && digits;
}

## Last()

char & String::Last | ( |  | ) |

inline

Definition at line 223 of file StringBasics.h.

{
return buffer[len - 1];
}

## Left()

String String::Left | ( | int | count | ) | const

Definition at line 804 of file StringBasics.cpp.

{
if (n < 0) n = 0;
if (len < n) n = len;
String result(n);
memcpy(result.buffer, buffer, n);
result.buffer[result.len = n] = 0;
return result;
}

## LeftClip()

String & String::LeftClip | ( | int | clipAmount | ) |

Definition at line 1561 of file StringBasics.cpp.

{
if (clipAmount == 0)
return *this;
if (clipAmount > Length())
{
len = 0;
return *this;
}
// Use memory move, because the two blocks can overlap
memmove(buffer, buffer + clipAmount, len - clipAmount);
buffer[len -= clipAmount] = 0;
return *this;
}

## Length()

int String::Length | ( |  | ) | const

inline

Definition at line 287 of file StringBasics.h.

{
return len;
}

## LockBuffer()

char * String::LockBuffer | ( | int | size = -1 | ) |

Definition at line 390 of file StringBasics.cpp.

{
if (min > 0) Grow(min);
return buffer;
}

## MatchesBeginningOf() [1/2]

int String::MatchesBeginningOf | ( | const char * | stem | ) | const

Definition at line 1247 of file StringBasics.cpp.

{
if (caseSensitive)
return String::FastMatchesBeginningOf(stem);
else
return String::SlowMatchesBeginningOf(stem);
}

## MatchesBeginningOf() [2/2]

int String::MatchesBeginningOf | ( | const String & | stem | ) | const

Definition at line 1223 of file StringBasics.cpp.

{
if (caseSensitive)
return String::FastMatchesBeginningOf(stem);
else
return String::SlowMatchesBeginningOf(stem);
}

## Mid()

String String::Mid | ( | int | start,
|  | int | end ) const

Definition at line 845 of file StringBasics.cpp.

{
return SubStr(start, end - start + 1);
}

## my_snprintf()

int String::my_snprintf | ( | char * | buffer,
|  | int | bufsize,
|  | const char * | format,
|  |  | ... )

static

Definition at line 1477 of file StringBasics.cpp.

{
va_list ap;
va_start(ap, format);
int bytes = my_vsnprintf(buffer, bufsize, format, ap);
va_end(ap);
return bytes;
}

## my_vsnprintf()

int String::my_vsnprintf | ( | char * | buffer,
|  | int | bufsize,
|  | const char * | format,
|  | va_list | args )

static

Definition at line 1452 of file StringBasics.cpp.

{
if (my_vsnprintf_file == NULL)
{
my_vsnprintf_file = tmpfile();
atexit(my_vsnprintf_close_file);
}
rewind(my_vsnprintf_file);
int len = vfprintf(my_vsnprintf_file, format, args);
rewind(my_vsnprintf_file);
if (len < bufsize)
buffer[bufsize = len] = 0;
int numRead = fread(buffer, 1, bufsize, my_vsnprintf_file);
if(numRead != bufsize)
{
std::cerr
<< "Warning, StringBasics failed reading stream in my_vsnprintf\n";
}
return len;
}

## my_vsnprintf_close_file()

void String::my_vsnprintf_close_file | ( |  | ) |

static

Definition at line 1489 of file StringBasics.cpp.

{
fclose(my_vsnprintf_file);
}

## operator char *()

String::operator char * | ( |  | ) |

inline

Definition at line 199 of file StringBasics.h.

{
return buffer;
}

## operator const char *()

String::operator const char * | ( |  | ) | const

inline

Definition at line 191 of file StringBasics.h.

{
return buffer;
}

## operator double()

String::operator double | ( |  | ) | const

inline

Definition at line 208 of file StringBasics.h.

{
return atof(buffer);
}

## operator int()

String::operator int | ( |  | ) | const

inline

Definition at line 204 of file StringBasics.h.

{
return atoi(buffer);
}

## operator long double()

String::operator long double | ( |  | ) | const

Definition at line 1609 of file StringBasics.cpp.

{
return atof(buffer);
}

## operator!=() [1/2]

int String::operator!= | ( | const char * | rhs | ) | const

inline

Definition at line 170 of file StringBasics.h.

{
return Compare(rhs) != 0;
}

## operator!=() [2/2]

int String::operator!= | ( | const String & | rhs | ) | const

inline

Definition at line 145 of file StringBasics.h.

{
return Compare(rhs) != 0;
}

## operator*=()

String & String::operator*= | ( | unsigned int | rhs | ) |

Definition at line 344 of file StringBasics.cpp.

{
if (rhs == 0)
Clear();
else
{
String original(*this);
Grow(len * rhs);
for (unsigned int i = 1; i < rhs; i++)
*this += original;
}
return *this;
}

## operator+() [1/6]

String String::operator+ | ( | char | ch | ) | const

Definition at line 270 of file StringBasics.cpp.

{
String result(*this);
result += ch;
return result;
}

## operator+() [2/6]

String String::operator+ | ( | const char * | rhs | ) | const

Definition at line 231 of file StringBasics.cpp.

{
if (rhs != NULL)
{
int clen = strlen(rhs);
String result(len + clen);
memcpy(result.buffer, buffer, len);
memcpy(result.buffer + len, rhs, clen + 1);
result.len = len + clen;
return result;
}
return *this;
}

## operator+() [3/6]

String String::operator+ | ( | const String & | rhs | ) | const

Definition at line 222 of file StringBasics.cpp.

{
String result(len + rhs.len);
memcpy(result.buffer, buffer, len);
memcpy(result.buffer + len, rhs.buffer, rhs.len + 1);
result.len = len + rhs.len;
return result;
}

## operator+() [4/6]

String String::operator+ | ( | double | rhs | ) | const

Definition at line 368 of file StringBasics.cpp.

{
String result(*this);
result += rhs;
return result;
}

## operator+() [5/6]

String String::operator+ | ( | int | rhs | ) | const

Definition at line 316 of file StringBasics.cpp.

{
String result(*this);
result += rhs;
return result;
};

## operator+() [6/6]

String String::operator+ | ( | unsigned int | rhs | ) | const

Definition at line 323 of file StringBasics.cpp.

{
String result(*this);
result += rhs;
return result;
};

## operator+=() [1/6]

String & String::operator+= | ( | char | ch | ) |

Definition at line 259 of file StringBasics.cpp.

{
if (ch)
{
Grow(len + 1);
buffer[len] = ch;
buffer[++len] = 0;
}
return *this;
}

## operator+=() [2/6]

String & String::operator+= | ( | const char * | rhs | ) |

Definition at line 210 of file StringBasics.cpp.

{
if (rhs != NULL)
{
int clen = strlen(rhs);
Grow(len + clen);
memcpy(buffer + len, rhs, clen + 1);
len += clen;
}
return *this;
}

## operator+=() [3/6]

String & String::operator+= | ( | const String & | rhs | ) |

Definition at line 202 of file StringBasics.cpp.

{
Grow(len + rhs.len);
memcpy(buffer + len, rhs.buffer, rhs.len + 1);
len += rhs.len;
return *this;
}

## operator+=() [4/6]

String & String::operator+= | ( | double | rhs | ) |

Definition at line 375 of file StringBasics.cpp.

{
String temp;
temp = rhs;
return *this += temp;
}

## operator+=() [5/6]

String & String::operator+= | ( | int | rhs | ) |

Definition at line 330 of file StringBasics.cpp.

{
String temp;
temp = rhs;
return *this += temp;
}

## operator+=() [6/6]

String & String::operator+= | ( | unsigned int | rhs | ) |

Definition at line 337 of file StringBasics.cpp.

{
String temp;
temp = rhs;
return *this += temp;
}

## operator<() [1/2]

int String::operator< | ( | const char * | rhs | ) | const

inline

Definition at line 174 of file StringBasics.h.

{
return Compare(rhs) < 0;
}

## operator<() [2/2]

int String::operator< | ( | const String & | rhs | ) | const

inline

Definition at line 149 of file StringBasics.h.

{
return Compare(rhs) < 0;
}

## operator<=() [1/2]

int String::operator<= | ( | const char * | rhs | ) | const

inline

Definition at line 182 of file StringBasics.h.

{
return Compare(rhs) <= 0;
}

## operator<=() [2/2]

int String::operator<= | ( | const String & | rhs | ) | const

inline

Definition at line 161 of file StringBasics.h.

{
return Compare(rhs) <= 0;
}

## operator=() [1/6]

String & String::operator= | ( | char | ch | ) |

Definition at line 245 of file StringBasics.cpp.

{
if (ch)
{
Grow(1);
buffer[0] = ch;
buffer[1] = 0;
len = 1;
}
else
len = buffer[0] = 0;
return *this;
}

## operator=() [2/6]

String & String::operator= | ( | const char * | rhs | ) |

Definition at line 196 of file StringBasics.cpp.

{
Copy(rhs);
return * this;
}

## operator=() [3/6]

String & String::operator= | ( | const String & | rhs | ) |

Definition at line 190 of file StringBasics.cpp.

{
Copy(rhs);
return *this;
}

## operator=() [4/6]

String & String::operator= | ( | double | rhs | ) |

Definition at line 360 of file StringBasics.cpp.

{
LockBuffer(32);
sprintf(buffer, "%.3f", rhs);
UnlockBuffer();
return *this;
}

## operator=() [5/6]

String & String::operator= | ( | int | rhs | ) |

Definition at line 277 of file StringBasics.cpp.

{
Clear();
if (rhs < 0)
{
Add('-');
*this += (unsigned int) -rhs;
}
else
*this = (unsigned int) rhs;
return *this;
}

## operator=() [6/6]

String & String::operator= | ( | unsigned int | rhs | ) |

Definition at line 291 of file StringBasics.cpp.

{
Clear();
unsigned long long base = 10;
int digits = 1;
while (rhs >= base)
{
base *= 10;
digits++;
}
Grow(digits);
while (base /= 10)
{
char ch = char(rhs / base);
rhs = rhs - ch * base;
buffer[len++] = char(ch + '0');
}
buffer[len] = 0;
return *this;
};

## operator==() [1/2]

int String::operator== | ( | const char * | rhs | ) | const

inline

Definition at line 166 of file StringBasics.h.

{
return Compare(rhs) == 0;
}

## operator==() [2/2]

int String::operator== | ( | const String & | rhs | ) | const

inline

Definition at line 141 of file StringBasics.h.

{
return Compare(rhs) == 0;
}

## operator>() [1/2]

int String::operator> | ( | const char * | rhs | ) | const

inline

Definition at line 178 of file StringBasics.h.

{
return Compare(rhs) > 0;
}

## operator>() [2/2]

int String::operator> | ( | const String & | rhs | ) | const

inline

Definition at line 153 of file StringBasics.h.

{
return Compare(rhs) > 0;
}

## operator>=() [1/2]

int String::operator>= | ( | const char * | rhs | ) | const

inline

Definition at line 186 of file StringBasics.h.

{
return Compare(rhs) >= 0;
}

## operator>=() [2/2]

int String::operator>= | ( | const String & | rhs | ) | const

inline

Definition at line 157 of file StringBasics.h.

{
return Compare(rhs) >= 0;
}

## operator[]() [1/2]

char & String::operator[] | ( | int | i | ) |

inline

Definition at line 218 of file StringBasics.h.

{
return buffer[i];
}

## operator[]() [2/2]

char String::operator[] | ( | int | i | ) | const

inline

Definition at line 214 of file StringBasics.h.

{
return buffer[i];
}

## printf()

int String::printf | ( | const char * | format,
|  |  | ... )

Definition at line 1335 of file StringBasics.cpp.

{
va_list ap;
va_start(ap, format);
vprintf(format, ap);
va_end(ap);
return len;
}

## Read() [1/3]

String & String::Read | ( |  | ) |

Definition at line 568 of file StringBasics.cpp.

{
return Read(stdin);
}

## Read() [2/3]

String & String::Read | ( | FILE * | f | ) |

Definition at line 546 of file StringBasics.cpp.

{
len = 0;
buffer[len] = 0;
if (f == NULL) return *this;
int clen = 0;
char check[2] = {'G', 0};
while (strchr(WHITESPACE, check[0]) == NULL)
{
clen += READBUF;
int io = fscanf(f, " %" READBUFSTR "[^" WHITESPACE "]"
"%1[" WHITESPACE "]", LockBuffer(clen) + len, check);
if (io == 0 || io == EOF) break;
UnlockBuffer();
}
return *this;
}

## Read() [3/3]

String & String::Read | ( | IFILE & | f | ) |

Definition at line 573 of file StringBasics.cpp.

{
len = 0;
buffer[len] = 0;
if (f == NULL) return *this;
bool leading = true;
while (true)
{
int ch = ifgetc(f);
if (ch == -1) break;
if (strchr(WHITESPACE, ch) != NULL)
{
if (leading)
{
continue;
}
else
{
break;
}
}
if (len + 1 == size)
Grow(len + 1);
buffer[len++] = (char) ch;
buffer[len] = 0;
leading = false;
}
return *this;
}
ifgetc
int ifgetc(IFILE file)
Get a character from the file.
Definition InputFile.h:615

## ReadLine() [1/3]

int String::ReadLine | ( |  | ) |

Definition at line 612 of file StringBasics.cpp.

{
static int last = 0;
int ch;
len = 0;
buffer[len] = 0;
while (true)
{
ch = getchar();
if (ch == EOF)
{
break;
}
if (ch == 10)
{
if (last == 13)
{
last = 0;
continue;
}
else
{
last = 10;
break;
}
}
if (ch == 13)
{
if (last == 10)
{
last = 0;
continue;
}
else
{
last = 13;
break;
}
}
if (len + 1 == size)
{
Grow(len + 1);
}
last = ch;
buffer[len++] = (char) last;
buffer[len] = 0;
}
if ((ch == EOF) && (len == 0))
{
// Indicate error/EOF if nothing was read.
return -1;
}
// Return success.
return 1;
}

## ReadLine() [2/3]

int String::ReadLine | ( | FILE * | f | ) |

Definition at line 500 of file StringBasics.cpp.

{
len = 0;
buffer[len] = 0;
if (f == NULL) return -1;
int clen = 0;
char check[2] = {0, 0};
int step = 128;
String format("%128[^\n\r]%1[\n\r]");
int returnValue = 1;
int io = 0;
while (check[0] != '\n' && check[0] != '\r')
{
if (clen)
{
step *= 2;
format.printf("%%%d%s", step, "[^\n\r]%1[\n\r]");
}
clen += step;
io = fscanf(f, format, LockBuffer(clen) + len, check);
UnlockBuffer();
// Avoid getting stuck on zero length lines (system specific!)
if (io == 0 && check[0] != '\n' && check[0] != '\r')
io = fscanf(f, "%1[\n\r]", check);
if (io == 0 || io == EOF)
{
// Set return value to indicate error/EOF
returnValue = -1;
break;
}
}
if (check[0] == '\n') io = fscanf(f, "%*1[\r]");
if (check[0] == '\r') io = fscanf(f, "%*1[\n]");
return returnValue;
}

## ReadLine() [3/3]

int String::ReadLine | ( | IFILE & | f | ) |

Definition at line 744 of file StringBasics.cpp.

{
int ch;
char *ptr = buffer;
char *endBuffer = buffer + size;
len = 0;
while ( ((ch = f->ifgetc()) != EOF) && (ch != '\n'))
{
if (ptr >= endBuffer - 1)
{
// resize: 1 byte for the next character, 1 byte
// for the NUL at the end.
Grow(len + 2);
endBuffer = buffer + size;
ptr = buffer + len;
}
*ptr++ = ch;
len++;
}
// NB: assumes that buffer is always allocated.
buffer[len] = 0;
if ((ch == EOF) && (len == 0))
{
// Indicate error/EOF if nothing was read.
return -1;
}
return 1;
}
InputFile::ifgetc
int ifgetc()
Get a character from the file.
Definition InputFile.h:324

## Reverse()

String & String::Reverse | ( |  | ) |

Definition at line 1547 of file StringBasics.cpp.

{
for (int i = 0, j = len - 1; i < j; i++, j--)
{
int tmp = buffer[i];
buffer[i] = buffer[j];
buffer[j] = tmp;
}
return *this;
}

## Right()

String String::Right | ( | int | count | ) | const

Definition at line 814 of file StringBasics.cpp.

{
if (n < 0) n = 0;
if (len < n) n = len;
String result(n);
memcpy(result.buffer, buffer + len - n, n);
result.buffer[result.len = n] = 0;
return result;
}

## RightClip()

String & String::RightClip | ( | int | clipAmount | ) |

Definition at line 1579 of file StringBasics.cpp.

{
if (clipAmount == 0) return *this;
if (clipAmount > Length())
{
len = 0;
return *this;
}
len -= clipAmount;
buffer[len] = 0;
return *this;
}

## RightToLeft()

String String::RightToLeft | ( |  | ) |

Definition at line 1140 of file StringBasics.cpp.

{
String result(*this);
result.Invert();
return result;
}

## schar()

const signed char * String::schar | ( |  | ) | const

inline

Definition at line 353 of file StringBasics.h.

{
return (signed char *) buffer;
}

## SetLength()

int String::SetLength | ( | int | newlen | ) |

Definition at line 929 of file StringBasics.cpp.

{
if (newlen > len)
{
Grow(newlen);
memset(buffer + len, ' ', newlen - len);
}
buffer[newlen] = 0;
return len = newlen;
}

## SlowCompare() [1/2]

int String::SlowCompare | ( | const char * | rhs | ) | const

Definition at line 478 of file StringBasics.cpp.

{
if (s == NULL)
return -len;
for (int i = 0; i <= len; i++)
if (toupper(buffer[i]) - toupper(s[i]))
{
#ifdef NATURAL_ORDERING
int d = i;
while (isdigit(buffer[d]) && isdigit(s[d]))
d++;
if (isdigit(buffer[d]))
return 1;
if (isdigit(s[d]))
return -1;
#endif
return toupper(buffer[i]) - toupper(s[i]);
}
return 0;
}

## SlowCompare() [2/2]

int String::SlowCompare | ( | const String & | rhs | ) | const

Definition at line 459 of file StringBasics.cpp.

{
for (int i = 0; i <= len; i++)
if (toupper(buffer[i]) - toupper(s.buffer[i]))
{
#ifdef NATURAL_ORDERING
int d = i;
while (isdigit(buffer[d]) && isdigit(s[d]))
d++;
if (isdigit(buffer[d]))
return 1;
if (isdigit(s.buffer[d]))
return -1;
#endif
return toupper(buffer[i]) - toupper(s.buffer[i]);
}
return 0;
}

## SlowCompareToStem() [1/2]

int String::SlowCompareToStem | ( | const char * | stem | ) | const

Definition at line 1215 of file StringBasics.cpp.

{
for (int i = 0; stem[i] != 0; i++)
if (toupper(buffer[i]) - toupper(stem[i]))
return toupper(buffer[i]) - toupper(stem[i]);
return 0;
}

## SlowCompareToStem() [2/2]

int String::SlowCompareToStem | ( | const String & | stem | ) | const

Definition at line 1180 of file StringBasics.cpp.

{
for (int i = 0; i < stem.len; i++)
if (toupper(buffer[i]) - toupper(stem.buffer[i]))
{
#ifdef NATURAL_ORDERING
int d = i;
while (isdigit(buffer[d]) && isdigit(stem.buffer[d]) && d < stem.len)
d++;
if (isdigit(buffer[d]) && d < stem.len)
return 1;
if (isdigit(stem.buffer[d]))
return -1;
#endif
return toupper(buffer[i]) - toupper(stem.buffer[i]);
}
return 0;
}

## SlowFind()

int String::SlowFind | ( | const String & | str,
|  | int | start = 0 ) const

Definition at line 914 of file StringBasics.cpp.

{
int firstchar = toupper(pattern[0]);
for (int i ; start <= len - pattern.Length(); start++)
if (toupper(buffer[start]) == firstchar)
{
for (i = 1; i < pattern.Length(); i++)
if (toupper(pattern[i]) != toupper(buffer[start + i]))
break;
if (i == pattern.Length()) return start;
}
return -1;
}

## SlowFindChar()

int String::SlowFindChar | ( | char | ch,
|  | int | start = 0 ) const

Definition at line 863 of file StringBasics.cpp.

{
ch = (char) toupper(ch);
for (; start < len; start++)
if (toupper(buffer[start]) == ch)
return start;
return -1;
}

## SlowFindLastChar()

int String::SlowFindLastChar | ( | char | ch | ) | const

Definition at line 885 of file StringBasics.cpp.

{
ch = (char) toupper(ch);
for (int start = len-1 ; start >= 0; start--)
if (toupper(buffer[start]) == ch)
return start;
return -1;
}

## SlowMatchesBeginningOf() [1/2]

int String::SlowMatchesBeginningOf | ( | const char * | stem | ) | const

Definition at line 1263 of file StringBasics.cpp.

{
for (int i = 0; i < len; i++)
if (toupper(buffer[i]) - toupper(stem[i]))
return toupper(buffer[i]) - toupper(stem[i]);
return 0;
}

## SlowMatchesBeginningOf() [2/2]

int String::SlowMatchesBeginningOf | ( | const String & | stem | ) | const

Definition at line 1239 of file StringBasics.cpp.

{
for (int i = 0; i < len; i++)
if (toupper(buffer[i]) - toupper(stem.buffer[i]))
return toupper(buffer[i]) - toupper(stem.buffer[i]);
return 0;
}

## Split()

vector< String > * String::Split | ( | char | splitChar | ) |

Definition at line 1309 of file StringBasics.cpp.

{
vector<String> *result = new vector<String>;
String word;
for (int i = 0; i<Length(); i++)
{
if ((*this)[i]==splitChar)
{
result->push_back(word);
word.Clear();
}
else
word.Add((*this)[i]);
}
if (word.Length()>0) result->push_back(word);
return result;
}

## SubStr() [1/2]

String String::SubStr | ( | int | start | ) | const

Definition at line 840 of file StringBasics.cpp.

{
return SubStr(start, len - start);
}

## SubStr() [2/2]

String String::SubStr | ( | int | start,
|  | int | count ) const

Definition at line 824 of file StringBasics.cpp.

{
if (start < 0)
{
n += start;
start = 0;
};
n = min(len - start, n);
n = max(n, 0);
String result(n);
if (start > len) return result;
memcpy(result.buffer, buffer + start, n);
result.buffer[result.len = n] = 0;
return result;
}

## Swap()

void String::Swap | ( | String & | s | ) |

Definition at line 104 of file StringBasics.cpp.

{
char * temp = s.buffer;
s.buffer = buffer;
buffer = temp;
int swap = s.size;
s.size = size;
size = swap;
swap = s.len;
s.len = len;
len = swap;
}

## ToLower()

String & String::ToLower | ( |  | ) |

Definition at line 161 of file StringBasics.cpp.

{
for (int i = 0; i < len; i++)
buffer[i] = (char) tolower(buffer[i]);
return *this;
}

## ToUpper()

String & String::ToUpper | ( |  | ) |

Definition at line 154 of file StringBasics.cpp.

{
for (int i = 0; i < len; i++)
buffer[i] = (char) toupper(buffer[i]);
return *this;
}

## Trim() [1/2]

String & String::Trim | ( |  | ) |

Definition at line 1290 of file StringBasics.cpp.

{
int first = 0;
while (buffer[first] && isspace(buffer[first]))
first++;
int last = len - 1;
while (last >= 0 && isspace(buffer[last]))
last--;
int out = 0;
while (first <= last)
buffer[out++] = buffer[first++];
buffer[len = out] = 0;
return *this;
}

## Trim() [2/2]

String & String::Trim | ( | char | character | ) |

Definition at line 1271 of file StringBasics.cpp.

{
int first = 0;
while (buffer[first] && buffer[first] == character)
first++;
int last = len - 1;
while (last >= 0 && buffer[last] == character)
last--;
int out = 0;
while (first <= last)
buffer[out++] = buffer[first++];
buffer[len = out] = 0;
return *this;
}

## uchar()

const unsigned char * String::uchar | ( |  | ) | const

inline

Definition at line 349 of file StringBasics.h.

{
return (unsigned char *) buffer;
}

## UnlockBuffer()

String & String::UnlockBuffer | ( |  | ) |

Definition at line 396 of file StringBasics.cpp.

{
for (len = 0; len < size; len++)
if (buffer[len] == 0)
return *this;
error("BasicString - direct access overflowed buffer");
return *this;
}

## vcatprintf()

int String::vcatprintf | ( | const char * | format,
|  | va_list | arglist )

Definition at line 1413 of file StringBasics.cpp.

{
check_vsnprintf();
if (len == size)
Grow(size * 2);
while (true)
{
int bytes_needed;
#ifdef va_copy
va_list arguments;
va_copy(arguments, ap);
#else
va_list & arguments = ap;
#endif
if (vsnprintfChecked == VSNPRINTF_IS_OK)
bytes_needed = len + vsnprintf(buffer + len, size - len, format, arguments);
else
bytes_needed = len + my_vsnprintf(buffer + len, size - len, format, arguments);
#ifdef va_copy
va_end(arguments);
#endif
if (bytes_needed >= size)
Grow(bytes_needed);
else if (bytes_needed < len)
Grow(size * 2);
else
{
return len = bytes_needed;
}
}
}

## vprintf()

int String::vprintf | ( | const char * | format,
|  | va_list | arglist )

Definition at line 1357 of file StringBasics.cpp.

{
check_vsnprintf();
while (true)
{
int bytes_needed;
#ifdef va_copy
va_list arguments;
va_copy(arguments, ap);
#else
va_list & arguments = ap;
#endif
if (vsnprintfChecked == VSNPRINTF_IS_OK)
bytes_needed = vsnprintf(buffer, size, format, arguments);
else
bytes_needed = my_vsnprintf(buffer, size, format, arguments);
#ifdef va_copy
va_end(arguments);
#endif
if (bytes_needed >= size)
Grow(bytes_needed);
else if (bytes_needed == -1)
Grow(size * 2);
else
{
return len = bytes_needed;
}
}
}

## Write() [1/2]

void String::Write | ( |  | ) |

Definition at line 783 of file StringBasics.cpp.

{
Write(stdout);
}

## Write() [2/2]

void String::Write | ( | FILE * | f | ) |

Definition at line 778 of file StringBasics.cpp.

{
fprintf(f, "%s", buffer);
}

## WriteLine() [1/2]

void String::WriteLine | ( |  | ) |

Definition at line 788 of file StringBasics.cpp.

{
WriteLine(stdout);
}

## WriteLine() [2/2]

void String::WriteLine | ( | FILE * | f | ) |

Definition at line 793 of file StringBasics.cpp.

{
if (f == NULL) return;
fprintf(f, "%s\n", buffer);
}

## Member Data Documentation

## alloc

int String::alloc = 8

static

Definition at line 48 of file StringBasics.h.

## buffer

char* String::buffer

protected

Definition at line 44 of file StringBasics.h.

## caseSensitive

bool String::caseSensitive = true

static

Definition at line 49 of file StringBasics.h.

## len

int String::len

protected

Definition at line 45 of file StringBasics.h.

## my_vsnprintf_file

FILE * String::my_vsnprintf_file = NULL

static

Definition at line 358 of file StringBasics.h.

## size

int String::size

protected

Definition at line 45 of file StringBasics.h.

The documentation for this class was generated from the following files:

- general/StringBasics.h
- general/StringBasics.cpp