cgv
advanced_scan.h
Go to the documentation of this file.
1 #pragma once
2 
7 #include <vector>
8 
9 #include "token.h"
10 #include "scan.h"
11 
12 #include "lib_begin.h"
13 
14 namespace cgv {
15  namespace utils {
16 
18 struct line : public token
19 {
21  line(const char* _b = 0, const char* _e = 0) : token(_b, _e) {}
22 };
23 
25 enum token_type {
26  PLAIN, URL, FLOAT_VALUE, TIME_VALUE, DATE_VALUE
27 };
28 
33 struct typed_token : public token
34 {
35  token_type type;
36  typed_token(const token& t, token_type tt = PLAIN) : token(t), type(tt), date_value(0) {}
37  double float_value;
38  utils::time time_value;
39  utils::date date_value;
40 };
41 
74 extern CGV_API void split_to_tokens(
75  const char* begin, const char* end,
76  std::vector<token>& tokens,
77  const std::string& separators,
78  bool merge_separators = true,
79  const std::string& open_parenthesis = "", const std::string& close_parenthesis = "",
80  const std::string& whitespaces = " \t\n",
81  unsigned int max_nr_tokens = -1);
82 
84 inline void split_to_tokens(
85  const token& tok,
86  std::vector<token>& tokens,
87  const std::string& separators,
88  bool merge_separators = true,
89  const std::string& open_parenthesis = "", const std::string& close_parenthesis = "",
90  const std::string& whitespaces = " \t\n",
91  unsigned int /*max_nr_tokens*/ = -1)
92 {
94  tok.begin,tok.end,
95  tokens,
96  separators,merge_separators,open_parenthesis,close_parenthesis,whitespaces);
97 }
98 
100 inline void split_to_tokens(
101  const std::string& s,
102  std::vector<token>& tokens,
103  const std::string& separators,
104  bool merge_separators = true,
105  const std::string& open_parenthesis = "", const std::string& close_parenthesis = "",
106  const std::string& whitespaces = " \t\n",
107  unsigned int /*max_nr_tokens*/ = (unsigned int)-1)
108 {
109  split_to_tokens(&s[0],&s[0]+s.size(),tokens,separators,merge_separators,open_parenthesis,close_parenthesis,whitespaces);
110 }
111 
115 extern CGV_API void split_to_lines(const char* begin, const char* end,
116  std::vector<line>& lines,
117  bool truncate_trailing_spaces = true);
119 inline void split_to_lines(const token& tok,
120  std::vector<line>& lines,
121  bool truncate_trailing_spaces = true) {
122  split_to_lines(tok.begin,tok.end,lines,truncate_trailing_spaces);
123 }
124 
126 inline void split_to_lines(const std::string& s,
127  std::vector<line>& lines,
128  bool truncate_trailing_spaces = true) {
129  split_to_lines(&s[0],&s[0]+s.size(),lines,truncate_trailing_spaces);
130 }
131 
142 extern CGV_API bool balanced_find_content(
143  const char* begin, const char* end,
144  token& content,
145  char open_parenthesis, char close_parenthesis);
146 
147 inline bool balanced_find_content(
148  const token& expression,
149  token& content,
150  char open_parenthesis, char close_parenthesis) {
151  return balanced_find_content(expression.begin, expression.end,
152  content,open_parenthesis,close_parenthesis);
153 }
154 inline bool balanced_find_content(
155  const std::string& expression,
156  token& content,
157  char open_parenthesis, char close_parenthesis) {
158  return balanced_find_content(&expression[0], &expression[0]+expression.size(),
159  content,open_parenthesis,close_parenthesis);
160 }
161 
162  }
163 }
164 
165 #include <cgv/config/lib_end.h>
scan.h
cgv::utils::token_type
token_type
different types that a typed_token can have
Definition: advanced_scan.h:25
cgv::utils::token
Definition: token.h:16
cgv::utils::split_to_lines
void split_to_lines(const char *global_begin, const char *global_end, std::vector< line > &lines, bool truncate_trailing_spaces)
Definition: advanced_scan.cxx:65
cgv::utils::balanced_find_content
bool balanced_find_content(const char *begin, const char *end, token &content, char open_parenthesis, char close_parenthesis)
Definition: advanced_scan.cxx:87
cgv::utils::line
Definition: advanced_scan.h:19
cgv::utils::token::begin
const char * begin
pointers that define the range of characters
Definition: token.h:18
cgv::utils::token::token
token()
construct with both pointers set to 0
Definition: token.cxx:8
cgv::utils::typed_token
Definition: advanced_scan.h:34
cgv::utils::split_to_tokens
void split_to_tokens(const char *begin, const char *end, std::vector< token > &tokens, const std::string &separators, bool merge_separators, const std::string &open_parenthesis, const std::string &close_parenthesis, const std::string &whitespaces, unsigned int max_nr_tokens)
Definition: advanced_scan.cxx:6
cgv
the cgv namespace
Definition: vr_calib.cxx:9
cgv::utils::line::line
line(const char *_b=0, const char *_e=0)
construct from range
Definition: advanced_scan.h:21