Tag Parser 12.5.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
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);
31 static const LocaleDetail &getEmpty();
32};
33
41
45inline LocaleDetail::LocaleDetail(std::string_view value, LocaleFormat format)
46 : std::string(value)
47 , format(format)
48{
49}
50
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;
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.
static const LocaleDetail & getEmpty()
Returns an empty LocaleDetail.
LocaleDetail()
Constructs an empty LocaleDetail.
const LocaleDetail & abbreviatedName(LocaleFormat format) const
Returns the abbreviated name of the specified format.
const std::string & fullOrSomeAbbreviatedName() const
Returns the full name if possible and otherwise falls back to the abbreviated name.
std::string toString() const
Returns all details as comma-separated string.
const std::string & fullName() const
Returns the full name of the locale, e.g.
const LocaleDetail & someAbbreviatedName(LocaleFormat preferredFormat=LocaleFormat::BCP_47) const
Returns some abbreviated name, preferably of the specified preferredFormat.