Skip to content

Fix bugs in String.fromCString and Char.scan - #659

Merged
MatthewFluet merged 9 commits into
MLton:masterfrom
MatthewFluet:text-scan-bugs
Sep 30, 2026
Merged

MatthewFluet merged 9 commits into
MLton:masterfrom
MatthewFluet:text-scan-bugs

Conversation

@MatthewFluet

Copy link
Copy Markdown
Member

No description provided.

The implementation of `String.fromCString` did not confirm that at
least a single C-string character could be consumed from the input
string and would return `SOME ""` on an input string whose first
character could not be converted (e.g., illegal escape).

Closes MLton#658

Also, unify the implementations of `String.fromString` and
`String.fromCString` to share the logic for converting an initial
character and converting the remaining characters.
The Basis Library specification for `Char.scan` states: "As the table
indicates, escaped formatting sequences (`\f...f\`) are passed over
during scanning. Such sequences are successfully scanned, so that the
remaining stream returned by scan will never have a valid escaped
formatting sequence as its prefix."

`Char.scan` ran `skipFormatSequences` on the state after the
successful scan of a non-escape character, but did not on the state
after the successful scan of a non-escaped-formatting-sequence escape
sequence.
@MatthewFluet
MatthewFluet merged commit 936011c into MLton:master Sep 30, 2026
22 checks passed
@MatthewFluet
MatthewFluet deleted the text-scan-bugs branch September 30, 2026 15:19
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