Something went wrong. Try again.
The Unicode Collation Algorithm (UTS #10) and CLDR locale tailorings in Zig: sort text the way people expect rather than by code point.
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475#!/usr/bin/env bash# SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us># SPDX-License-Identifier: MIT## Refreshes the Unicode data files in data/.## These are committed rather than fetched by the Zig package manager, which# refuses a dependency served as text/plain -- and the DUCET is published only# as a plain text file, with no archive of it anywhere on unicode.org. See the# README.## Usage: tools/update-ducet.sh [version]## With no argument it takes whatever `Public/UCA/latest/` is serving, which is# whichever release is current. Pass a version to pin one, which is what the# committed files are: a version's UCA data lives under `Public/<version>/uca/`# in the UCD tree, and *not* under `Public/UCA/<version>/`, where the# numbered directories stop at 16.0.0.## The Unicode version here must match the one `uucode` ships, because step 1# of the algorithm reads uucode's Unicode Character Database and step 2 reads# this table. `zig build test-conformance` is what notices if they disagree.
set -euo pipefail
cd "$(dirname "$0")/.."
version="${1:-}"if [[ -n "$version" ]]; then uca="https://www.unicode.org/Public/${version}/uca" ucd="https://www.unicode.org/Public/${version}/ucd"else uca="https://www.unicode.org/Public/UCA/latest" ucd="https://www.unicode.org/Public/UCD/latest/ucd"fi
work="$(mktemp -d)"trap 'rm -rf "$work"' EXIT
curl -fsSL -o "$work/allkeys.txt" "$uca/allkeys.txt"curl -fsSL -o "$work/PropList.txt" "$ucd/PropList.txt"curl -fsSL -o "$work/Blocks.txt" "$ucd/Blocks.txt"
# Each file names its own version on its first line: allkeys.txt as an# `@version` line, the two UCD files as `# <Name>-<version>.txt`. Read it out# rather than trusting the URL, so that `latest` is recorded as whatever it# actually served.allkeys_version="$(sed -n 's/^@version[[:space:]]*//p' "$work/allkeys.txt" | head -1)"proplist_version="$(sed -n '1s/^# PropList-\(.*\)\.txt$/\1/p' "$work/PropList.txt")"blocks_version="$(sed -n '1s/^# Blocks-\(.*\)\.txt$/\1/p' "$work/Blocks.txt")"
if [[ "$allkeys_version" != "$proplist_version" || "$allkeys_version" != "$blocks_version" ]]; then echo "the three files disagree: allkeys $allkeys_version," \ "PropList $proplist_version, Blocks $blocks_version" >&2 exit 1fi
rm -f data/allkeys-*.txt data/PropList-*.txt data/Blocks-*.txtmv "$work/allkeys.txt" "data/allkeys-${allkeys_version}.txt"mv "$work/PropList.txt" "data/PropList-${allkeys_version}.txt"mv "$work/Blocks.txt" "data/Blocks-${allkeys_version}.txt"
echo "data/ is now Unicode ${allkeys_version}"echoechoecho "The CLDR root collation in data/allkeys_CLDR-*.txt is versioned by CLDR"echo "release rather than by Unicode release and is not touched by this; it"echo "comes from common/uca/allkeys_CLDR.txt in the CLDR repository, and its"echo "own header says which UCA version it was built against."echoecho "Next:"echo " * point the b.path() calls in build.zig at the new file names"echo " * check that uucode is on the same Unicode version, and bump it if not"echo " * zig build test && zig build test-conformance"