mirror of
https://github.com/roc-lang/roc.git
synced 2025-08-03 19:58:18 +00:00
Merge pull request #7321 from shua/fromutf8
DO NOT MERGE update Str.fromUtf8 error type
This commit is contained in:
commit
8540aa1a14
10 changed files with 105 additions and 105 deletions
|
@ -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 "சி"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue