Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Examples  

Word Class Reference

A word is a sequence of lower case alphabetic characters. More...

#include <word.h>

List of all members.

Public Methods

 Word (const string &w="")
 Constructor. More...

 operator string () const
 Convert to string. More...

const string & str () const

Friends

istream & operator>> (istream &, Word &w)
 Read a word from a stream. More...

bool operator== (const Word &w1, const Word &w2)
bool operator< (const Word &w1, const Word &w2)


Detailed Description

A word is a sequence of lower case alphabetic characters.

The only way to obtain a non-empty wordt is via the input operator operator<<(istream &, Word &).

Examples:

test-stringpool.C, and test-word.C.

Definition at line 14 of file word.h.


Constructor & Destructor Documentation

Word::Word const string &    w = ""
 

Constructor.

Parameters:
w  initial underlying string.

Definition at line 5 of file word.C.

00005                             : w_(w) {
00006 }


Member Function Documentation

Word::operator string   const [inline]
 

Convert to string.

Definition at line 24 of file word.h.

00024 { return w_; }

const string& Word::str   const [inline]
 

Returns:
reference to underlying string.

Definition at line 28 of file word.h.

Referenced by operator>>().

00028 { return w_; }


Friends And Related Function Documentation

istream& operator>> istream &    is,
Word &    w
[friend]
 

Read a word from a stream.

Non-alhabetic characters before and after the word will be skipped.

Parameters:
is  stream to read from.
w  word that will be read (it is cleared beforehand).
Returns:
reference to is.

Definition at line 9 of file word.C.

00009                                  {
00010 w.w_.resize(0);
00011 char c(EOF);
00012 while (is.get(c) && ! isalpha(c))
00013   ;
00014 if ( isalpha(c) ) {
00015   do 
00016     w.w_ += tolower(c);
00017   while (is.get(c) && isalpha(c));
00018   // operation succeeded, so we want stream in ok state
00019   // otherwise is >> w would fail if w was followed in is by EOF 
00020   is.clear();
00021   }
00022 return is;
00023 }

bool operator== const Word &    w1,
const Word &    w2
[friend]
 

Definition at line 39 of file word.h.

00039 { return w1.w_ == w2.w_; }

bool operator< const Word &    w1,
const Word &    w2
[friend]
 

Definition at line 41 of file word.h.

00041 { return w1.w_ < w2.w_; }


The documentation for this class was generated from the following files:
textindexer-0.2 [27 March, 2002]