mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-25 04:11:44 +00:00
BCP 47: format includes all components even if language is empty
Before there was a shortcut: if language is empty, only private use was formatted as that's the only possible way to produce a valid tag. However, the GUI uses formatting of potentially invalid tags and then parsing them again as a test for validity. Therefore the formatting function must always format all individual components. Fixes #2924.
This commit is contained in:
parent
093f53e007
commit
7d24542a7d
4
NEWS.md
4
NEWS.md
@ -12,6 +12,10 @@
|
|||||||
* MKVToolNix GUI: IETF BCP 47 language tags: the "variants" combo-boxes were
|
* MKVToolNix GUI: IETF BCP 47 language tags: the "variants" combo-boxes were
|
||||||
not populated even when the language tag was valid and contained at a
|
not populated even when the language tag was valid and contained at a
|
||||||
variant. Fixes #2923.
|
variant. Fixes #2923.
|
||||||
|
* MKVToolNix GUI: IETF BCP 47 language tags: when no language is selected, at
|
||||||
|
least one of the other components (extended subtags, region, or variants)
|
||||||
|
has something selected and "private use" is not empty, the GUI would claim
|
||||||
|
this to be a valid tag, which it isn't. Fixes #2924.
|
||||||
|
|
||||||
|
|
||||||
# Version 50.0.0 "Awakenings" 2020-09-06
|
# Version 50.0.0 "Awakenings" 2020-09-06
|
||||||
|
@ -79,15 +79,6 @@ language_c::format_internal(bool force)
|
|||||||
if (!m_valid && !force)
|
if (!m_valid && !force)
|
||||||
return {};
|
return {};
|
||||||
|
|
||||||
if (m_language.empty()) {
|
|
||||||
auto output = "x"s;
|
|
||||||
|
|
||||||
for (auto const &private_use : m_private_use)
|
|
||||||
output += fmt::format("-{}", mtx::string::to_lower_ascii(private_use));
|
|
||||||
|
|
||||||
return output;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto output = mtx::string::to_lower_ascii(m_language);
|
auto output = mtx::string::to_lower_ascii(m_language);
|
||||||
|
|
||||||
for (auto const &subtag : m_extended_language_subtags)
|
for (auto const &subtag : m_extended_language_subtags)
|
||||||
@ -106,7 +97,11 @@ language_c::format_internal(bool force)
|
|||||||
output += fmt::format("-{}", mtx::string::to_lower_ascii(extension));
|
output += fmt::format("-{}", mtx::string::to_lower_ascii(extension));
|
||||||
|
|
||||||
if (!m_private_use.empty()) {
|
if (!m_private_use.empty()) {
|
||||||
output += "-x";
|
if (!output.empty())
|
||||||
|
output += "-";
|
||||||
|
|
||||||
|
output += "x";
|
||||||
|
|
||||||
for (auto const &private_use : m_private_use)
|
for (auto const &private_use : m_private_use)
|
||||||
output += fmt::format("-{}", mtx::string::to_lower_ascii(private_use));
|
output += fmt::format("-{}", mtx::string::to_lower_ascii(private_use));
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,16 @@ TEST(BCP47LanguageTags, Formatting) {
|
|||||||
EXPECT_EQ("x-weee-wooo"s, l.format_long(true));
|
EXPECT_EQ("x-weee-wooo"s, l.format_long(true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST(BCP47LanguageTags, FormattingInvalidWithoutLanguage) {
|
||||||
|
auto l = mtx::bcp47::language_c{};
|
||||||
|
|
||||||
|
l.set_region("FR"s);
|
||||||
|
l.set_private_use({ "moo"s });
|
||||||
|
|
||||||
|
EXPECT_EQ(""s, l.format());
|
||||||
|
EXPECT_EQ("-FR-x-moo"s, l.format(true));
|
||||||
|
}
|
||||||
|
|
||||||
TEST(BCP47LanguageTags, CodeConversion) {
|
TEST(BCP47LanguageTags, CodeConversion) {
|
||||||
EXPECT_EQ(""s, mtx::bcp47::language_c{}.get_iso639_2_code());
|
EXPECT_EQ(""s, mtx::bcp47::language_c{}.get_iso639_2_code());
|
||||||
EXPECT_EQ("ger"s, mtx::bcp47::language_c::parse("de").get_iso639_2_code());
|
EXPECT_EQ("ger"s, mtx::bcp47::language_c::parse("de").get_iso639_2_code());
|
||||||
|
Loading…
Reference in New Issue
Block a user