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 PREFERENCES_UTILS_H 17 #define PREFERENCES_UTILS_H 18 19 #include <string> 20 21 #include "preferences_value.h" 22 23 namespace OHOS { 24 namespace NativePreferences { 25 class PreferencesUtils { 26 public: 27 /** 28 * @brief The constant Indicates the maximum length of the key in the preferences. 29 */ 30 static constexpr uint32_t MAX_KEY_LENGTH = 1024; 31 /** 32 * @brief The constant Indicates the maximum length of the value in the preferences. 33 */ 34 static constexpr uint32_t MAX_VALUE_LENGTH = 16 * 1024 * 1024; 35 36 static constexpr const char *STR_BROKEN = ".broken"; 37 static constexpr const char *STR_BACKUP = ".bak"; 38 static constexpr const char *STR_LOCK = ".lock"; 39 static constexpr const char *STR_QUERY = "?"; 40 static constexpr const char *STR_SLASH = "/"; 41 static constexpr const char *STR_SCHEME = "sharepreferences://"; 42 static constexpr const char *STR_OBJECT_FLAG = ".objectFlag"; 43 44 static std::string MakeFilePath(const std::string &prefPath, const std::string &suffix); 45 46 static int CheckKey(const std::string &key); 47 48 static int CheckValue(const PreferencesValue &value); 49 }; 50 } // End of namespace NativePreferences 51 } // End of namespace OHOS 52 #endif // End of #ifndef PREFERENCES_H 53