Line data Source code
1 : #include "string_reader.hpp"
2 :
3 : namespace wren::utils {
4 :
5 3 : void StringReader::skip_to_text_end(const std::string_view& text) {
6 3 : const auto size = text.size();
7 3 : position_ = input_.find(text, position_) + size;
8 3 : }
9 :
10 1 : void StringReader::skip_to_end_line() {
11 1 : auto pos = input_.find("\n", position_);
12 1 : position_ = pos + 1;
13 1 : }
14 :
15 2 : auto StringReader::read_to_end_line() -> std::string_view {
16 2 : auto pos = input_.find("\n", position_);
17 :
18 2 : const auto text = substr(position_, pos);
19 2 : position_ = pos + 1;
20 2 : return text;
21 : }
22 :
23 2 : auto StringReader::read_to_text_start(const std::string_view& text)
24 : -> std::string_view {
25 2 : auto end = input_.find(text, position_);
26 :
27 2 : const auto content = substr(position_, end);
28 2 : position_ = end;
29 2 : return content;
30 : }
31 :
32 1 : auto StringReader::read_to_text_end(const std::string_view& text)
33 : -> std::string_view {
34 1 : auto end = input_.find(text, position_) + text.size();
35 :
36 1 : const auto content = substr(position_, end);
37 1 : position_ = end;
38 1 : return content;
39 : }
40 :
41 5 : auto StringReader::substr(std::string_view::size_type start,
42 : std::string_view::size_type end) -> std::string_view {
43 5 : return input_.substr(start, end - start);
44 : }
45 :
46 : } // namespace wren::utils
|