• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2018 The Android Open Source Project
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 
17 #ifndef LIBTEXTCLASSIFIER_UTILS_I18N_LOCALE_LIST_H_
18 #define LIBTEXTCLASSIFIER_UTILS_I18N_LOCALE_LIST_H_
19 
20 #include <string>
21 
22 #include "utils/i18n/locale.h"
23 #include "utils/strings/split.h"
24 
25 namespace libtextclassifier3 {
26 
27 // Parses and hold data about locales (combined by delimiter ',').
28 class LocaleList {
29  public:
30   // Constructs the
31   //  - Collection of locale tag from local_tags
32   //  - Collection of Locale objects from a valid BCP47 tag. (If the tag is
33   //    invalid, an object is created but return false for IsInvalid() call.
34   //  - Assigns the first parsed locale to reference_locale.
35   static LocaleList ParseFrom(const std::string& locale_tags);
36 
GetLocales()37   std::vector<Locale> GetLocales() const { return locales_; }
GetLocaleTags()38   std::vector<StringPiece> GetLocaleTags() const { return split_locales_; }
GetReferenceLocale()39   std::string GetReferenceLocale() const { return reference_locale_; }
40 
41  private:
LocaleList(const std::vector<Locale> & locales,const std::vector<StringPiece> & split_locales,const StringPiece & reference_locale)42   LocaleList(const std::vector<Locale>& locales,
43              const std::vector<StringPiece>& split_locales,
44              const StringPiece& reference_locale)
45       : locales_(locales),
46         split_locales_(split_locales),
47         reference_locale_(reference_locale.ToString()) {}
48 
49   const std::vector<Locale> locales_;
50   const std::vector<StringPiece> split_locales_;
51   const std::string reference_locale_;
52 };
53 }  // namespace libtextclassifier3
54 
55 #endif  // LIBTEXTCLASSIFIER_UTILS_I18N_LOCALE_LIST_H_
56