1 /* 2 * Copyright (c) 2024 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #ifndef THIRD_PARTY_SKIA_HYPHENTRIE_H 17 #define THIRD_PARTY_SKIA_HYPHENTRIE_H 18 19 #ifdef ENABLE_TEXT_ENHANCE 20 #include <iostream> 21 #include <map> 22 #include <memory> 23 #include <string> 24 25 namespace skia { 26 namespace textlayout { 27 class TrieNode { 28 public: 29 std::map<char, std::shared_ptr<TrieNode>> children; 30 std::string value; 31 }; 32 33 class HyphenTrie { 34 public: HyphenTrie()35 HyphenTrie() { root = std::make_shared<TrieNode>(); }; 36 ~HyphenTrie() = default; 37 HyphenTrie(HyphenTrie&&) = delete; 38 HyphenTrie& operator=(HyphenTrie&&) = delete; 39 HyphenTrie(const HyphenTrie&) = delete; 40 HyphenTrie& operator=(const HyphenTrie&) = delete; 41 42 void insert(const std::string& key, const std::string& value); 43 std::string findPartialMatch(const std::string& keyPart); 44 45 private: 46 std::shared_ptr<TrieNode> root = nullptr; 47 48 std::string collectValues(const std::shared_ptr<TrieNode>& node); 49 }; 50 } // namespace textlayout 51 } // namespace skia 52 #endif // ENABLE_TEXT_ENHANCE 53 #endif // THIRD_PARTY_SKIA_HYPHENTRIE_H 54