| 8 | } |
| 9 | |
| 10 | void EditorconfigPattern::Compile(std::string_view pattern) { |
| 11 | _patternSource = pattern; |
| 12 | TextReader reader(_patternSource); |
| 13 | while (true) { |
| 14 | auto type = Lex(reader); |
| 15 | if (type == MatchType::Eof) { |
| 16 | break; |
| 17 | } |
| 18 | |
| 19 | auto &matchData = _matches.emplace_back(type); |
| 20 | auto text = reader.GetSaveText(); |
| 21 | switch (type) { |
| 22 | case MatchType::Path: { |
| 23 | matchData.String = text; |
| 24 | break; |
| 25 | } |
| 26 | case MatchType::AnyCharOf: { |
| 27 | if (text.size() > 2) { |
| 28 | text = text.substr(1, text.size() - 2); |
| 29 | matchData.CharSet = std::set<char>(text.begin(), text.end()); |
| 30 | } |
| 31 | break; |
| 32 | } |
| 33 | case MatchType::NotCharOf: { |
| 34 | if (text.size() > 3) { |
| 35 | text = text.substr(2, text.size() - 3); |
| 36 | matchData.CharSet = std::set<char>(text.begin(), text.end()); |
| 37 | } |
| 38 | break; |
| 39 | } |
| 40 | case MatchType::StringOf: { |
| 41 | if (text.size() > 2) { |
| 42 | text = text.substr(1, text.size() - 2); |
| 43 | matchData.Strings = string_util::Split(text, ","); |
| 44 | } |
| 45 | break; |
| 46 | } |
| 47 | default: { |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | EditorconfigPattern::MatchType EditorconfigPattern::Lex(TextReader &reader) { |
| 55 | reader.ResetBuffer(); |