-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathWordIter.h
59 lines (44 loc) · 1.47 KB
/
WordIter.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#if !defined(AFX_WORDITER_H_INCLUDED_)
#define AFX_WORDITER_H_INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#include <ctype.h>
#include <iterator>
#include <string>
class WordIter : public std::iterator<std::input_iterator_tag,
std::string>
{
private:
static const char END_OF_STRING;
char const *s;
char const *e;
int nLen;
void findword();
public:
static const WordIter EOS;
// Default ctor equal
// beyond-the-end.
WordIter() : s(&END_OF_STRING), e(&END_OF_STRING), nLen(0) {};
WordIter(char const * const S) : e(S) {findword();}
WordIter(const std::string S) : e(S.c_str()) {findword();}
WordIter& operator=(char const * const S)
{e=S; findword(); return(*this);}
std::string operator*() const
{return std::string(s, nLen);}
bool operator==(WordIter rhs) const
{
bool retv = false;
if (*s == *rhs.s)
if ( (*s==END_OF_STRING) || (s == rhs.s) )
retv = true;
return (retv);
}
bool operator!=(WordIter rhs) const
{return ! operator==(rhs); }
WordIter &operator++()
{findword(); return (*this);}
WordIter operator++(int)
{WordIter ret(*this);findword();return (ret);}
};
#endif // !defined(AFX_WORDITER_H_INCLUDED_)