mirror of
https://gitlab.com/mbunkus/mkvtoolnix.git
synced 2024-12-25 04:11:44 +00:00
BCP 47: sort extensions by their identifier
This commit is contained in:
parent
487574a3d7
commit
cac5d587fd
@ -28,6 +28,12 @@
|
||||
|
||||
namespace mtx::bcp47 {
|
||||
|
||||
bool
|
||||
operator <(language_c::extension_t const &a,
|
||||
language_c::extension_t const &b) {
|
||||
return mtx::string::to_lower_ascii(a.singleton) < mtx::string::to_lower_ascii(b.singleton);
|
||||
}
|
||||
|
||||
bool language_c::ms_disabled = false;
|
||||
|
||||
language_c::extension_t::extension_t(std::string const &singleton_,
|
||||
@ -255,6 +261,8 @@ language_c::parse_extensions(std::string const &str) {
|
||||
else
|
||||
m_extensions.back().extensions.emplace_back(part);
|
||||
|
||||
std::sort(m_extensions.begin(), m_extensions.end());
|
||||
|
||||
return validate_extensions();
|
||||
}
|
||||
|
||||
@ -543,7 +551,8 @@ language_c::add_extension(extension_t const &extension) {
|
||||
for (auto const &extension_subtag : extension.extensions)
|
||||
extensions_lower.emplace_back(mtx::string::to_lower_ascii(extension_subtag));
|
||||
|
||||
m_extensions.emplace_back(extension_t{ mtx::string::to_lower_ascii(extension.singleton), extensions_lower });
|
||||
auto cleaned_extension = extension_t{ mtx::string::to_lower_ascii(extension.singleton), extensions_lower };
|
||||
m_extensions.insert(std::lower_bound(m_extensions.begin(), m_extensions.end(), cleaned_extension), cleaned_extension);
|
||||
|
||||
m_formatted_up_to_date = false;
|
||||
|
||||
|
@ -329,4 +329,9 @@ TEST(BCP47LanguageTags, ExtensionsRFC6497) {
|
||||
EXPECT_TRUE(mtx::bcp47::language_c::parse("ja-t-it-m0-xxx-v21a-2007").is_valid());
|
||||
}
|
||||
|
||||
TEST(BCP47LanguageTags, ExtensionsFormatting) {
|
||||
EXPECT_EQ("ja-t-test-u-attr-co-phonebk"s, mtx::bcp47::language_c::parse("ja-T-Test-U-AttR-CO-phoNEbk").format());
|
||||
EXPECT_EQ("ja-t-test-u-attr-co-phonebk"s, mtx::bcp47::language_c::parse("ja-U-AttR-CO-phoNEbk-T-Test").format());
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user