Tag Parser  10.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
localehelper.h
Go to the documentation of this file.
1 #ifndef TAG_PARSER_LANGUAGE_H
2 #define TAG_PARSER_LANGUAGE_H
3 
4 #include "./global.h"
5 
6 #include <cstdint>
7 #include <string>
8 #include <utility>
9 #include <vector>
10 
11 namespace TagParser {
12 
14 enum class LocaleFormat : std::uint64_t {
15  Unknown,
17  ISO_639_1,
18  ISO_639_2_T,
19  ISO_639_2_B,
20  BCP_47,
23 };
24 
26 struct TAG_PARSER_EXPORT LocaleDetail : public std::string {
27  explicit LocaleDetail();
28  explicit LocaleDetail(std::string_view value, LocaleFormat format);
29  explicit LocaleDetail(std::string &&value, LocaleFormat format);
31  static const LocaleDetail &getEmpty();
32 };
33 
38  : format(LocaleFormat::Unknown)
39 {
40 }
41 
45 inline LocaleDetail::LocaleDetail(std::string_view value, LocaleFormat format)
46  : std::string(value)
47  , format(format)
48 {
49 }
50 
54 inline LocaleDetail::LocaleDetail(std::string &&value, LocaleFormat format)
55  : std::string(std::move(value))
56  , format(format)
57 {
58 }
59 
61 struct TAG_PARSER_EXPORT Locale : public std::vector<LocaleDetail> {
62  explicit Locale() = default;
63  explicit Locale(std::initializer_list<LocaleDetail> details);
64  explicit Locale(std::string &&value, LocaleFormat format);
65  explicit Locale(std::string_view value, LocaleFormat format);
66  const LocaleDetail &abbreviatedName(LocaleFormat format) const;
67  template <typename LocaleFormat, typename... LocaleFormats>
68  const LocaleDetail &abbreviatedName(LocaleFormat format, LocaleFormats... moreFormats) const;
69  const LocaleDetail &someAbbreviatedName(LocaleFormat preferredFormat = LocaleFormat::BCP_47) const;
70  const std::string &fullName() const;
71  const std::string &fullOrSomeAbbreviatedName() const;
72  std::string toString() const;
73 };
74 
78 template <typename LocaleFormat, typename... LocaleFormats>
79 inline const LocaleDetail &Locale::abbreviatedName(LocaleFormat format, LocaleFormats... moreFormats) const
80 {
81  if (const auto &detail = abbreviatedName(format); !detail.empty()) {
82  return detail;
83  } else {
84  return abbreviatedName(moreFormats...);
85  }
86 }
87 
91 inline Locale::Locale(std::initializer_list<LocaleDetail> details)
92  : std::vector<LocaleDetail>(details)
93 {
94 }
95 
99 inline Locale::Locale(std::string &&value, LocaleFormat format)
100  : std::vector<LocaleDetail>()
101 {
102  emplace_back(std::move(value), format);
103 }
104 
108 inline Locale::Locale(std::string_view value, LocaleFormat format)
109  : std::vector<LocaleDetail>()
110 {
111  emplace_back(value, format);
112 }
113 
114 } // namespace TagParser
115 
116 #endif // TAG_PARSER_LANGUAGE_H
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
LocaleFormat
The LocaleFormat enum class specifies the format used by a LocaleDetail.
Definition: localehelper.h:14
The LocaleDetail struct specifies a language and/or country.
Definition: localehelper.h:26
LocaleDetail()
Constructs an empty LocaleDetail.
Definition: localehelper.h:37
The Locale struct specifies a language and/or a country using one or more LocaleDetail objects.
Definition: localehelper.h:61
const LocaleDetail & abbreviatedName(LocaleFormat format) const
Returns the abbreviated name of the specified format.