pattern_group.cpp 621 B

12345678910111213141516171819202122232425262728
  1. #include "pattern_group.h"
  2. namespace NYql {
  3. void TPatternGroup::Add(const TString& pattern, const TString& alias) {
  4. auto it = CompiledPatterns.find(pattern);
  5. if (it != CompiledPatterns.end()) {
  6. return;
  7. }
  8. CompiledPatterns.emplace(pattern, std::make_pair(TRegExMatch(pattern), alias));
  9. }
  10. bool TPatternGroup::IsEmpty() const {
  11. return CompiledPatterns.empty();
  12. }
  13. TMaybe<TString> TPatternGroup::Match(const TString& s) const {
  14. for (auto& p : CompiledPatterns) {
  15. if (p.second.first.Match(s.c_str())) {
  16. return p.second.second;
  17. }
  18. }
  19. return Nothing();
  20. }
  21. }