Word String Class

The word string class library module has the file name wstring.cpp. This class manipulates strings as a series of words which can be delimited by any single character or command words which are always delimited the space character. Most of the functionality of the Future Lab C parse module is encapsulated in this class. Here is a list of methods in the word string class:

Class Data Members

string ws_contents - private

This data member holds the current string contents.

Module Dependencies

This class does not depend on any other Future Lab module and may be used by itself. This class does, however, use the C++ standard library string class.

Class Header Files

This class requires the header files:

Class Methods

empty constructor

Prototype  : word_string()

This empty constructor initializes the word string class data member ws_contents to an empty string.

constructor(string)

Prototype  : word_string(string& text)
Parameters :
      Name : text
Description: string contents

This constructor will load the class data member ws_contents from the input string contents.

constructor(char *)

Prototype  : word_string(char *text)
Parameters :
      Name : text
Description: string contents

This constructor will load the class data member ws_contents from the input string contents.

constructor(word_string)

Prototype  : word_string(word_string& o_string)
Parameters :
      Name : o_string
Description: string contents

This copy constructor will load the class data member ws_contents from the input string contents.

constructor(char, int)

Prototype  : word_string(char ch, int cnt)
Parameters :
      Name : ch
Description: fill character

      Name : cnt
Description: fill count

This constructor will load the class data member ws_contents with fill count number of the fill character.

destructor

Prototype  : ~word_string()

This destructor will set the class data member ws_contents to an empty string.

operator = (word_string)

Prototype  : void operator = (word_string str)
Parameters :
      Name : str
Description: source string

This inline operator will assign the class data member ws_contents to the contents of the source string.

operator = (char *)

Prototype  : void operator = (char *str)
Parameters :
      Name : str
Description: source string

This inline operator will assign the class data member ws_contents to the contents of the source string.

operator = (char)

Prototype  : void operator = (char ch)
Parameters :
      Name : ch
Description: source character

This inline operator will assign the class data member ws_contents to the contents of the source character.

operator = (string)

Prototype  : void operator = (string str)
Parameters :
      Name : str
Description: source string

This inline operator will assign the class data member ws_contents to the contents of the source string.

operator + (word_string, word_string)

Prototype  : friend word_string operator + (word_string str1, word_string str2)
Parameters :
      Name : str1
Description: first source string

Parameters :
      Name : str2
Description: second source string

Returns    : concatenated string

This friend method will concatenate two word strings and return the result.

operator + (word_string, string)

Prototype  : friend word_string operator + (word_string str1, string str2)
Parameters :
      Name : str1
Description: first source string

Parameters :
      Name : str2
Description: second source string

Returns    : concatenated string

This friend method will concatenate a word string with a C++ string and return the result.

operator + (string, word_string)

Prototype  : friend word_string operator + (string str1, word_string str2)
Parameters :
      Name : str1
Description: first source string

Parameters :
      Name : str2
Description: second source string

Returns    : concatenated string

This friend method will concatenate a C++ string with a word string and return the result.

operator + (word_string, char *)

Prototype  : friend word_string operator + (word_string str1, char *str2)
Parameters :
      Name : str1
Description: first source string

Parameters :
      Name : str2
Description: second source string

Returns    : concatenated string

This friend method will concatenate a word string with a C string and return the result.

operator + (char *, word_string)

Prototype  : friend word_string operator + (char *str1, word_string str2)
Parameters :
      Name : str1
Description: first source string

Parameters :
      Name : str2
Description: second source string

Returns    : concatenated string

This friend method will concatenate a C string with a word string and return the result.

operator + (word_string, char)

Prototype  : friend word_string operator + (word_string str1, char ch)
Parameters :
      Name : str1
Description: first source string

Parameters :
      Name : ch
Description: source character

Returns    : concatenated string

This friend method will concatenate a word string with a source character and return the result.

operator + (char, word_string)

