#include <include/EST_String.h>
Public Types | |
typedef int | EST_string_size |
Type of string size field. | |
Public Member Functions | |
Before | |
EST_String | before (int pos, int len=0) const |
Part before position. | |
EST_String | before (const char *s, int pos=0) const |
Part before first matching substring after pos. | |
EST_String | before (const EST_String &s, int pos=0) const |
Part before first matching substring after pos. | |
EST_String | before (EST_Regex &e, int pos=0) const |
Part before first match of regexp after pos. | |
At | |
EST_String | at (int from, int len=0) const |
Return part at position. | |
EST_String | at (const char *s, int pos=0) const |
Return part where substring found (not useful, included for completeness) | |
EST_String | at (const EST_String &s, int pos=0) const |
Return part where substring found (not useful, included for completeness) | |
EST_String | at (EST_Regex &e, int pos=0) const |
Return part matching regexp. | |
After | |
EST_String | after (int pos, int len=1) const |
Part after pos+len. | |
EST_String | after (const char *s, int pos=0) const |
Part after substring. | |
EST_String | after (const EST_String &s, int pos=0) const |
Part after substring. | |
EST_String | after (EST_Regex &e, int pos=0) const |
Part after match of regular expression. | |
Search for something | |
int | search (const char *s, int len, int &mlen, int pos=0) const |
Find a substring. | |
int | search (const EST_String s, int &mlen, int pos=0) const |
Find a substring. | |
int | search (EST_Regex &re, int &mlen, int pos=0, int *starts=NULL, int *ends=NULL) const |
Find a match of the regular expression. | |
Get position of something | |
int | index (const char *s, int pos=0) const |
Position of substring (starting at pos) | |
int | index (const EST_String &s, int pos=0) const |
Position of substring (starting at pos) | |
int | index (EST_Regex &ex, int pos=0) const |
Position of match of regexp (starting at pos) | |
Does string contain something? | |
int | contains (const char *s, int pos=-1) const |
Does it contain this substring? | |
int | contains (const EST_String &s, int pos=-1) const |
Does it contain this substring? | |
int | contains (const char c, int pos=-1) const |
Does it contain this character? | |
int | contains (EST_Regex &ex, int pos=-1) const |
Does it contain a match for this regular expression? | |
Does string exactly match? | |
int | matches (const char *e, int pos=0) const |
Exactly match this string? | |
int | matches (const EST_String &e, int pos=0) const |
Exactly match this string? | |
int | matches (EST_Regex &e, int pos=0, int *starts=NULL, int *ends=NULL) const |
Exactly matches this regular expression, can return ends of sub-expressions. | |
Global replacement | |
int | gsub (const char *os, const EST_String &s) |
Substitute one string for another. | |
int | gsub (const char *os, const char *s) |
Substitute one string for another. | |
int | gsub (const EST_String &os, const EST_String &s) |
Substitute one string for another. | |
int | gsub (const EST_String &os, const char *s) |
Substitute one string for another. | |
int | gsub (EST_Regex &ex, const EST_String &s) |
Substitute string for matches of regular expression. | |
int | gsub (EST_Regex &ex, const char *s) |
Substitute string for matches of regular expression. | |
int | gsub (EST_Regex &ex, int bracket_num) |
Substitute string for matches of regular expression. | |
int | subst (EST_String source, int(&starts)[EST_Regex_max_subexpressions], int(&ends)[EST_Regex_max_subexpressions]) |
Substitute the result of a match into a string. | |
Frequency counts | |
int | freq (const char *s) const |
Number of occurrences of substring. | |
int | freq (const EST_String &s) const |
Number of occurrences of substring. | |
int | freq (EST_Regex &s) const |
Number of matches of regular expression. | |
Quoting | |
EST_String | quote (const char quotec) const |
Return the string in quotes with internal quotes protected. | |
EST_String | quote_if_needed (const char quotec) const |
Return in quotes if there is something to protect (e.g. spaces) | |
EST_String | unquote (const char quotec) const |
Remove quotes and unprotect internal quotes. | |
EST_String | unquote_if_needed (const char quotec) const |
Remove quotes if any. | |
Operators | |
const char | operator() (int i) const |
Function style access to constant strings. | |
char & | operator[] (int i) |
Array style access to writable strings. | |
operator const char * () const | |
Cast to const char * by simply giving access to pointer. | |
operator const char * () | |
operator char * () | |
Cast to char *, may involve copying. | |
Add to end of string. | |
EST_String & | operator+= (const char *b) |
Add C string to end of EST_String. | |
EST_String & | operator+= (const EST_String b) |
Add EST_String to end of EST_String. | |
Assignment | |
EST_String & | operator= (const char *str) |
Assign C string to EST_String. | |
Static Public Attributes | |
static const char * | version = "CSTR String Class " STRING_VERSION " " STRING_DATE |
Global version string. | |
static const EST_String | Empty |
Constant empty string. | |
Global search and replace | |
EST_String (void) | |
Construct an empty string. | |
EST_String (const char *s) | |
Construct from char *. | |
EST_String (const char *s, int start_or_fill, int len) | |
Construct from part of char * or fill with given character. | |
EST_String (const char *s, int s_size, int start, int len) | |
Construct from C string. | |
EST_String (const EST_String &s, int start, int len) | |
~EST_String () | |
Destructor. | |
int | length (void) const |
Length of string ({not} length of underlying chunk) | |
int | space (void) const |
Size of underlying chunk. | |
const char * | str (void) const |
Get a const-pointer to the actual memory. | |
char * | updatable_str (void) |
Get a writable pointer to the actual memory. | |
void | make_updatable (void) |
int | Int (bool &ok) const |
Convert to an integer. | |
int | Int (void) const |
long | Long (bool &ok) const |
Convert to a long. | |
long | Long (void) const |
float | Float (bool &ok) const |
Convert to a float. | |
float | Float (void) const |
double | Double (bool &ok) const |
Convert to a double. | |
double | Double (void) const |
static EST_String | FromChar (const char c) |
Build string from a single character. | |
static EST_String | Number (int i, int base=10) |
Build string from an integer. | |
static EST_String | Number (long i, int base=10) |
Build string from a long integer. | |
static EST_String | Number (double d) |
Build string from a double. | |
static EST_String | Number (float f) |
Build string from a float. | |
A non-copyleft implementation of a string class to use with compilers that aren't GNU C++.
Strings are reference-counted and reasonably efficient (eg you can pass them around, into and out of functions and so on without worrying too much about the cost).
The associated class EST_Regex can be used to represent regular expressions.
Definition at line 70 of file EST_String.h.
Type of string size field.
Definition at line 114 of file EST_String.h.
|
inline |
Construct an empty string.
Definition at line 201 of file EST_String.h.
Construct from char *.
Definition at line 811 of file EST_String.cc.
Construct from part of char * or fill with given character.
Definition at line 824 of file EST_String.cc.
Construct from C string.
Definition at line 857 of file EST_String.cc.
EST_String::EST_String | ( | const EST_String & | s, |
int | start, | ||
int | len | ||
) |
Definition at line 871 of file EST_String.cc.
|
inline |
Destructor.
Copy constructor We have to declare our own copy constructor to lie to the compiler about the constness of the RHS.
Definition at line 235 of file EST_String.h.
|
inline |
Length of string ({not} length of underlying chunk)
Definition at line 241 of file EST_String.h.
|
inline |
Size of underlying chunk.
Definition at line 243 of file EST_String.h.
Get a const-pointer to the actual memory.
Definition at line 245 of file EST_String.h.
Get a writable pointer to the actual memory.
Definition at line 247 of file EST_String.h.
Definition at line 248 of file EST_String.h.
|
inlinestatic |
Build string from a single character.
Definition at line 252 of file EST_String.h.
|
static |
Build string from an integer.
Definition at line 1211 of file EST_String.cc.
|
static |
Build string from a long integer.
Definition at line 1236 of file EST_String.cc.
|
static |
Build string from a double.
Definition at line 1270 of file EST_String.cc.
|
static |
Build string from a float.
Definition at line 1261 of file EST_String.cc.
|
inline |
Convert to an integer.
Definition at line 268 of file EST_String.h.
|
inline |
Definition at line 269 of file EST_String.h.
|
inline |
Convert to a long.
Definition at line 272 of file EST_String.h.
Definition at line 273 of file EST_String.h.
|
inline |
Convert to a float.
Definition at line 276 of file EST_String.h.
Definition at line 277 of file EST_String.h.
|
inline |
Convert to a double.
Definition at line 280 of file EST_String.h.
Definition at line 281 of file EST_String.h.
|
inline |
Part before position.
Definition at line 286 of file EST_String.h.
|
inline |
Part before first matching substring after pos.
Definition at line 289 of file EST_String.h.
|
inline |
Part before first matching substring after pos.
Definition at line 292 of file EST_String.h.
|
inline |
Part before first match of regexp after pos.
Definition at line 295 of file EST_String.h.
|
inline |
Return part at position.
Definition at line 302 of file EST_String.h.
|
inline |
Return part where substring found (not useful, included for completeness)
Definition at line 305 of file EST_String.h.
|
inline |
Return part where substring found (not useful, included for completeness)
Definition at line 308 of file EST_String.h.
|
inline |
Return part matching regexp.
Definition at line 311 of file EST_String.h.
|
inline |
Part after pos+len.
Definition at line 318 of file EST_String.h.
|
inline |
Part after substring.
Definition at line 321 of file EST_String.h.
|
inline |
Part after substring.
Definition at line 324 of file EST_String.h.
|
inline |
Part after match of regular expression.
Definition at line 327 of file EST_String.h.
Find a substring.
Definition at line 334 of file EST_String.h.
|
inline |
Find a substring.
Definition at line 342 of file EST_String.h.
|
inline |
Find a match of the regular expression.
Definition at line 350 of file EST_String.h.
Position of substring (starting at pos)
Definition at line 362 of file EST_String.h.
|
inline |
Position of substring (starting at pos)
Definition at line 365 of file EST_String.h.
|
inline |
Position of match of regexp (starting at pos)
Definition at line 368 of file EST_String.h.
Does it contain this substring?
Definition at line 375 of file EST_String.h.
|
inline |
Does it contain this substring?
Definition at line 378 of file EST_String.h.
Does it contain this character?
Definition at line 381 of file EST_String.h.
|
inline |
Does it contain a match for this regular expression?
Definition at line 384 of file EST_String.h.
Exactly match this string?
Definition at line 652 of file EST_String.cc.
int EST_String::matches | ( | const EST_String & | e, |
int | pos = 0 |
||
) | const |
Exactly match this string?
Definition at line 669 of file EST_String.cc.
int EST_String::matches | ( | EST_Regex & | e, |
int | pos = 0 , |
||
int * | starts = NULL , |
||
int * | ends = NULL |
||
) | const |
Exactly matches this regular expression, can return ends of sub-expressions.
Definition at line 679 of file EST_String.cc.
|
inline |
Substitute one string for another.
Definition at line 401 of file EST_String.h.
Substitute one string for another.
Definition at line 404 of file EST_String.h.
|
inline |
Substitute one string for another.
Definition at line 407 of file EST_String.h.
|
inline |
Substitute one string for another.
Definition at line 410 of file EST_String.h.
|
inline |
Substitute string for matches of regular expression.
Definition at line 414 of file EST_String.h.
Substitute string for matches of regular expression.
Definition at line 417 of file EST_String.h.
|
inline |
Substitute string for matches of regular expression.
Definition at line 420 of file EST_String.h.
int EST_String::subst | ( | EST_String | source, |
int(&) | starts[EST_Regex_max_subexpressions], | ||
int(&) | ends[EST_Regex_max_subexpressions] | ||
) |
Substitute the result of a match into a string.
Definition at line 467 of file EST_String.cc.
Number of occurrences of substring.
Definition at line 997 of file EST_String.cc.
int EST_String::freq | ( | const EST_String & | s | ) | const |
Number of occurrences of substring.
Definition at line 982 of file EST_String.cc.
int EST_String::freq | ( | EST_Regex & | s | ) | const |
Number of matches of regular expression.
Definition at line 1015 of file EST_String.cc.
EST_String EST_String::quote | ( | const char | quotec | ) | const |
Return the string in quotes with internal quotes protected.
Definition at line 1029 of file EST_String.cc.
EST_String EST_String::quote_if_needed | ( | const char | quotec | ) | const |
Return in quotes if there is something to protect (e.g. spaces)
Definition at line 1068 of file EST_String.cc.
EST_String EST_String::unquote | ( | const char | quotec | ) | const |
Remove quotes and unprotect internal quotes.
Definition at line 1041 of file EST_String.cc.
EST_String EST_String::unquote_if_needed | ( | const char | quotec | ) | const |
Remove quotes if any.
Definition at line 1078 of file EST_String.cc.
Function style access to constant strings.
Definition at line 457 of file EST_String.h.
|
inline |
Array style access to writable strings.
Definition at line 459 of file EST_String.h.
Cast to const char * by simply giving access to pointer.
Definition at line 463 of file EST_String.h.
Definition at line 464 of file EST_String.h.
|
inline |
Cast to char *, may involve copying.
Definition at line 466 of file EST_String.h.
EST_String & EST_String::operator+= | ( | const char * | b | ) |
Add C string to end of EST_String.
Definition at line 765 of file EST_String.cc.
EST_String & EST_String::operator+= | ( | const EST_String | b | ) |
Add EST_String to end of EST_String.
Definition at line 788 of file EST_String.cc.
EST_String & EST_String::operator= | ( | const char * | str | ) |
Assign C string to EST_String.
Definition at line 907 of file EST_String.cc.
|
static |
Concatenate a number of strings. This is more efficient than multiple uses of + or +=
Definition at line 1096 of file EST_String.cc.
|
inline |
Definition at line 638 of file EST_String.h.
|
friend |
Concatenate two EST_Strings.
Definition at line 709 of file EST_String.cc.
|
friend |
Concatenate C String with EST_String.
Definition at line 727 of file EST_String.cc.
|
friend |
Concatenate EST_String with C String.
Definition at line 688 of file EST_String.cc.
|
friend |
Repeat string N times.
Definition at line 748 of file EST_String.cc.
|
friend |
Definition at line 1189 of file EST_String.cc.
|
friend |
Definition at line 506 of file EST_String.h.
|
friend |
Definition at line 1201 of file EST_String.cc.
|
friend |
Definition at line 512 of file EST_String.h.
|
friend |
Definition at line 515 of file EST_String.h.
|
friend |
Definition at line 518 of file EST_String.h.
|
friend |
Definition at line 522 of file EST_String.h.
|
friend |
Definition at line 525 of file EST_String.h.
|
friend |
Definition at line 528 of file EST_String.h.
|
friend |
Definition at line 531 of file EST_String.h.
|
friend |
Definition at line 534 of file EST_String.h.
|
friend |
Definition at line 537 of file EST_String.h.
|
friend |
Definition at line 540 of file EST_String.h.
|
friend |
Definition at line 543 of file EST_String.h.
|
friend |
Definition at line 546 of file EST_String.h.
|
friend |
Definition at line 549 of file EST_String.h.
|
friend |
Definition at line 552 of file EST_String.h.
|
friend |
Definition at line 555 of file EST_String.h.
|
friend |
Definition at line 1138 of file EST_String.cc.
|
friend |
Definition at line 1150 of file EST_String.cc.
|
friend |
Definition at line 571 of file EST_String.h.
|
friend |
Case folded comparison.
The table argument can defined how upper and lower case characters correspond. The default works for ASCII.
Definition at line 1162 of file EST_String.cc.
|
friend |
Definition at line 583 of file EST_String.h.
Definition at line 1175 of file EST_String.cc.
|
friend |
Definition at line 590 of file EST_String.h.
|
friend |
Split at a given separator.
Definition at line 605 of file EST_String.h.
|
friend |
Split at a given separator.
Definition at line 609 of file EST_String.h.
|
friend |
Split at each match of the regular expression.
Definition at line 613 of file EST_String.h.
|
friend |
Convert to upper case.
Definition at line 967 of file EST_String.cc.
|
friend |
Convert to lower case.
Definition at line 954 of file EST_String.cc.
|
friend |
Stream output for EST_String.
Definition at line 1087 of file EST_String.cc.
Global version string.
Definition at line 108 of file EST_String.h.
|
static |
Constant empty string.
Definition at line 111 of file EST_String.h.