cgv
Loading...
Searching...
No Matches
tokenizer.h
1#pragma once
2
3#include <vector>
4
5#include "token.h"
6
7#include "lib_begin.h"
8
9namespace cgv {
10 namespace utils {
11
67class CGV_API tokenizer : public token
68{
69protected:
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);
81public:
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
121inline 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>
the tokenizer allows to split text into tokens in a convenient way.
Definition tokenizer.h:68
bool skip_ws_check_empty()
skip whitespaces at the front and return whether the complete text has been processed
Definition tokenizer.h:111
bool reverse_skip_ws_check_empty()
skip whitespaces at the back and return whether the complete text has been processed
Definition tokenizer.h:113
token bite()
bite away a single token from the front
void bite_all(tokenizer &t, std::vector< token > &result)
bite all tokens into a token vector
Definition tokenizer.h:121
the cgv namespace
Definition print.h:11
representation of a token in a text by two pointers begin and end, that point to the first character ...
Definition token.h:18