feat(bindings): mirror TextEncoding - #837
Merged
Merged
Conversation
andiwand
force-pushed
the
refactor/one-way-to-open
branch
from
September 6, 2026 13:46
ca771d0 to
25dd861
Compare
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
force-pushed
the
feat/mirror-text-encoding
branch
from
September 6, 2026 13:55
a480dda to
d744f6b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🤖 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:
TextEncodingismirrored in no binding. Java, python and objc each build a
charset()string from
TextFile::encoding()and stop there, so from outside C++ youcould 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:
CsvOptionscarries aTextEncoding, so PR 8 cannot fold it intoDecodeOptionsuntil the enumcrosses.
What lands
The enum plus all five lookups, in every binding:
TextEncodingenum,canonicalName(),names(),isDecodable(),byName(),all();TextFile.encoding()pyodr.TextEncoding,all_text_encodings,text_encoding_to_string,text_encoding_by_name,text_encoding_names,text_encoding_is_decodable;TextFile.encoding()ODRTextEncoding,Odr.allTextEncodings/string(textEncoding:)/textEncoding(name:)/names(textEncoding:)/isDecodable(textEncoding:);TextFile.encodingOdr.enums.TextEncodingThe 41 enumerators were generated from
file.hpprather than retyped, so theordinals cannot drift by transcription.
charset()stays everywhere it was, now layered onencoding(). wasm derivesits table from
all_text_encodings()the wayFileTypealready does, insteadof restating ordinals — the one hand-written part is
unknown, whichall_text_encodings()deliberately leaves out because it has no name.Tests
New in all four: name round-trips including alias resolution (
CP1252→windows-1252),unknownhaving no name,decodablebeing narrower thannamed(shift_jisis named, not decoded),all()excludingunknown, and atext file reporting its encoding. The wasm case is pinned in
enums.test.mjsbeside 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 -Werroragainst their real toolchains and deployment targets — see the note on #836
about why that check is now part of the loop here.