Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
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
11namespace TagParser {
12
14enum class LocaleFormat : std::uint64_t {
15 Unknown,
17 ISO_639_1,
20 BCP_47,
23};
24
26struct 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);
30 LocaleFormat format = LocaleFormat::Unknown;
31 static const LocaleDetail &getEmpty();
32};
33
38 : format(LocaleFormat::Unknown)
39{
40}
41
45inline LocaleDetail::LocaleDetail(std::string_view value, LocaleFormat format)
46 : std::string(value)
47 , format(format)
48{
49}
50
54inline LocaleDetail::LocaleDetail(std::string &&value, LocaleFormat format)
55 : std::string(std::move(value))
56 , format(format)
57{
58}
59
61struct 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
78template <typename LocaleFormat, typename... LocaleFormats>
79inline 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
91inline Locale::Locale(std::initializer_list<LocaleDetail> details)
92 : std::vector<LocaleDetail>(details)
93{
94}
95
99inline Locale::Locale(std::string &&value, LocaleFormat format)
100 : std::vector<LocaleDetail>()
101{
102 emplace_back(std::move(value), format);
103}
104
108inline 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.
Definition global.h:14
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.
The LocaleDetail struct specifies a language and/or country.
LocaleDetail()
Constructs an empty LocaleDetail.
The Locale struct specifies a language and/or a country using one or more LocaleDetail objects.
const LocaleDetail & abbreviatedName(LocaleFormat format) const
Returns the abbreviated name of the specified format.
const std::string & fullName() const