1 /* 2 * tokenizer.h 3 * DIN Is Noise is copyright (c) 2006-2021 Jagannathan Sampath 4 * For more information, please visit http://dinisnoise.org/ 5 */ 6 7 8 // string tokenizer 9 // based on public domain code by Song Ho Ahn (song.ahn@gmail.com) 10 11 #ifndef TOKENIZER_H 12 #define TOKENIZER_H 13 14 #include <string> 15 #include <vector> 16 17 struct tokenizer { 18 19 static const std::string DEFAULT_DELIMITER; 20 21 tokenizer(); 22 tokenizer(const std::string& s, const std::string& d=DEFAULT_DELIMITER); 23 tokenizer (const std::vector<std::string>& tokens); 24 25 tokenizer& operator>> (std::string& s); 26 tokenizer& operator>> (float& f); 27 tokenizer& operator>> (double& d); 28 tokenizer& operator>> (int& i); 29 tokenizer& operator>> (char& c); 30 tokenizer& operator>> (unsigned char& c); 31 32 std::vector<std::string> tokens; 33 int tokens_available; 34 unsigned int tokid; 35 36 std::string delimiter; 37 std::string buffer; 38 int blen, dlen; 39 void str (const std::string& s); 40 void del (const std::string& d); 41 void vec (const std::vector<std::string>& v); 42 void set (const std::string& s, const std::string& d=DEFAULT_DELIMITER); 43 bool isdelim (char c); 44 45 void skip_ws (); 46 47 int cur; 48 void init_cur (); 49 50 std::string cur2end (); 51 52 std::string token; 53 54 }; 55 #endif 56