/* * Copyright (c) 2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef OHOS_GLOBAL_DATE_TIME_RULE_H #define OHOS_GLOBAL_DATE_TIME_RULE_H #include #include #include #include #include #include #include "libxml/globals.h" #include "libxml/tree.h" #include "libxml/xmlstring.h" namespace OHOS { namespace Global { namespace I18n { class DateTimeRule { public: DateTimeRule(std::string& locale); ~DateTimeRule(); std::unordered_map GetUniverseRules(); std::unordered_map GetLocalesRules(); std::unordered_map GetLocalesRulesBackup(); std::unordered_map> GetSubRulesMap(); std::unordered_map GetSubRules(); std::unordered_map GetFilterRules(); std::unordered_map GetPastRules(); std::unordered_map GetParam(); std::unordered_map GetParamBackup(); std::unordered_map GetPatternsMap(); int CompareLevel(std::string& key1, std::string& key2); std::string Get(std::unordered_map& param, std::string& ruleName); std::string GetLocale(); bool IsRelDates(icu::UnicodeString& hyphen, std::string& locale); static std::string trim(const std::string& src); static bool CompareBeginEnd(const std::string src, const std::string target, bool flag); static std::string SubReplace(std::string& src, const std::string& subStr, const std::string& newStr); private: void Init(std::string& locale); void RuleLevel(); void InitRules(std::string& xmlPath); void InitRuleBackup(std::string& xmlPathBackup); void LoadStrToStr(std::unordered_map* map, xmlNodePtr cur); void LoadStrToPattern(std::unordered_map& map, xmlNodePtr cur); int GetLevel(std::string& name); std::string GetWithoutB(const std::string& ruleName); std::unordered_map universeRules; std::unordered_map localesRules; std::unordered_map localesRulesBackup; std::unordered_map> subRulesMap; std::unordered_map subRules; std::unordered_map filterRules; std::unordered_map pastRules; std::unordered_map levels; std::unordered_map delimiter; std::unordered_map relDates; std::unordered_map param; std::unordered_map paramBackup; std::unordered_map localeMap; std::unordered_map*> loadMap; std::unordered_map patternsMap; std::string locale; static std::string xmlCommonPath; }; } // namespace I18n } // namespace Global } // namespace OHOS #endif