fuzion-lang.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.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] s0 := bytes_ok b0 := String.from_bytes s0 .codepoints_and_errors ∀ x -> x.ok say "utf8? $s0: $b0" s1 := bytes_not_ok b1 := String.from_bytes s1 .codepoints_and_errors ∀ x -> x.ok say "utf8? $s1: $b1"
What are effects?
last changed: 2024-07-01
next: Idiom # 232: Read a command line boolean flag