cgv
tokenizer.h
1 #pragma once
2 
3 #include <vector>
4 
5 #include "token.h"
6 
7 #include "lib_begin.h"
8 
9 namespace cgv {
10  namespace utils {
11 
67 class CGV_API tokenizer : public token
68 {
69 protected:
70  std::string separators;
71  bool merge_separators;
72  std::string begin_skip;
73  std::string end_skip;
74  std::string escape_skip;
75  std::string whitespaces;
76  void init();
77  bool handle_skip(token& result);
78  bool handle_separators(token& result,bool check_skip=true);
79  bool reverse_handle_skip(token& result);
80  bool reverse_handle_separators(token& result,bool check_skip=true);
81 public:
83  tokenizer();
85  tokenizer(const token&);
87  tokenizer(const char*);
89  tokenizer(const std::string&);
91  tokenizer& set_ws(const std::string& ws);
93  tokenizer& set_skip(const std::string& open, const std::string& close);
95  tokenizer& set_skip(const std::string& open, const std::string& close, const std::string& escape);
97  tokenizer& set_sep(const std::string& sep, bool merge);
99  tokenizer& set_sep(const std::string& sep);
101  tokenizer& set_sep_merge(bool merge);
103  token bite();
105  token reverse_bite();
107  void reverse_skip_whitespaces();
109  void skip_whitespaces();
111  bool skip_ws_check_empty() { skip_whitespaces(); return empty(); }
113  bool reverse_skip_ws_check_empty() { reverse_skip_whitespaces(); return empty(); }
115  bool balanced_bite(token& result, const std::string& open_parenthesis, const std::string& close_parenthesis, bool wait_for_sep = false);
117  void bite_all(std::vector<token>& result);
118 };
119 
121 inline void bite_all(tokenizer& t, std::vector<token>& result) { while(!t.skip_ws_check_empty())result.push_back(t.bite()); }
122 
123  }
124 }
125 
126 #include <cgv/config/lib_end.h>
cgv::utils::tokenizer
Definition: tokenizer.h:68
cgv::utils::tokenizer::reverse_skip_ws_check_empty
bool reverse_skip_ws_check_empty()
skip whitespaces at the back and return whether the complete text has been processed
Definition: tokenizer.h:113
cgv::utils::token
Definition: token.h:16
cgv::utils::tokenizer::skip_ws_check_empty
bool skip_ws_check_empty()
skip whitespaces at the front and return whether the complete text has been processed
Definition: tokenizer.h:111
cgv::utils::tokenizer::bite
token bite()
bite away a single token from the front
Definition: tokenizer.cxx:179
cgv::utils::bite_all
void bite_all(tokenizer &t, std::vector< token > &result)
bite all tokens into a token vector
Definition: tokenizer.h:121
cgv
the cgv namespace
Definition: vr_calib.cxx:9