Add utf to your gleam.toml dependencies
[dependencies]
utf = { git = "https://github.com/JonasHedEng/utf-convert.git", ref = "1c887f8" }import gleam/bit_array
import gleam/io
import gleam/string
import utf
pub fn main() -> Nil {
let bytes = bit_array.append(<<"Hello Joe ">>, <<0xF0, 0x9F, 0x94, 0x94>>)
case utf.convert_utf8(bytes) {
Ok(valid) -> io.println(valid)
Error(invalid) -> {
string.replace(in: invalid, each: "\u{FFFD}", with: "") |> io.println
}
}
}gleam run # Run the project
gleam test # Run the tests