Code Monkey home page Code Monkey logo

utf8's Introduction

utf8

UTF-8 support for Nix

Why

Strings in Nix are byte strings, and builtin functions like substring (and by extension some lib functions in nixpkgs) processes bytes instead of UTF-8 code points. That means these functions can create invalid strings when given strings with UTF-8. This library basically allows you to convert it to a list of UTF-8 code points.

Usage

Try it out with flakes

nix repl github:figsoda/utf8#lib --extra-experimental-features "flakes nix-command repl-flake"

or locally

nix repl -f .

chars

Type: String -> [ String ]

Split a string into a list of code points

nix-repl> chars "你好,世界!"
[ "你" "好" "," "世" "界" "!" ]

head

Type: String -> String

Return the first code point of the string

nix-repl> head "你好,世界!"
"你"

tail

Type: String -> String

Return the string without the first code point

nix-repl> tail "你好,世界!"
"好,世界!"

length

Type: String -> Int

Return the number of code points in the string

nix-repl> length "你好,世界!"
6

Development

nix run ./dev # regenerate table.nix

nix develop ./dev
namaka check # run tests
namaka review # review pending snapshots

utf8's People

Contributors

dependabot[bot] avatar figsoda avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.