flang.dev — The Fuzion Language Portal
JavaScript seems to be disabled. Functionality is limited.
Fuzion
•
Idioms
•
Idiom # 231: Test if bytes are a valid UTF-8 string
Idiom # 231: Test if bytes are a valid UTF-8 string
See
programming-idioms.org
:
Code
String isb := String.type.from_bytes s .codepoints_and_errors ∀ x -> x.ok
What are effects?
Running Example
ex231 is bytes_ok := [u8 1; u8 2; u8 3; u8 4; u8 5] bytes_not_ok := [u8 200; u8 1; u8 201; u8 2; u8 203] s := bytes_ok b := String.type.from_bytes s .codepoints_and_errors ∀ x -> x.ok say "utf8? $s: $b" s := bytes_not_ok b := String.type.from_bytes s .codepoints_and_errors ∀ x -> x.ok say "utf8? $s: $b"
What are effects?
next: Idiom # 232: Read a command line boolean flag