1 /* 2 * Copyright (C) 2018 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef LIBTEXTCLASSIFIER_UTILS_REGEX_MATCH_H_ 18 #define LIBTEXTCLASSIFIER_UTILS_REGEX_MATCH_H_ 19 20 #include "utils/optional.h" 21 #include "utils/utf8/unilib.h" 22 23 namespace libtextclassifier3 { 24 25 // Returns text of a capturing group if the capturing group was fulfilled in 26 // the regex match. 27 Optional<std::string> GetCapturingGroupText(const UniLib::RegexMatcher* matcher, 28 const int group_id); 29 30 // Post-checks a regular expression match with a lua verifier script. 31 // The verifier can access: 32 // * `context`: The context as a string. 33 // * `match`: The groups of the regex match as an array, each group gives 34 // * `begin`: span start 35 // * `end`: span end 36 // * `text`: the text 37 // The verifier is expected to return a boolean, indicating whether the 38 // verification succeeded or not. 39 // Returns true if the verification was successful, false if not. 40 bool VerifyMatch(const std::string& context, 41 const UniLib::RegexMatcher* matcher, 42 const std::string& lua_verifier_code); 43 44 } // namespace libtextclassifier3 45 46 #endif // LIBTEXTCLASSIFIER_UTILS_REGEX_MATCH_H_ 47