62 typedef std::shared_ptr<tld_string> pointer_t;
63 typedef std::map<std::string, pointer_t> map_by_string_t;
64 typedef std::map<string_id_t, pointer_t> map_by_id_t;
66 tld_string(string_id_t
id, std::string
const & s);
68 string_id_t get_id()
const;
69 std::string
const & get_string()
const;
70 std::string::size_type length()
const;
71 void set_found_in(string_id_t
id);
72 string_id_t get_found_in()
const;
75 string_id_t f_id = STRING_ID_NULL;
76 std::string f_string = std::string();
77 string_id_t f_found_in = STRING_ID_NULL;
84 string_id_t add_string(std::string
const & s);
85 string_id_t find_string(std::string
const & s);
86 std::string get_string(string_id_t
id)
const;
87 string_id_t get_next_string_id()
const;
88 std::size_t size()
const;
89 std::size_t max_length()
const;
90 std::size_t total_length()
const;
91 std::string
const & compressed_strings()
const;
92 std::size_t compressed_length()
const;
94 std::size_t included_count()
const;
95 std::size_t included_length()
const;
96 std::size_t merged_count()
const;
97 std::size_t merged_length()
const;
98 std::size_t get_string_offset(std::string
const & s)
const;
99 std::size_t get_string_offset(string_id_t
id)
const;
102 typedef std::set<string_id_t> set_id_t;
104 std::string::size_type end_start_match(
105 std::string
const & s1
106 , std::string
const & s2);
107 bool merge_two_strings();
109 string_id_t f_next_id = STRING_ID_NULL;
110 tld_string::map_by_string_t f_strings_by_string = tld_string::map_by_string_t();
111 tld_string::map_by_id_t f_strings_by_id = tld_string::map_by_id_t();
112 set_id_t f_strings_reviewed = set_id_t();
113 std::size_t f_max_length = 0;
114 std::size_t f_total_length = 0;
115 std::size_t f_included_count = 0;
116 std::size_t f_included_length = 0;
117 std::size_t f_merged_count = 0;
118 std::size_t f_merged_length = 0;
119 std::string f_merged_strings = std::string();
126 typedef std::vector<string_id_t> tags_table_t;
128 void add(tags_t
const & tags);
130 tags_table_t
const & merged_tags()
const;
131 std::size_t merged_size()
const;
132 std::size_t get_tag_offset(tags_t
const & tags)
const;
135 typedef std::vector<tags_table_t> tags_vector_t;
137 tags_table_t tags_to_table(tags_t
const & tags)
const;
138 std::size_t end_start_match(
139 tags_table_t
const & s1
140 , tags_table_t
const & s2);
142 tags_vector_t f_tags = tags_vector_t();
143 tags_table_t f_merged_tags = tags_table_t();
150 typedef std::shared_ptr<tld_definition> pointer_t;
151 typedef std::vector<string_id_t> segments_t;
152 typedef std::map<std::string, pointer_t> map_t;
154 static constexpr std::uint32_t SET_TLD = 0x0001;
155 static constexpr std::uint32_t SET_STATUS = 0x0002;
156 static constexpr std::uint32_t SET_APPLY_TO = 0x0080;
163 bool add_segment(std::string
const & segment, std::string & errmsg);
164 segments_t
const & get_segments()
const;
167 std::string get_parent_name()
const;
168 std::string get_parent_inverted_name()
const;
170 void set_index(
int idx);
171 int get_index()
const;
176 bool set_apply_to(std::string
const & apply_to);
177 std::string get_apply_to()
const;
180 std::string
const & tag_name
181 , std::string
const & value
182 , std::string & errmsg);
183 tags_t
const & get_tags()
const;
185 void reset_set_flags();
186 void set_named_parameter(
187 std::string
const & name
188 , std::string
const & value
189 , std::string & errmsg);
191 void set_start_offset(uint16_t start);
192 void set_end_offset(uint16_t end);
193 uint16_t get_start_offset()
const;
194 uint16_t get_end_offset()
const;
200 segments_t f_tld = segments_t();
203 std::string f_apply_to = std::string();
205 tags_t f_tags = tags_t();
207 uint16_t f_start_offset = USHRT_MAX;
208 uint16_t f_end_offset = USHRT_MAX;
215 void set_input_folder(std::string
const & path);
216 std::string
const & get_input_folder()
const;
217 void set_output(std::string
const & filename);
218 std::string
const & get_output()
const;
219 void set_c_file(std::string
const & filename);
220 std::string
const & get_c_file()
const;
222 int get_errno()
const;
223 std::string
const & get_errmsg()
const;
224 int get_line()
const;
225 std::string
const & get_filename()
const;
227 void output_to_json(std::ostream & out,
bool verbose)
const;
230 typedef std::vector<std::string> paths_t;
231 typedef std::vector<std::uint8_t> data_t;
232 typedef std::map<std::string, std::string> values_t;
234 static constexpr char32_t const CHAR_ERR =
static_cast<char32_t>(-2);
235 static constexpr char32_t const CHAR_EOF =
static_cast<char32_t>(-1);
248 TOKEN_OPEN_SQUARE_BRACKET,
249 TOKEN_CLOSE_SQUARE_BRACKET,
254 typedef std::vector<token> vector_t;
256 token(std::string
const & filename
259 , std::string
const & value);
261 std::string
const & get_filename()
const;
262 int get_line()
const;
263 token_t get_token()
const;
264 std::string
const & get_value()
const;
267 std::string
const f_filename;
268 int const f_line = 0;
269 token_t
const f_token = TOKEN_EOF;
270 std::string
const f_value = std::string();
273 void find_files(std::string
const & path);
274 void process_input_files();
275 void process_file(std::string
const & filename);
276 bool get_backslash(
char32_t & c);
278 bool is_space(
char32_t wc)
const;
280 void ungetc(
char32_t c);
281 bool append_wc(std::string & value,
char32_t wc);
283 void parse_variable();
286 void define_default_category();
288 void compress_tags();
289 uint16_t find_definition(std::string name)
const;
290 void output_tlds(std::ostream & out);
291 void save_to_file(std::string
const & buffer);
292 void output_header(std::ostream & out);
293 void save_to_c_file(std::string
const & buffer);
295 std::string f_input_folder =
"/usr/share/libtld/tlds";
296 std::string f_output =
"/var/lib/libtld/tlds.tld";
297 std::string f_c_file = std::string();
299 std::string f_errmsg = std::string();
300 paths_t f_input_files = paths_t();
301 values_t f_global_variables = values_t();
302 values_t f_global_tags = values_t();
303 std::string f_current_tld = std::string();
304 tld_definition::map_t f_definitions = tld_definition::map_t();
305 token::vector_t f_tokens = token::vector_t();
306 data_t f_data = data_t();
307 std::string::size_type f_pos = 0;
309 std::string f_filename = std::string();
310 char32_t f_ungetc[1] = {};
311 std::string::size_type f_ungetc_pos = 0;
313 string_id_t f_strings_count = 0;
315 time_t f_created_on = time(
nullptr);
316 uint8_t f_tld_max_level = 0;
317 uint16_t f_tld_start_offset = USHRT_MAX;
318 uint16_t f_tld_end_offset = USHRT_MAX;