In file ../include/EST_String.h:

class EST_String

A non-copyleft implementation of a string class to use with compilers that aren't GNU C++.

Inheritance:


Public Fields

[more]static const char* version
Global version string
[more]static const EST_String Empty
Constant empty string
[more] Split a string into parts.

[more]int max

Public Methods

[more] EST_String (void)
Construct an empty string
[more] EST_String (const char* s)
Construct from char *
[more] EST_String (const char* s, int start_or_fill, int len)
Construct from part of char * or fill with given character
[more] EST_String (const char* s, int s_size, int start, int len)
Construct from C string
[more] EST_String (const EST_String &s)
Copy constructor We have to declare our own copy constructor to lie to the compier about the constness of the RHS
[more] EST_String (const char c)
Construct from single char.
[more] ~EST_String ()
Destructor
[more]int length (void) const
Length of string (not length of underlying chunk)
[more]int space (void) const
Size of underlying chunk
[more]const char* str (void) const
Get a const-pointer to the actual memory
[more]char* updatable_str (void)
Get a writable pointer to the actual memory
[more]static EST_String FromChar (const char c)
Build string from a single character
[more]static EST_String Number (int i, int base=10)
Build string from an integer
[more]static EST_String Number (long i, int base=10)
Build string from a long integer
[more]static EST_String Number (double d)
Build string from a double
[more]static EST_String Number (float f)
Build string from a float
[more]int Int (bool &ok) const
Convert to an integer
[more]long Long (bool &ok) const
Convert to a long
[more]float Float (bool &ok) const
Convert to a float
[more]double Double (bool &ok) const
Convert to a double
[more] Before

[more]EST_String before (int pos, int len=0) const
Part before position
[more]EST_String before (const char* s, int pos=0) const
Part before first matching substring after pos
[more]EST_String before (const EST_String &s, int pos=0) const
Part before first matching substring after pos
[more]EST_String before (EST_Regex &e, int pos=0) const
Part before first match of regexp after pos

[more] At

[more]EST_String at (int from, int len=0) const
Return part at position
[more]EST_String at (const char* s, int pos=0) const
Return part where substring found (not useful, included for completeness)
[more]EST_String at (const EST_String &s, int pos=0) const
Return part where substring found (not useful, included for completeness)
[more]EST_String at (EST_Regex &e, int pos=0) const
Return part matching regexp

[more] After

[more]EST_String after (int pos, int len=1) const
Part after pos+len
[more]EST_String after (const char* s, int pos=0) const
Part after substring
[more]EST_String after (const EST_String &s, int pos=0) const
Part after substring
[more]EST_String after (EST_Regex &e, int pos=0) const
Part after match of regular expression

[more] Search for something

[more]int search (const char* s, int len, int &mlen, int pos=0) const
Find a substring
[more]int search (const EST_String s, int &mlen, int pos=0) const
Find a substring
[more]int search (EST_Regex &re, int &mlen, int pos=0, int* starts=NULL, int* ends=NULL) const
Find a match of the regular expression

[more] Get position of something

[more]int index (const char* s, int pos=0) const
Position of substring (starting at pos)
[more]int index (const EST_String &s, int pos=0) const
Position of substring (starting at pos)
[more]int index (EST_Regex &ex, int pos=0) const
Position of match of regexp (starting at pos)

[more] Does string contain something?

[more]int contains (const char* s, int pos=-1) const
Does it contain this substring?
[more]int contains (const EST_String &s, int pos=-1) const
Does it contain this substring?
[more]int contains (const char c, int pos=-1) const
Does it contain this character?
[more]int contains (EST_Regex &ex, int pos=-1) const
Does it contain a match for this regular expression?

[more] Does string exactly match?

[more]int matches (const char* e, int pos=0) const
Exatly match this string?
[more]int matches (const EST_String &e, int pos=0) const
Exatly match this string?
[more]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

[more] Global replacement

