2020-06-28 12:04:57 +00:00
|
|
|
def create_iso15924_script_list_file
|
2022-03-24 20:39:23 +00:00
|
|
|
content = Mtx::OnlineFile.download("https://unicode.org/iso15924/iso15924.txt")
|
2020-06-28 12:04:57 +00:00
|
|
|
|
2022-03-26 11:14:31 +00:00
|
|
|
entries = content.
|
2021-07-17 09:18:07 +00:00
|
|
|
force_encoding("UTF-8").
|
|
|
|
split(%r{\n+}).
|
2020-06-28 12:04:57 +00:00
|
|
|
map(&:chomp).
|
|
|
|
reject { |line| %r{^#}.match(line) }.
|
2021-07-19 12:32:12 +00:00
|
|
|
reject { |line| %r{^Qa(a|b[a-x])}.match(line) }.
|
2020-06-28 12:04:57 +00:00
|
|
|
select { |line| %r{;.*;.*;}.match(line) }.
|
|
|
|
map { |line| line.split(';') }.
|
|
|
|
map { |line| [
|
2022-03-26 11:14:31 +00:00
|
|
|
line[0][0..0].upcase + line[0][1..line[0].length].downcase,
|
|
|
|
line[1].gsub(%r{^0}, '').to_i,
|
|
|
|
line[2],
|
2020-06-28 12:04:57 +00:00
|
|
|
] }
|
|
|
|
|
2022-03-26 11:14:31 +00:00
|
|
|
(0..49).map do |idx|
|
|
|
|
entries << [
|
|
|
|
sprintf('Qa%s%s', ('a'.ord + (idx / 26)).chr, ('a'.ord + (idx % 26)).chr),
|
|
|
|
900 + idx,
|
|
|
|
'Reserved for private use',
|
2021-07-19 12:32:12 +00:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2022-03-26 11:14:31 +00:00
|
|
|
entry_map = Hash[ *
|
|
|
|
entries.map { |e| [ e[0], e ] }.flatten(1) +
|
|
|
|
entries.map { |e| [ e[1], e ] }.flatten(1)
|
|
|
|
]
|
|
|
|
|
|
|
|
Mtx::IANALanguageSubtagRegistry.
|
|
|
|
fetch_registry["script"].
|
|
|
|
reject { |entry| %r{\.\.}.match(entry[:subtag]) }.
|
|
|
|
each do |entry|
|
|
|
|
|
|
|
|
if %r{^[0-9]+$}.match(entry[:subtag])
|
|
|
|
number = entry[:subtag].gsub(%r{^0+}, '').to_i
|
|
|
|
code = ""
|
|
|
|
idx = number
|
|
|
|
else
|
|
|
|
number = 0
|
|
|
|
code = entry[:subtag]
|
|
|
|
idx = code
|
|
|
|
end
|
|
|
|
|
|
|
|
if !entry_map.key?(idx)
|
|
|
|
entry_map[key] = [
|
|
|
|
code,
|
|
|
|
number,
|
|
|
|
entry[:description],
|
|
|
|
]
|
|
|
|
end
|
2022-03-26 12:16:26 +00:00
|
|
|
|
|
|
|
entry_map[idx] << entry.key?(:deprecated)
|
2022-03-26 11:14:31 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
rows = entries.
|
|
|
|
map { |entry| [
|
2022-04-22 20:06:21 +00:00
|
|
|
entry[0].to_c_string,
|
2022-03-26 11:14:31 +00:00
|
|
|
sprintf('%03s', entry[1]),
|
2022-04-22 20:06:21 +00:00
|
|
|
entry[2].to_u8_c_string,
|
2022-03-26 12:16:26 +00:00
|
|
|
(entry[3] || false).to_s,
|
2022-03-26 11:14:31 +00:00
|
|
|
] }
|
|
|
|
|
|
|
|
|
2020-06-28 12:04:57 +00:00
|
|
|
header = <<EOT
|
|
|
|
/*
|
|
|
|
mkvmerge -- utility for splicing together matroska files
|
|
|
|
from component media subtypes
|
|
|
|
|
|
|
|
Distributed under the GPL v2
|
|
|
|
see the file COPYING for details
|
2020-08-01 16:03:54 +00:00
|
|
|
or visit https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
|
2020-06-28 12:04:57 +00:00
|
|
|
|
|
|
|
ISO 15924 script list
|
|
|
|
|
|
|
|
Written by Moritz Bunkus <moritz@bunkus.org>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
// NOTE: this file is auto-generated by the "dev:iso15924_list" rake target.
|
|
|
|
// -------------------------------------------------------------------------
|
|
|
|
|
|
|
|
#include "common/common_pch.h"
|
|
|
|
|
|
|
|
#include "common/iso15924.h"
|
|
|
|
|
|
|
|
namespace mtx::iso15924 {
|
|
|
|
|
2021-01-25 23:54:55 +00:00
|
|
|
std::vector<script_t> g_scripts;
|
|
|
|
|
2022-04-22 20:06:21 +00:00
|
|
|
struct script_init_t {
|
|
|
|
char const *code;
|
|
|
|
unsigned int number;
|
|
|
|
char const *english_name;
|
|
|
|
bool is_deprecated;
|
|
|
|
};
|
2021-01-25 23:54:55 +00:00
|
|
|
|
2022-04-22 20:06:21 +00:00
|
|
|
static script_init_t const s_scripts_init[] = {
|
2020-06-28 12:04:57 +00:00
|
|
|
EOT
|
|
|
|
|
|
|
|
footer = <<EOT
|
2022-04-22 20:06:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void
|
|
|
|
init() {
|
|
|
|
g_scripts.reserve(#{rows.size});
|
|
|
|
|
|
|
|
for (script_init_t const *script = s_scripts_init, *end = script + #{rows.size}; script < end; ++script)
|
|
|
|
g_scripts.emplace_back(script->code, script->number, script->english_name, script->is_deprecated);
|
2021-01-25 23:54:55 +00:00
|
|
|
}
|
2020-06-28 12:04:57 +00:00
|
|
|
|
|
|
|
} // namespace mtx::iso15924
|
|
|
|
EOT
|
|
|
|
|
2022-04-22 20:06:21 +00:00
|
|
|
content = header + format_table(rows.sort, :column_suffix => ',', :row_prefix => " { ", :row_suffix => " },").join("\n") + "\n" + footer
|
2021-07-17 09:18:07 +00:00
|
|
|
cpp_file_name = "src/common/iso15924_script_list.cpp"
|
2020-06-28 12:04:57 +00:00
|
|
|
|
|
|
|
runq("write", cpp_file_name) { IO.write("#{$source_dir}/#{cpp_file_name}", content); 0 }
|
|
|
|
end
|