Prototype  : friend word_string operator + (char ch, word_string str1)
Parameters :
      Name : ch
Description: source character

Parameters :
      Name : str1
Description: source string

Returns    : concatenated string

This friend method will concatenate the source character with the source string and return the result.

operator += (word_string)

Prototype  : void operator += (word_string str)
Parameters :
      Name : str
Description: source string

This inline operator will concatenate the contents of the source string with the existing contents of the class data member ws_contents.

operator += (char *)

Prototype  : void operator += (char *str)
Parameters :
      Name : str
Description: source string

This inline operator will concatenate the contents of the source string with the existing contents of the class data member ws_contents.

operator += (char)

Prototype  : void operator += (char ch)
Parameters :
      Name : ch
Description: source character

This inline operator will concatenate the contents of the source character with the existing contents of the class data member ws_contents.

operator += (string)

Prototype  : void operator += (string str)
Parameters :
      Name : str
Description: source string

This inline operator will concatenate the contents of the source string with the existing contents of the class data member ws_contents.

operator [] (int)

Prototype  : char operator [] (int pos)
Parameters :
      Name : pos
Description: index position

Returns    : extracted character

This operator will extract and return the character at the index position within the class data member ws_contents.

operator == (word_string)

Prototype  : bool operator == (word_string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if equal, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator == (string)

Prototype  : bool operator == (string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if equal, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator == (char *)

Prototype  : bool operator == (char *s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if equal, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator == (char)

Prototype  : bool operator == (char ch)
Parameters :
      Name : ch
Description: comparison character

Returns    : TRUE if equal, FALSE otherwise

This operator will compare the first character of the class data member ws_contents with the comparison character. Comparison is case-sensitive.

operator != (word_string)

Prototype  : bool operator != (word_string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if not equal, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator != (string)

Prototype  : bool operator != (string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if not equal, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator != (char *)

Prototype  : bool operator != (char *s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if not equal, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator != (char)

Prototype  : bool operator != (char ch)
Parameters :
      Name : ch
Description: comparison character

Returns    : TRUE if not equal, FALSE otherwise

This operator will compare the first character of the class data member ws_contents with the comparison character. Comparison is case-sensitive.

operator < (word_string)

Prototype  : bool operator < (word_string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is less than the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator < (string)

Prototype  : bool operator < (string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is less than the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator < (char *)

Prototype  : bool operator < (char *s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is less than the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator <= (word_string)

Prototype  : bool operator <= (word_string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is less than or equal to the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator <= (string)

Prototype  : bool operator <= (string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is less than or equal to the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator <= (char *)

Prototype  : bool operator <= (char *s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is less than or equal to the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator > (word_string)

Prototype  : bool operator > (word_string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is greater than the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator > (string)

Prototype  : bool operator > (string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is greater than the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator > (char *)

Prototype  : bool operator > (char *s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is greater than the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator >= (word_string)

Prototype  : bool operator >= (word_string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is greater than or equal to the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator >= (string)

Prototype  : bool operator >= (string& s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is greater than or equal to the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator >= (char *)

Prototype  : bool operator >= (char *s)
Parameters :
      Name : s
Description: comparison string

Returns    : TRUE if *this->ws_contents is greater than or equal to the comparison string, FALSE otherwise

This inline operator will compare the class data member ws_contents with the comparison string. Comparison is case-sensitive.

operator << (ostream, word_string)

Prototype  : friend ostream& operator << (ostream& out, const word_string& wstr)
Parameters :
      Name : out
Description: output stream

      Name : wstr
Description: output word string

Returns    : contents of the output word string within the output stream

This inline friend operator will format a word_string for C++ standard stream output.

length

Prototype  : int length(void)

Returns    : length of *this->ws_contents

This inline function will return the current length of the word string.

empty

Prototype  : bool empty(void)

Returns    : TRUE if *this->ws_contents is an empty string, FALSE otherwise

This function will determine if the word string is empty. Note that a word string consisting of all spaces is considered to be not empty.

clear

Prototype  : void clear(void)

This inline function will set *this->ws_contents to an empty string.

show

Prototype  : void show(void)

This function will display the contents of *this->ws_contents along with the word string length to the screen using cout.

substr

Prototype  : word_string substr(int pos, int len)
Parameters :
      Name : pos
Description: starting position

      Name : len
Description: extraction length

Returns    : extracted word string

This function will extract a portion of *this->ws_contents beginning at the starting position for extraction length number of bytes. Note that in keeping with C and C++ array indexing, the starting position starts at zero.

left

Prototype  : word_string left(int len = 1)
Parameters :
      Name : len
Description: extraction length

Returns    : extracted word string

This function will extract a word string ala BASIC, that is... starting from the beginning of *this->ws_contents for extraction length number of bytes. Note the default extraction length of one byte. If the requested extraction length exceeds the actual length of *this->ws_contents, the entire contents of *this->ws_contents will be returned.

right

Prototype  : word_string right(int len = 1)
Parameters :
      Name : len
Description: extraction length

Returns    : extracted word string

This function will extract a word string ala BASIC, that is... starting from the end of *this->ws_contents for extraction length number of bytes. Note the default extraction length of one byte. If the requested extraction length exceeds the actual length of *this->ws_contents, the entire contents of *this->ws_contents will be returned.

trim

Prototype  : word_string trim(void)

Returns    : trimed word string
C Function : trim

This function will remove all extraneous spaces from the beginning, end and between each word within *this->ws_contents and return the result. The contents of *this->ws_contents will not be affected.

ucase

Prototype  : word_string ucase(void)

Returns    : upper case word string
C Function : ucase

This function will force the contents of *this->ws_contents to upper case characters and return the result. The contents of *this->ws_contents will not be affected.

lcase

Prototype  : word_string lcase(void)

Returns    : lower case word string
C Function : none

This function will force the contents of *this->ws_contents to lower case characters and return the result. The contents of *this->ws_contents will not be affected.

words

Prototype  : int words(char delim = ' ')
Parameters :
      Name : delim
Description: word delimiter

Returns    : number of words
C Function : words

This function will count the number of word delimiter words in *this->ws_contents. Note that the default word delimiter is the space character.

indxword

Prototype  : int indxword(int which, char delim = ' ')
Parameters :
      Name : which
Description: requested word

      Name : delim
Description: word delimiter

Returns    : index or position of the word upon success, -1 otherwise
C Function : indxword

This function will determine the index or position of the requested word delimited by word delimiter within *this->ws_contents. The position returned will reflect the position of the first character of the word, not the delimiter before the word. Note that the default word delimiter is the space character and in keeping with C and C++ array indexing, the returned index starts at zero.

wordlen

Prototype  : int wordlen(int which, char delim = ' ')
Parameters :
      Name : which
Description: requested word

      Name : delim
Description: word delimiter

Returns    : length of the word upon success, -1 otherwise
C Function : wordlen

This function will determine the length of the requested word delimited by word delimiter within *this->ws_contents. The returned length does not include any delimiters. Note that the default word delimiter is the space character and it is valid to have a word length of zero characters.

word

Prototype  : bool word(word_string& outstr, int which = 1, char delim = ' ')
Parameters :
      Name : outstr
Description: extracted word

      Name : which
Description: requested word

      Name : delim
Description: word delimiter

Returns    : TRUE if extraction was successful, FALSE otherwise
C Function : word

This function will extract a specific word delimited by the word delimiter from the *this->ws_contents and place it into the extracted word. Note the default requested word is the first and the default word delimiter is the space character.

command_words

Prototype  : int command_words(void)

Returns    : number of command words upon success, zero otherwise
C Function : command_words

This function will count the number of command words within *this->ws_contents.

command_indxword

Prototype  : int command_indxword(int which)
Parameters :
      Name  : which
Description : command word number

Returns     : the position upon success, -1 otherwise
C Function : command_indxword

This function determines the index/position of a specific command word within *this->ws_contents. Note that it is valid to have a word of zero characters.

command_wordlen

Prototype  : int command_wordlen(int which)
Parameters :
      Name  : which
Description : command word number

Returns     : the length upon success, -1 otherwise
C Function : command_wordlen

This function determines the length of a specific command word within *this->ws_contents. Note that it is valid to have a word of zero characters.

command_word

Prototype  : bool command_word(word_string& o_string, int which)
Parameters :
      Name : o_string
Description: extracted command word

      Name : which
Description: requested command word

Returns    : TRUE if extraction was successful, FALSE otherwise
C Function : command_word

This function will extract a specific command word within *this->ws_contents. Note that it is valid to have a word of zero characters.

find

Prototype  : int find(word_string& sub)
Parameters :
      Name : sub
Description: search sub-string

Returns    : position/index upon success, -1 otherwise
C Function : sub_string

This function searches *this->ws_contents for the search sub-string. Note that the returned index is base zero (first position is zero) to conform to C/C++'s array indexing.

find_char

Prototype  : int find_char(char findch)
Parameters :
      Name : findch
Description: search character

Returns    : position/index upon success, -1 otherwise
C Function : none

This function will locate the first occurrence of the search character within *this->ws_contents.

command_worddel

Prototype  : bool command_worddel(int which)
Parameters :
      Name : which
Description: command word number

Returns    : TRUE upon success, FALSE otherwise
C Function : command_worddel

This function will delete a specific command word within *this->ws_contents.

worddel

Prototype  : bool worddel(int which = 1, char delim = ' ')
Parameters :
      Name : which
Description: word number

      Name : delim
Description: word delimiter

Returns    : TRUE upon success, FALSE otherwise
C Function : worddel

This function will delete a specific word delimiter word from *this->ws_contents. Note the default word number of one and the default word delimiter of the space character.

wordput

Prototype  : bool wordput(word_string& wdata, int which = 1, char delim = ' ')
Parameters :
      Name : wdata
Description: word data

      Name : which
Description: word number

      Name : delim
Description: word delimiter

Returns    : TRUE upon success, FALSE otherwise
C Function : ll_wordput

This function will place the word data into *this->ws_contents at the specific word number delimited by the word delimiter. If the specific word already exists, it will be replaced, if does not exist, the word string will be extended out to the required word before copying. Each word is delimited by the word delimiter. Note the default word number of one and the default word delimiter of the space character.

num

Prototype  : bool num(void)

Returns    : TRUE upon success, FALSE otherwise
C Function : num

This function evaluates *this->ws_contents to determine whether it is a valid number. Numbers are the digits 0-9. A minus sign is allowed in the first character. No other characters are allowed.

parse_extend

Prototype  : bool parse_extend(int which, char delim)
Parameters :
      Name : which
Description: word number

      Name : delim
Description: word delimiter

Returns    : TRUE upon success, FALSE otherwise
C Function : parse_extend

This function will extend *this->ws_contents out to the requested word number. Each word is delimited by the word delimiter. You may not extend using the space delimiter because of the nature of the space and the trim function.

str_replace

Prototype  : bool str_replace(int spos, word_string& wdata)
Parameters :
      Name : spos
Description: start position

      Name : wdata
Description: replacement data

Returns    : TRUE upon success, FALSE otherwise
C Function : none

This function will replace bytes in *this->ws_contents. Bytes from index start position will be replaced with content from the replacement data. Number of bytes replaced depends on length of the replacement data. Start position plus length of the replacement data cannot exceed length of *this->ws_contents.

Goto Top | C++ GPL Library Overview | C++ Overview
Future Lab Home | Contact Webmaster | Feedback

Copyright © 2000-2006 Future Lab, Last Updated Jun 29, 2006