Merge pull request #7321 from shua/fromutf8

DO NOT MERGE update Str.fromUtf8 error type
This commit is contained in:
Luke Boswell 2025-01-08 07:56:40 +11:00 committed by GitHub
commit 8540aa1a14
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 105 additions and 105 deletions

View file

@ -538,14 +538,14 @@ toUtf8 : Str -> List U8
## expect Str.fromUtf8 [] == Ok ""
## expect Str.fromUtf8 [255] |> Result.isErr
## ```
fromUtf8 : List U8 -> Result Str [BadUtf8 Utf8ByteProblem U64]
fromUtf8 : List U8 -> Result Str [BadUtf8 { problem : Utf8ByteProblem, index : U64 }]
fromUtf8 = \bytes ->
result = fromUtf8Lowlevel bytes
if result.cIsOk then
Ok result.bString
else
Err (BadUtf8 result.dProblemCode result.aByteIndex)
Err (BadUtf8 { problem: result.dProblemCode, index: result.aByteIndex })
expect (Str.fromUtf8 [82, 111, 99]) == Ok "Roc"
expect (Str.fromUtf8 [224, 174, 154, 224, 174, 191]) == Ok "சி"