Skip to content

GSUnicode: implement non-lossy ASCII conversion - #127

Open
DTW-Thalion wants to merge 2 commits into
gnustep:masterfrom
DTW-Thalion:fix/gsunicode-nonlossy-ascii
Open

GSUnicode: implement non-lossy ASCII conversion#127
DTW-Thalion wants to merge 2 commits into
gnustep:masterfrom
DTW-Thalion:fix/gsunicode-nonlossy-ascii

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

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.

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
DTW-Thalion force-pushed the fix/gsunicode-nonlossy-ascii branch from 043582b to 2bd76a1 Compare July 24, 2026 15:22
@DTW-Thalion DTW-Thalion reopened this Jul 24, 2026
@DTW-Thalion DTW-Thalion reopened this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant