ucstat

All Top-level Files
Login

All Top-level Files

Files in the top-level directory in any check-in


ucstat: Report Unicode text statistics

This Unix-style filter collects statistics about a body of text from standard input or named files, then reports what it finds:

Details mode adds per-character reporting along those same lines.

Flags

--details

If you give the program a single character…

echo -n 'a' | ucstat

…it reports more details about that character than are given in the default output mode. Each classification given in aggregate output is given per-character in this mode. Give the --details flag to do this for every input character.

Aggregate statistics continue to be reported in this mode.

--encoding

Force the input encoding when there is no BOM.2 Accepted names are:

Hyphens and case are flexible. Bare UTF-16/UTF-32 are rejected as ambiguous.

iconv -f utf8 -t utf-32le < README.md | ucstat --encoding=utf-32le

--json

This switches the default human-readable tabular output mode to give the same data in JSON form, for automated consumption.

Warnings and errors are on stderr to allow redirection of this without worry over intermixing those with the result data.

Combine this with --details to include an array of per-character information in the report. The total value is no longer given separately, but is implied by the count of the chars array, which is an integer count in aggregate mode.

Downloads

Pre-built static binaries for Windows, macOS, and Linux (amd64 and arm64) are available here for direct download.

Our versionless URLs allow pulling the current release without prior knowledge of its version number.3

We push release images to Quay to allow direct runs, without manually downloading and installing the binary first:

$ podman run --rm -i quay.io/tangent/ucstat --version
v0.2.0 (Unicode 18.0.0)

Build

Prerequisites:

Say task to build a debug binary, or task install to build a release binary and put it in a sensible PATH location.

The included Makefile is a thin wrapper around the above for those like your humble author, who have make grooved bone-deep into their finger memory. 🤓

Other useful top-level targets include:

task clean      # remove build products
task container  # build + push multi-arch Quay image (pre-release tag)
task install    # native release binary into PATH (+ dist/)
task lint       # check for Go code style problems
task login      # podman login to Quay.io
task release    # cut release via tools/mkrel (dist + /uv + Quay)
task test       # run built-in self-test suite

Cached Data

To avoid abusing the Unicode data providers, task/make clean does not remove the UCD master data files or the generated Go version of these. To force a refresh, use fossil clean and build again so that the next build re-pulls and starts afresh.

We choose not to commit these files to the code repository because we do not wish to pin this program to a specific version of Unicode. We rely on each builder to pull the current UCD files at build time. From that point forward, the local copies serve as long-lived caches; Unicode rarely updates more than once a year. “Outdated” binaries are likely good enough for local purposes until you start seeing unassigned code point warnings for text you know is legal Unicode.

The --version flag reports the current Unicode standard in effect at build time, whence comes all the UCD data built into the binary.

Versioning

Day-to-day work is done on Fossil trunk, with branches used when a feature needs multiple commits that would destabilize trunk if made there prior to the final merge point. Releases use a sibling checkout ../release checkout pinned to the release branch. This selects the --version flag output format:

$ task && ./ucstat --version
trunk branch post-v0.0.0 [01199fd46d] 2026-11-24T12:02:22Z (Unicode 18.0.0)
$ cd ../release && fossil up && task && ./ucstat --version
v0.2.0 (Unicode 18.0.0)

Stupid CLI Trick

An aggregate report from ucstat claims there is a single character pinning our docs to Unicode 4.1, and all else is either ASCII or Unicode 1. How do we find out which one tips us over?

ucstat --json --details doc/*.md |
  jq '.chars[] | select(.age == "4.1")'

Append .char after the closing paren to give the quoted character alone, suppressing all the --details reporting on every character in the input corpus.

The aaronland/go-ucd package has a similar purpose, with a CLI program making related reports. I would have liked to use that instead of building this, but I failed at the first hurdle: my immediate need was reporting the maximum age of a given body of Unicode text, which it does not do, despite having glommed the UCD namespace unto itself. Should it not present everything in UCD, then, including a report on code point age?

We hope Aaron will soon make this project obsolete 😆 and if not that, then at least steal everything worth making a library out of so that we can take go-ucd as a dep, hollowing this project out as nothing but an alternative front end.

What we don’t want is for the internal library core of ucstat to go into direct competition. The last thing the Go ecosystem needs is more “Now which of these N overlapping libraries should I be using…?”

License

Copyright © 2026 by Warren Young, released under the MIT license.


  1. ^ BOMs are not counted as input characters.
  2. ^ When a BOM is present and --encoding names a different encoding, ucstat warns, then takes the BOM as authoritative for that data stream. This condition is easiest to trigger when giving multiple inputs, which is why ucstat prefers the per-input BOM check.
  3. ^ Those who need a specific version can pull its source code using its Fossil tag and build from that.