| 1 | 
gezelter | 
1334 | 
//: C07:StreamTokenizer.hpp | 
| 2 | 
  | 
  | 
// From "Thinking in C++, 2nd Edition, Volume 2" | 
| 3 | 
  | 
  | 
// by Bruce Eckel & Chuck Allison, (c) 2001 MindView, Inc. | 
| 4 | 
  | 
  | 
// Available at www.BruceEckel.com. | 
| 5 | 
  | 
  | 
// C++ Replacement for Standard C strtok() | 
| 6 | 
  | 
  | 
 | 
| 7 | 
  | 
  | 
#ifndef STREAMTOKENIZER_H | 
| 8 | 
  | 
  | 
#define STREAMTOKENIZER_H | 
| 9 | 
  | 
  | 
#include <string> | 
| 10 | 
  | 
  | 
#include <iostream> | 
| 11 | 
  | 
  | 
#include <iterator> | 
| 12 | 
  | 
  | 
 | 
| 13 | 
  | 
  | 
class StreamTokenizer { | 
| 14 | 
  | 
  | 
  typedef std::istreambuf_iterator<char> It; | 
| 15 | 
  | 
  | 
  It p, end; | 
| 16 | 
  | 
  | 
  std::string delimiters; | 
| 17 | 
  | 
  | 
  bool isDelimiter(char c) { | 
| 18 | 
  | 
  | 
    return  | 
| 19 | 
  | 
  | 
      delimiters.find(c) != std::string::npos; | 
| 20 | 
  | 
  | 
  } | 
| 21 | 
  | 
  | 
public: | 
| 22 | 
  | 
  | 
  StreamTokenizer(std::istream& is,  | 
| 23 | 
  | 
  | 
                  std::string delim = " \t\n;()\"<>:{}[]+-=&*#" | 
| 24 | 
  | 
  | 
                  ".,/\\~!0123456789") : p(is), end(It()), | 
| 25 | 
  | 
  | 
                                         delimiters(delim) {} | 
| 26 | 
  | 
  | 
  std::string next(); // Get next token | 
| 27 | 
  | 
  | 
}; | 
| 28 | 
  | 
  | 
#endif STREAMTOKENIZER_H |