JonasHedEng/utf-convert

★ 0Forks 0GleamGitHub ↗Compare

README

utf-convert

Package Version Hex Docs

Install

Add utf to your gleam.toml dependencies

[dependencies]
utf = { git = "https://github.com/JonasHedEng/utf-convert.git", ref = "1c887f8" }

Usage

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
    }
  }
}

Development

gleam run   # Run the project
gleam test  # Run the tests

Contributors

JonasHedEng

Issues