2 * Copyright (C) 2015 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 #ifndef AAPT_LOCALE_VALUE_H
18 #define AAPT_LOCALE_VALUE_H
23 #include "androidfw/ResourceTypes.h"
24 #include "androidfw/StringPiece.h"
29 * A convenience class to build and parse locales.
40 * Initialize this LocaleValue from a config string.
42 bool InitFromFilterString(const android::StringPiece& config);
45 * Initialize this LocaleValue from parts of a vector.
47 ssize_t InitFromParts(std::vector<std::string>::iterator iter,
48 std::vector<std::string>::iterator end);
51 * Initialize this LocaleValue from a ResTable_config.
53 void InitFromResTable(const android::ResTable_config& config);
56 * Set the locale in a ResTable_config from this LocaleValue.
58 void WriteTo(android::ResTable_config* out) const;
60 inline int compare(const LocaleValue& other) const;
62 inline bool operator<(const LocaleValue& o) const;
63 inline bool operator<=(const LocaleValue& o) const;
64 inline bool operator==(const LocaleValue& o) const;
65 inline bool operator!=(const LocaleValue& o) const;
66 inline bool operator>=(const LocaleValue& o) const;
67 inline bool operator>(const LocaleValue& o) const;
70 void set_language(const char* language);
71 void set_region(const char* language);
72 void set_script(const char* script);
73 void set_variant(const char* variant);
80 LocaleValue::LocaleValue() { memset(this, 0, sizeof(LocaleValue)); }
82 int LocaleValue::compare(const LocaleValue& other) const {
83 return memcmp(this, &other, sizeof(LocaleValue));
86 bool LocaleValue::operator<(const LocaleValue& o) const {
87 return compare(o) < 0;
90 bool LocaleValue::operator<=(const LocaleValue& o) const {
91 return compare(o) <= 0;
94 bool LocaleValue::operator==(const LocaleValue& o) const {
95 return compare(o) == 0;
98 bool LocaleValue::operator!=(const LocaleValue& o) const {
99 return compare(o) != 0;
102 bool LocaleValue::operator>=(const LocaleValue& o) const {
103 return compare(o) >= 0;
106 bool LocaleValue::operator>(const LocaleValue& o) const {
107 return compare(o) > 0;
112 #endif // AAPT_LOCALE_VALUE_H