1 /*
2    mkvmerge -- utility for splicing together matroska files
3    from component media subtypes
4 
5    Distributed under the GPL v2
6    see the file COPYING for details
7    or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
8 
9    IANA language subtag registry
10 
11    Written by Moritz Bunkus <moritz@bunkus.org>.
12 */
13 
14 #include "common/common_pch.h"
15 
16 #include "common/iana_language_subtag_registry.h"
17 #include "common/strings/formatting.h"
18 
19 namespace mtx::iana::language_subtag_registry {
20 
21 namespace {
22 
23 std::optional<entry_t>
look_up_entry(std::string const & s,std::vector<entry_t> const & entries)24 look_up_entry(std::string const &s,
25              std::vector<entry_t> const &entries) {
26   if (s.empty())
27     return {};
28 
29   auto s_lower = mtx::string::to_lower_ascii(s);
30   auto itr     = std::find_if(entries.begin(), entries.end(), [&s_lower](auto const &entry) {
31     return s_lower == mtx::string::to_lower_ascii(entry.code);
32   });
33 
34   if (itr != entries.end())
35     return *itr;
36 
37   return {};
38 }
39 
40 }
41 
42 std::optional<entry_t>
look_up_extlang(std::string const & s)43 look_up_extlang(std::string const &s) {
44   return look_up_entry(s, g_extlangs);
45 }
46 
47 std::optional<entry_t>
look_up_variant(std::string const & s)48 look_up_variant(std::string const &s) {
49   return look_up_entry(s, g_variants);
50 }
51 
52 } // namespace mtx::iana::language_subtag_registry
53