GSUnicode: implement non-lossy ASCII conversion - #127
Open
DTW-Thalion wants to merge 2 commits into
Open
Conversation
Both directions of the kCFStringEncodingNonLossyASCII codec were empty stubs. Implement them in GSUnicodeFromEncoding and GSUnicodeToEncoding: characters above printable ASCII become octal escapes (backslash then three digits) up to U+00FF and four-digit lowercase hexadecimal escapes (backslash u) above that, and a backslash doubles. Remove the two older standalone helpers, which were never wired in and did not work (the encoder never advanced its source pointer and used uppercase hexadecimal).
DTW-Thalion
force-pushed
the
fix/gsunicode-nonlossy-ascii
branch
from
July 24, 2026 15:22
043582b to
2bd76a1
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.
The kCFStringEncodingNonLossyASCII codec was an empty stub in both GSUnicodeFromEncoding and GSUnicodeToEncoding, so CFStringGetBytes and CFStringCreateWithBytes produced nothing for it.
Implement both directions:
Encoding writes a character below 0x80 literally, doubles a backslash, writes characters up to U+00FF as a backslash followed by three octal digits, and writes higher characters as a backslash, a u and four lowercase hexadecimal digits.
Decoding reverses this, accepting octal escapes, backslash-u hexadecimal escapes (either case) and doubled backslashes, and copying other bytes through.
The two older standalone helpers GSUnicodeFromNonLossyASCII and GSUnicodeToNonLossyASCII are removed: they were never referenced, and did not work (the encoder never advanced its source pointer, an infinite loop, and produced uppercase hexadecimal; the decoder read past the end of its input).
Tests/CFString/nonlossy.m covers the octal range boundaries, the hex range, backslash doubling, a mixed string and round-tripping including uppercase-hex decode, verified against Apple CoreFoundation.