Chapter 7. Utility Functions

Utility Classes and Functions

class EST_Token{}

class EST_Token

This class is similar to EST_String but also maintains the original punctuation and whitespace found around the token.

EST_Token's primary use is with EST_TokenStream class which allows easy tokenizing of ascii files.

A token consists of four parts, any of which may be empty: a name, the actual token, preceding whitespace, preceding punctuation, the name and succeeding punctuation.

Construction and Initialisation

init()

void init ( )

Basic access to fields

set_token()

void set_token ( const EST_String &p)

set token from a string

set_token()

void set_token ( const char *p)

set_whitespace()

void set_whitespace ( const EST_String &p)

set whitespace of token.

set_whitespace()

void set_whitespace ( const char *p)

set_punctuation()

void set_punctuation ( const EST_String &p)

set (post) punctuation of token.

set_punctuation()

void set_punctuation ( const char *p)

set_prepunctuation()

void set_prepunctuation ( const EST_String &p)

set prepunction

set_prepunctuation()

void set_prepunctuation ( const char *p)

whitespace()

const EST_String& whitespace ( )

punctuation()

const EST_String& punctuation ( )

prepunctuation()

const EST_String& prepunctuation ( )

Token Access

string()

const EST_String& string ( ) const

Access token as a string

S()

const EST_String& S ( ) const

Access token as a string

String()

const EST_String& String ( ) const

Access token as a string

operator EST_String()

operator EST_String ( ) const

For automatic coercion to a EST_String

Int()

int Int ( bool &valid) const

Access token as an int

Int()

int Int ( ) const

Access token as an int

I()

int I ( bool &valid) const

Access token as an int

I()

int I ( ) const

Access token as an int

operator int()

operator int ( ) const

Access token as an int

Long()

long Long ( bool &valid) const

Access token as a long

Long()

long Long ( ) const

Access token as a long

L()

long L ( bool &valid) const

Access token as a long

L()

long L ( ) const

Access token as a long

operator long()

operator long ( ) const

Access token as a long

Float()

float Float ( bool &valid) const

Access token as a float

Float()

float Float ( ) const

Access token as a float

F()

float F ( bool &valid) const

Access token as a float

F()

float F ( ) const

Access token as a float

operator float()

operator float ( ) const

Access token as a float

Double()

double Double ( bool &valid) const

Access token as a double

Double()

double Double ( ) const

Access token as a double

D()

double D ( bool &valid) const

Access token as a double

D()

double D ( ) const

Access token as a double

operator double()

operator double ( ) const

Access token as a double

set_quoted()

void set_quoted ( int q)

Note that this token was quoted (or not)

quoted()

int quoted ( ) const

TRUE is token was quoted

set_row()

void set_row ( int r)

set row

set_col()

void set_col ( int c)

set column

set_filepos()

void set_filepos ( int c)

Set file position in original \Ref{EST_TokenStream}

lstring()

EST_String lstring ( )

Return lower case version of token name

ustring()

EST_String ustring ( )

Return upper case version of token name

row()

int row ( void) const

Line number in original EST_TokenStream.

col()

int col ( void) const

Line position in original EST_TokenStream.

filepos()

int filepos ( void) const

file position in original EST_TokenStream.

pos_description()

const EST_String pos_description ( ) const

A string describing current position, suitable for error messages

Operators

operator = ()

EST_Token& operator = ( const EST_Token &a)

operator = ()

EST_Token& operator = ( const EST_String &a)

operator == ()

int operator == ( const EST_String &a)

operator != ()

int operator != ( const EST_String &a)

operator == ()

int operator == ( const char *a)

operator != ()

int operator != ( const char *a)

Utility Functions for strings

StringtoStrList()

void StringtoStrList ( EST_String s, EST_StrList &l, EST_String sep="")

Convert a EST_String to a EST_StrList by separating tokens in s delimited by the separator sep. By default, the string is assumed to be delimited by whitespace.

BracketStringtoStrList()

void BracketStringtoStrList ( EST_String s, EST_StrList &l, EST_String sep="")

Convert a EST_String enclosed in a single set of brackets to a EST_StrList by separating tokens in s delimited by the separator sep. By default, the string is assumed to be delimited by whitespace.

load_StrList()

EST_read_status load_StrList ( EST_String filename, EST_StrList &l)

Load tokens from a file and return them in a EST_StrList

save_StrList()

EST_write_status save_StrList ( EST_String filename, EST_StrList &l, EST_String style="words")

Save tokens from a EST_StrList. If style is set to "lines" each item is stored on a separate line, otherwise each item is separated by a single space

strip_quotes()

void strip_quotes ( EST_String &s, const EST_String quote_char="\"")

remove quotes from a string

itoString()

EST_String itoString ( int n)

Make a EST_String object from an integer

ftoString()

EST_String ftoString ( float n, int pres=3, int width=0, int l=0)

Make a EST_String object from an float, with variable precision

Stringtoi()

int Stringtoi ( EST_String s)

Make an int from a EST_String. EST_String equivalent of atoi()

StrListtoIList()

int StrListtoIList ( EST_StrList &s, EST_IList &il)

Convert a list of strings to a list of integers

StrListtoFList()

int StrListtoFList ( EST_StrList &s, EST_FList &il)

Convert a list of strings to a list of floats

StrList_to_StrVector()

void StrList_to_StrVector ( EST_StrList &l, EST_StrVector &v)

Convert a list of strings to a vector of strings

StrVector_to_StrList()

void StrVector_to_StrList ( EST_StrVector &v, EST_StrList &l)

Convert a vector of strings to a list of strings

StrVector_index()

int StrVector_index ( const EST_StrVector &v, const EST_String &s)

Search the vector and return the position of the first occurance of string s in the vector

strlist_member()

int strlist_member ( const EST_StrList &l, const EST_String &s)

Return true ifs is in list ls

strlist_index()

int strlist_index ( const EST_StrList &l, const EST_String &s)

Search the vector and return the position of the first occurance of string s in the list

basename()

EST_String basename ( EST_String full, EST_String ext="")

This acts like the bourne shell basename command. By default, it strips any leading path from a string. If ext is defined, it strips any suffix matching this string

Utility functions for I/O

make_tmp_filename()

EST_String make_tmp_filename ( )

Make a unique temporary filename

stdin_to_file()

EST_String stdin_to_file ( )

Copy stdin to a file and return the name of that tmpfile

writable_file()

int writable_file ( char *filename)

return true if this file is writeable

readable_file()

int readable_file ( char *filename)

return true if this file is readable

delete_file()

inline int delete_file ( const EST_String &filename)

OS independent way of removing a file

uncompress_file_to_temporary()

EST_String uncompress_file_to_temporary ( const EST_String &filename, const EST_String &prog_name)

Uncompress file by calling program prog, and write it to new tempoary file. Return name of temporary file

compress_file_in_place()

int compress_file_in_place ( const EST_String &filename, const EST_String &prog_name)

Uncompress file and over-write existing file with uncompressed version

compress_file()

int compress_file ( const EST_String &filename, const EST_String &new_filename, const EST_String &prog_name)

compress file by calling program prog, writing result to new_filename