WordIter.h

00001 #ifndef WORDITER_H
00002 #define WORDITER_H
00003 //****************************************************************************
00004 //
00005 // WordIter header.
00006 //
00007 // WordIter is a type definition that provides a word 
00008 // iterator over a string.
00009 //
00010 // It is a specialisation of TokenIter, using WordFinder 
00011 // to find the tokens.
00012 // 
00013 // WordFinder is a function object that finds a word token
00014 // in a string, using white space as the token delimiter.
00015 //
00016 //*****************************************************************************
00017 
00018 #if _MSC_VER > 1000
00019 #pragma once
00020 #endif // _MSC_VER > 1000
00021 
00022 #include "TokenIter.h"
00023 
00024 namespace token {
00025 
00026 class WordFinder
00027 {
00028 public:
00029         typedef TokenIter<WordFinder> WIter;
00030 
00031         size_t operator()(const char*& start, const char*& end)
00032         {
00033                 // Note: end initially points to beginning of string,
00034                 // start is undefined
00035 
00036                 // Skip whitespace up to next word
00037 
00038                 while (isspace(*end))
00039                         ++end;
00040 
00041                 start = end;
00042 
00043                 // Skip non-whitespace to end of word
00044 
00045                 while(*end != WIter::EndOfString && !isspace(*end))
00046                         ++end;
00047 
00048                 return (end - start);
00049         }
00050 };
00051 
00052 // Define WordIter
00053 
00054 typedef TokenIter<WordFinder>  WordIter;
00055 
00056 };
00057 
00058 #endif
00059 
00060 /* End of File */

Generated on Tue Aug 7 16:03:33 2007 for SOMCode by  doxygen 1.5.3