Tag Parser: localehelper.h Source File

Tag Parser 12.5.2 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
14 enum class LocaleFormat : std::uint64_t {
15 Unknown,
16 DomainCountry,
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);
30 LocaleFormat format = LocaleFormat::Unknown;
31 static const LocaleDetail &getEmpty();
32};
33
37 inline LocaleDetail::LocaleDetail()
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
78template <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
global.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::LocaleFormat
LocaleFormat
The LocaleFormat enum class specifies the format used by a LocaleDetail.
Definition localehelper.h:14
TagParser::LocaleFormat::BCP_47
@ BCP_47
Definition localehelper.h:20
TagParser::LocaleFormat::ISO_639_1
@ ISO_639_1
Definition localehelper.h:17
TagParser::LocaleFormat::ISO_639_2_T
@ ISO_639_2_T
Definition localehelper.h:18
TagParser::LocaleFormat::ISO_639_2_B
@ ISO_639_2_B
Definition localehelper.h:19
TagParser::LocaleFormat::Unknown
@ Unknown
Definition localehelper.h:15
TagParser::LocaleFormat::DomainCountry
@ DomainCountry
Definition localehelper.h:16
TagParser::StereoMode::Unknown
@ Unknown
Definition abstracttrack.h:77
TagParser::LocaleDetail
The LocaleDetail struct specifies a language and/or country.
Definition localehelper.h:26
TagParser::LocaleDetail::format
LocaleFormat format
Definition localehelper.h:30
TagParser::LocaleDetail::getEmpty
static const LocaleDetail & getEmpty()
Returns an empty LocaleDetail.
Definition localehelper.cpp:48
TagParser::LocaleDetail::LocaleDetail
LocaleDetail()
Constructs an empty LocaleDetail.
Definition localehelper.h:37
TagParser::Locale::abbreviatedName
const LocaleDetail & abbreviatedName(LocaleFormat format) const
Returns the abbreviated name of the specified format.
Definition localehelper.cpp:62
TagParser::Locale::Locale
Locale()=default
TagParser::Locale::fullOrSomeAbbreviatedName
const std::string & fullOrSomeAbbreviatedName() const
Returns the full name if possible and otherwise falls back to the abbreviated name.
Definition localehelper.cpp:124
TagParser::Locale::toString
std::string toString() const
Returns all details as comma-separated string.
Definition localehelper.cpp:135
TagParser::Locale::fullName
const std::string & fullName() const
Returns the full name of the locale, e.g.
Definition localehelper.cpp:110
TagParser::Locale::someAbbreviatedName
const LocaleDetail & someAbbreviatedName(LocaleFormat preferredFormat=LocaleFormat::BCP_47) const
Returns some abbreviated name, preferably of the specified preferredFormat.
Definition localehelper.cpp:85