[more]int gsub (const char* os, const EST_String &s)
Substitute one string for another
[more]int gsub (const char* os, const char* s)
Substitute one string for another
[more]int gsub (const EST_String &os, const EST_String &s)
Substitute one string for another
[more]int gsub (const EST_String &os, const char* s)
Substitute one string for another
[more]int gsub (EST_Regex &ex, const EST_String &s)
Substitute string for matches of regular expression
[more]int gsub (EST_Regex &ex, const char* s)
Substitute string for matches of regular expression
[more]int gsub (EST_Regex &ex, int bracket_num)
Substitute string for matches of regular expression
[more]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

[more] Frequency counts

[more]int freq (const char* s) const
Number of occurances of substring
[more]int freq (const EST_String &s) const
Number of occurances of substring
[more]int freq (EST_Regex &s) const
Number of matches of regular expression

[more] Quoting

[more]EST_String quote (const char quotec) const
Return the string in quotes with internal quotes protected
[more]EST_String quote_if_needed (const char quotec) const
Return in quotes if there is something to protect (eg.
[more]EST_String unquote (const char quotec) const
Remove quotes and unprotect internal quotes
[more]EST_String unquote_if_needed (const char quotec) const
Remove quotes if any

[more] Operators

[more]const char operator () (int i) const
Function style access to constant strings
[more]char& operator [] (int i)
Array style access to writable strings
[more] operator const char* () const
Cast to const char * by simply giving access to pointer
[more] operator char* ()
Cast to char *, may involve copying
[more] Add to end of string.

[more]EST_String& operator += (const char* b)
Add C string to end of EST_String
[more]EST_String& operator += (const EST_String b)
Add EST_String to end of EST_String

[more] Asignment

[more]EST_String& operator = (const char* str)
Assign C string to EST_String
[more]EST_String& operator = (const char c)
Assign single character to EST_String
[more]EST_String& operator = (const EST_String &s)
Assign EST_String to EST_String

[more] Concatenation
[more] relational operators

[more]return b
[more] return (a==b)
[more]return compare (a, b)

[more] String comparison.

[more]return compare (b, a)
[more] Case folded comparison.

[more]const EST_String& table return fcompare (a, b, (const unsigned char* )(const char* )table)

[more]static EST_String cat (const EST_String s1, const EST_String s2 = Empty, const EST_String s3 = Empty, const EST_String s4 = Empty, const EST_String s5 = Empty, const EST_String s6 = Empty, const EST_String s7 = Empty, const EST_String s8 = Empty, const EST_String s9 = Empty )
Concatenate a number of strings.

Public

[more]typedef int EST_string_size
Type of string size field
[more]#define MAX_STRING_SIZE (INT_MAX)
Maximum string size


Documentation

A non-copyleft implementation of a string class to use with compilers that aren't GNU C++.

Strings are reference-counted and reasonably efficiant (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.

ostatic const char* version
Global version string

ostatic const EST_String Empty
Constant empty string

otypedef int EST_string_size
Type of string size field

o#define MAX_STRING_SIZE(INT_MAX)
Maximum string size

oint locate(const char* it, int len, int from, int &start, int &end) const
Find substring

oint locate(const EST_String &s, int from, int &start, int &end) const
Find substring

oint locate(EST_Regex &ex, int from, int &start, int &end, int* starts=NULL, int* ends=NULL) const
Find match for regexp

oEST_String chop_internal(const char* s, int length, int pos, EST_chop_direction directionult) const
Locate subsring and chop

oEST_String chop_internal(int pos, int length, EST_chop_direction directionult) const
Chop at given position

oEST_String chop_internal(EST_Regex &ex, int pos, EST_chop_direction directionult) const
Locate match for expression and chop

oint gsub_internal(const char* os, int olength, const char* s, int length)
Substitute for string

oint gsub_internal(EST_Regex &ex, const char* s, int length)
Substitute for matches of regexp

o EST_String(void)
Construct an empty string

o EST_String(const char* s)
Construct from char *

o EST_String(const char* s, int start_or_fill, int len)
Construct from part of char * or fill with given character

o EST_String(const char* s, int s_size, int start, int len)
Construct from C string

o EST_String(const EST_String &s)
Copy constructor We have to declare our own copy constructor to lie to the compier about the constness of the RHS

o EST_String(const char c)
Construct from single char. This constructor is not usually included as it can mask errors.
See Also:
__FSF_COMPATABILITY__

o ~EST_String()
Destructor

oint length(void) const
Length of string (not length of underlying chunk)

oint space(void) const
Size of underlying chunk

oconst char* str(void) const
Get a const-pointer to the actual memory

ochar* updatable_str(void)
Get a writable pointer to the actual memory

ostatic EST_String FromChar(const char c)
Build string from a single character

ostatic EST_String Number(int i, int base=10)
Build string from an integer

ostatic EST_String Number(long i, int base=10)
Build string from a long integer

ostatic EST_String Number(double d)
Build string from a double

ostatic EST_String Number(float f)
Build string from a float

oint Int(bool &ok) const
Convert to an integer

olong Long(bool &ok) const
Convert to a long

ofloat Float(bool &ok) const
Convert to a float

odouble Double(bool &ok) const
Convert to a double

o Before

oEST_String before(int pos, int len=0) const
Part before position

oEST_String before(const char* s, int pos=0) const
Part before first matching substring after pos

oEST_String before(const EST_String &s, int pos=0) const
Part before first matching substring after pos

oEST_String before(EST_Regex &e, int pos=0) const
Part before first match of regexp after pos

o At

oEST_String at(int from, int len=0) const
Return part at position

oEST_String at(const char* s, int pos=0) const
Return part where substring found (not useful, included for completeness)

oEST_String at(const EST_String &s, int pos=0) const
Return part where substring found (not useful, included for completeness)

oEST_String at(EST_Regex &e, int pos=0) const
Return part matching regexp

o After

oEST_String after(int pos, int len=1) const
Part after pos+len

oEST_String after(const char* s, int pos=0) const
Part after substring

oEST_String after(const EST_String &s, int pos=0) const
Part after substring

oEST_String after(EST_Regex &e, int pos=0) const
Part after match of regular expression

o Search for something

oint search(const char* s, int len, int &mlen, int pos=0) const
Find a substring

oint search(const EST_String s, int &mlen, int pos=0) const
Find a substring

oint search(EST_Regex &re, int &mlen, int pos=0, int* starts=NULL, int* ends=NULL) const
Find a match of the regular expression

o Get position of something

oint index(const char* s, int pos=0) const
Position of substring (starting at pos)

oint index(const EST_String &s, int pos=0) const
Position of substring (starting at pos)

oint index(EST_Regex &ex, int pos=0) const
Position of match of regexp (starting at pos)

o Does string contain something?

oint contains(const char* s, int pos=-1) const
Does it contain this substring?

oint contains(const EST_String &s, int pos=-1) const
Does it contain this substring?

oint contains(const char c, int pos=-1) const
Does it contain this character?

oint contains(EST_Regex &ex, int pos=-1) const
Does it contain a match for this regular expression?

o Does string exactly match?

oint matches(const char* e, int pos=0) const
Exatly match this string?

oint matches(const EST_String &e, int pos=0) const
Exatly match this string?

oint 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

o Global replacement

oint gsub(const char* os, const EST_String &s)
Substitute one string for another

oint gsub(const char* os, const char* s)
Substitute one string for another

oint gsub(const EST_String &os, const EST_String &s)
Substitute one string for another

oint gsub(const EST_String &os, const char* s)
Substitute one string for another

oint gsub(EST_Regex &ex, const EST_String &s)
Substitute string for matches of regular expression

oint gsub(EST_Regex &ex, const char* s)
Substitute string for matches of regular expression

oint gsub(EST_Regex &ex, int bracket_num)
Substitute string for matches of regular expression

oint 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

o Frequency counts

oint freq(const char* s) const
Number of occurances of substring

oint freq(const EST_String &s) const
Number of occurances of substring

oint freq(EST_Regex &s) const
Number of matches of regular expression

o Quoting

oEST_String quote(const char quotec) const
Return the string in quotes with internal quotes protected

oEST_String quote_if_needed(const char quotec) const
Return in quotes if there is something to protect (eg. spaces)

oEST_String unquote(const char quotec) const
Remove quotes and unprotect internal quotes

oEST_String unquote_if_needed(const char quotec) const
Remove quotes if any

o Operators
Friends:
EST_String operator * (const EST_String &s, int n)

oconst char operator () (int i) const
Function style access to constant strings

ochar& operator [] (int i)
Array style access to writable strings

o operator const char*() const
Cast to const char * by simply giving access to pointer

o operator char*()
Cast to char *, may involve copying

o Add to end of string.

oEST_String& operator += (const char* b)
Add C string to end of EST_String

oEST_String& operator += (const EST_String b)
Add EST_String to end of EST_String

o Asignment

oEST_String& operator = (const char* str)
Assign C string to EST_String

oEST_String& operator = (const char c)
Assign single character to EST_String

oEST_String& operator = (const EST_String &s)
Assign EST_String to EST_String

o Concatenation
Friends:
EST_String operator + (const EST_String &a, const EST_String &b)
EST_String operator + (const char *a, const EST_String &b)
EST_String operator + (const EST_String &a, const char *b)

o relational operators
Friends:
int operator == (const char *a, const EST_String &b)
int operator == (const EST_String &a, const char *b)
int operator == (const EST_String &a, const EST_String &b)
int operator != (const char *a, const EST_String &b)
int operator != (const EST_String &a, const char *b)
int operator != (const EST_String &a, const EST_String &b)
inline int operator < (const char *a, const EST_String &b)
inline int operator < (const EST_String &a, const char *b)
inline int operator < (const EST_String &a, const EST_String &b)
inline int operator > (const char *a, const EST_String &b)
inline int operator > (const EST_String &a, const char *b)
inline int operator > (const EST_String &a, const EST_String &b)
inline int operator <= (const char *a, const EST_String &b)
inline int operator <= (const EST_String &a, const char *b)
inline int operator <= (const EST_String &a, const EST_String &b)
inline int operator >= (const char *a, const EST_String &b)
inline int operator >= (const EST_String &a, const char *b)
inline int operator >= (const EST_String &a, const EST_String &b)

oreturn b

o return(a==b)

oreturn compare(a, b)

o String comparison.
All these operators return -1, 0 or 1 to indicate the sort order of the strings.
Friends:
int compare(const EST_String &a, const EST_String &b)
int compare(const EST_String &a, const char *b)
inline int compare(const char *a, const EST_String &b)

oreturn compare(b, a)

o Case folded comparison.
Case folded comparison.

The table argument can defined how upper and lower case characters correspond. The default works for ASCII.

Friends:
int fcompare(const EST_String &a, const EST_String &b,
int fcompare(const EST_String &a, const char *b,
inline int fcompare(const EST_String &a, const EST_String &b,

oconst EST_String& table return fcompare(a, b, (const unsigned char* )(const char* )table)

o Split a string into parts.
These functions divide up a string producing an array of substrings.
Friends:
int split(const EST_String & s, EST_String result[],

oint max

ostatic EST_String cat(const EST_String s1, const EST_String s2 = Empty, const EST_String s3 = Empty, const EST_String s4 = Empty, const EST_String s5 = Empty, const EST_String s6 = Empty, const EST_String s7 = Empty, const EST_String s8 = Empty, const EST_String s9 = Empty )
Concatenate a number of strings. This is more efficiant than multiple uses of + or +=


Direct child classes:
EST_Pathname
EST_Regex
Friends:
EST_String upcase(const EST_String &s)
EST_String downcase(const EST_String &s)
ostream &operator << (ostream &s, const EST_String &str)
class EST_Regex
Author:
Alan W Black <awb@cstr.ed.ac.uk> Richard Caley <rjc@cstr.ed.ac.uk>
Version:
See Also:
EST_Chunk
EST_Regex
string_example

Alphabetic index HTML hierarchy of classes or Java


This page is part of the Edinburgh Speech Tools Library documentation
Copyright University of Edinburgh 1997
Contact: speech_tools@cstr.ed.ac.uk