Skip to content

feat(bindings): mirror TextEncoding - #837

Merged
andiwand merged 1 commit into
mainfrom
feat/mirror-text-encoding
Sep 6, 2026
Merged

feat(bindings): mirror TextEncoding#837
andiwand merged 1 commit into
mainfrom
feat/mirror-text-encoding

Conversation

@andiwand

@andiwand andiwand commented Sep 6, 2026

Copy link
Copy Markdown
Member

🤖 Generated with Claude Code

PR 7 of the v7 API plan.
Stacked on #836. Non-breaking — this only adds.

Why this exists

It was not in the first draft of the plan. #833 turned it up: TextEncoding is
mirrored in no binding. Java, python and objc each build a charset()
string from TextFile::encoding() and stop there, so from outside C++ you
could read the name of an encoding you had already been handed, and nothing
else — not enumerate them, not resolve an alias, not ask whether one is
actually decodable as opposed to merely named.

That is a gap on its own, and it is also a blocker: CsvOptions carries a
TextEncoding
, so PR 8 cannot fold it into DecodeOptions until the enum
crosses.

What lands

The enum plus all five lookups, in every binding:

Java TextEncoding enum, canonicalName(), names(), isDecodable(), byName(), all(); TextFile.encoding()
Python pyodr.TextEncoding, all_text_encodings, text_encoding_to_string, text_encoding_by_name, text_encoding_names, text_encoding_is_decodable; TextFile.encoding()
ObjC ODRTextEncoding, Odr.allTextEncodings / string(textEncoding:) / textEncoding(name:) / names(textEncoding:) / isDecodable(textEncoding:); TextFile.encoding
wasm Odr.enums.TextEncoding

The 41 enumerators were generated from file.hpp rather than retyped, so the
ordinals cannot drift by transcription.

charset() stays everywhere it was, now layered on encoding(). wasm derives
its table from all_text_encodings() the way FileType already does, instead
of restating ordinals — the one hand-written part is unknown, which
all_text_encodings() deliberately leaves out because it has no name.

Tests

New in all four: name round-trips including alias resolution (CP1252
windows-1252), unknown having no name, decodable being narrower than
named (shift_jis is named, not decoded), all() excluding unknown, and a
text file reporting its encoding. The wasm case is pinned in enums.test.mjs
beside the existing ordinal guards.

Verified

Full build; the JNI junit suite, 71 python tests and the C++ suite pass.
Apple (11 TUs) and wasm (6 TUs) syntax-checked with -Wall -Wextra -Werror
against their real toolchains and deployment targets — see the note on #836
about why that check is now part of the loop here.

@andiwand
andiwand force-pushed the refactor/one-way-to-open branch from ca771d0 to 25dd861 Compare September 6, 2026 13:46
Base automatically changed from refactor/one-way-to-open to main September 6, 2026 13:48
The enum never left C++. Java, python and objc each built a charset() string
from TextFile::encoding() and stopped there, so nothing outside C++ could name
an encoding it had not already been handed, or ask whether one is decodable.

All four bindings now carry the enum and the five lookups, and a text file
reports encoding() beside the charset() it keeps. wasm derives its table from
all_text_encodings() rather than restating ordinals, the way FileType already
does.

Nothing is removed. CsvOptions carries a TextEncoding, so this is what the
decode options need before they can cross a binding.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_016hxDa2rev11eLUEJZJ5nmz
@andiwand
andiwand force-pushed the feat/mirror-text-encoding branch from a480dda to d744f6b Compare September 6, 2026 13:55
@andiwand
andiwand merged commit 5ee25f1 into main Sep 6, 2026
25 checks passed
@andiwand
andiwand deleted the feat/mirror-text-encoding branch September 6, 2026 13:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant