1 /* 2 * Copyright (c) 2021 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 #ifndef OHOS_RESOURCE_MANAGER_UTILS_H 16 #define OHOS_RESOURCE_MANAGER_UTILS_H 17 #include <cstddef> 18 #include <cstdint> 19 #include "res_locale.h" 20 #include "rstate.h" 21 22 namespace OHOS { 23 namespace Global { 24 namespace Resource { 25 class Utils { 26 public: 27 static bool IsAlphaString(const char *s, int32_t len); 28 29 static bool IsNumericString(const char *s, int32_t len); 30 31 static bool IsStrEmpty(const char *s); 32 33 static size_t StrLen(const char *s); 34 35 static uint16_t EncodeLanguage(const char *language); 36 37 static uint16_t EncodeLanguageByResLocale(const ResLocale *locale); 38 39 static uint32_t EncodeScript(const char *script); 40 41 static uint32_t EncodeScriptByResLocale(const ResLocale *locale); 42 43 static void DecodeScript(uint32_t encodeScript, char *outValue); 44 45 static uint16_t EncodeRegion(const char *region); 46 47 static uint16_t EncodeRegionByResLocale(const ResLocale *locale); 48 49 static uint64_t EncodeLocale(const char *language, 50 const char *script, 51 const char *region); 52 53 static RState ConvertColorToUInt32(const char *s, uint32_t &outValue); 54 55 private: 56 57 static uint16_t EncodeLanguageOrRegion(const char *str, char base); 58 59 static bool StrCompare(const char *left, const char *right, size_t len, bool isCaseSensitive); 60 static constexpr uint64_t ROOT_LOCALE = 0x0; 61 static constexpr uint16_t NULL_LANGUAGE = 0x00; 62 static constexpr uint16_t NULL_REGION = 0x00; 63 static constexpr uint16_t NULL_SCRIPT = 0x0000; 64 static constexpr uint64_t NULL_LOCALE = 0x0; 65 }; 66 } // namespace Resource 67 } // namespace Global 68 } // namespace OHOS 69 #endif