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_CODEPOINT_RANGE_H_ 18 #define LIBTEXTCLASSIFIER_UTILS_CODEPOINT_RANGE_H_ 19 20 #include <vector> 21 22 #include "utils/base/integral_types.h" 23 #include "utils/codepoint-range_generated.h" 24 25 namespace libtextclassifier3 { 26 27 // Represents a codepoint range [start, end). 28 struct CodepointRangeStruct { 29 int32 start; 30 int32 end; 31 CodepointRangeStructCodepointRangeStruct32 CodepointRangeStruct(int32 arg_start, int32 arg_end) 33 : start(arg_start), end(arg_end) {} 34 }; 35 36 // Returns a sorted list of the codepoint (also converts the flatbuffer to 37 // struct). 38 void SortCodepointRanges( 39 const std::vector<const CodepointRange*>& codepoint_ranges, 40 std::vector<CodepointRangeStruct>* sorted_codepoint_ranges); 41 42 // Returns true if given codepoint is covered by the given sorted vector of 43 // codepoint ranges. 44 bool IsCodepointInRanges( 45 int codepoint, const std::vector<CodepointRangeStruct>& codepoint_ranges); 46 47 } // namespace libtextclassifier3 48 49 #endif // LIBTEXTCLASSIFIER_UTILS_CODEPOINT_RANGE_H_ 50