aboutsummaryrefslogtreecommitdiffstats
path: root/yql/essentials/core/url_preprocessing/pattern_group.cpp
blob: 8185a84a7f184ddb58c0b89c05184889cd41c2f4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include "pattern_group.h"

namespace NYql {

void TPatternGroup::Add(const TString& pattern, const TString& alias) {
    auto it = CompiledPatterns.find(pattern);
    if (it != CompiledPatterns.end()) {
        return;
    }

    CompiledPatterns.emplace(pattern, std::make_pair(TRegExMatch(pattern), alias));
}

bool TPatternGroup::IsEmpty() const {
    return CompiledPatterns.empty();
}

TMaybe<TString> TPatternGroup::Match(const TString& s) const {
    for (auto& p : CompiledPatterns) {
        if (p.second.first.Match(s.c_str())) {
            return p.second.second;
        }
    }

    return Nothing();
}

}