cgv
Loading...
Searching...
No Matches
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
14namespace cgv {
15 namespace utils {
16
18struct line : public token
19{
21 line(const char* _b = 0, const char* _e = 0) : token(_b, _e) {}
22};
23
26 PLAIN, URL, FLOAT_VALUE, TIME_VALUE, DATE_VALUE
27};
28
33struct 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
74extern 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
84inline 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
100inline 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
115extern CGV_API void split_to_lines(const char* begin, const char* end,
116 std::vector<line>& lines,
117 bool truncate_trailing_spaces = true);
119inline 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
126inline 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
142extern CGV_API bool balanced_find_content(
143 const char* begin, const char* end,
144 token& content,
145 char open_parenthesis, char close_parenthesis);
146
147inline 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}
154inline 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
168extern CGV_API std::string strip_cpp_comments(const std::string& source, bool correct_new_lines = true);
169
170 }
171}
172
173#include <cgv/config/lib_end.h>
token_type
different types that a typed_token can have
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)
this function splits a text range into tokens.
void split_to_lines(const char *global_begin, const char *global_end, std::vector< line > &lines, bool truncate_trailing_spaces)
this function splits a text range at the newline characters into single lines.
std::string strip_cpp_comments(const std::string &source, bool correct_new_lines)
remove cpp-style comments from string
bool balanced_find_content(const char *begin, const char *end, token &content, char open_parenthesis, char close_parenthesis)
the input range must begin with an open parenthesis.
the cgv namespace
Definition print.h:11
Helper functions to process strings.
a line in a text is simply represented as a token
line(const char *_b=0, const char *_e=0)
construct from range
representation of a token in a text by two pointers begin and end, that point to the first character ...
Definition token.h:18
const char * begin
pointers that define the range of characters
Definition token.h:20
token()
construct with both pointers set to 0
Definition token.cxx:8
a typed token also stores the type and value of a parsed token.