dymokomi/luce-browser-foundation
Source of release 0.6.0
0.6.0 / tools / gen_ucd / emit_locales.lucb
#==============================================================================================
#
# emit_locales - generated_icu_locales.lucb: ICU's locale data that web_unicode answers with
#
# DESCRIPTION:
# The available locales, likely subtags and right-to-left scripts of ICU 78.2, from
# the lists dumped into data/icu, as text the Locale functions search.
#
#==============================================================================================
## The data lines of `data`: without comments and blank lines.
func append_data_lines(out: collections.Buffer*, data: const u8[], separator: str) -> !:
var lines = Lines.over(data)
var first = true
while let line = lines.next():
let content = trim_spaces(strip_comment(line))
if content.length == 0:
continue
if not first:
try out.put_text(separator)
try out.put_text(content)
first = false
func emit_locales(available: const u8[], likely: const u8[], rtl: const u8[]) -> str!:
var out: collections.Buffer
try put_header(&out, "generated_icu_locales", "the locale data of ICU 78.2", [
"Generated by tools/gen_ucd from data/icu (lists dumped from ICU 78.2, CLDR 48); do not",
"edit.",
"",
"Unicode data: Copyright Unicode, Inc., Unicode License v3 (data/icu/LICENSE.txt).",
])
try out.put_text("\n# icu::Locale::getAvailableLocales as language tags, separated by spaces.\nlet icu_available_locales: str = \"")
try append_data_lines(&out, available, " ")
try out.put_text("\"\n\n# Likely subtags: `tag maximized` pairs separated by semicolons, ascending by tag.\nlet icu_likely_subtags: str = \"")
try append_data_lines(&out, likely, ";")
try out.put_text("\"\n\n# The scripts written right to left (uscript_isRightToLeft), separated by spaces.\nlet icu_rtl_scripts: str = \"")
try append_data_lines(&out, rtl, " ")
try out.put_text("\"\n")
return out.text()