-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:roc-lang/unicode
- Loading branch information
Showing
23 changed files
with
6,688 additions
and
6,678 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
app [main!] { | ||
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br", | ||
unicode: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/roc/unicode/releases | ||
} | ||
|
||
import pf.Stdout | ||
import unicode.CodePoint | ||
|
||
word = "世界" | ||
|
||
## Get the display width (in amount of characters) of a Str | ||
get_visual_width : Str -> Result U32 CodePoint.Utf8ParseErr | ||
get_visual_width = |str| | ||
str | ||
|> Str.to_utf8 | ||
|> CodePoint.parse_utf8 | ||
|> Result.map_ok(|lst| List.map(lst, CodePoint.visual_width)) | ||
|> Result.map_ok(List.sum) | ||
|
||
main! = |_args| | ||
when get_visual_width(word) is | ||
Ok(width) -> Stdout.line!("\n\nThe word ${word} will be displayed with the width of ${Num.to_str(width)} characters on most UIs.\n\n") | ||
Err(_) -> crash("ERROR: Unable to parse ${word}!") | ||
|
||
expect (get_visual_width(word)) == Ok(4) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
app [main!] { | ||
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br", | ||
unicode: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/roc/unicode/releases | ||
} | ||
|
||
import pf.Stdout | ||
import unicode.CodePoint exposing [Utf8ParseErr] | ||
|
||
## Get the number of code points for a given Str | ||
nr_of_code_points : Str -> Result U64 Utf8ParseErr | ||
nr_of_code_points = |str| | ||
str |> Str.to_utf8 |> CodePoint.parse_utf8 |> Result.map_ok(List.len) | ||
|
||
main! = |_args| | ||
word = "ẇ͓̞͒͟͡ǫ̠̠̉̏͠͡ͅr̬̺͚̍͛̔͒͢d̠͎̗̳͇͆̋̊͂͐" | ||
|
||
when nr_of_code_points(word) is | ||
Ok(nr) -> | ||
Stdout.line!("String \"${word}\" consists of ${Num.to_str(nr)} code points.") | ||
|
||
Err(_) -> | ||
Err(Exit(1, "Failed to parse string ${word} as Utf8.")) |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
app [main!] { | ||
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.19.0/bi5zubJ-_Hva9vxxPq4kNx4WHX6oFs8OP6Ad0tCYlrY.tar.br", | ||
unicode: "../package/main.roc", # use release URL (ends in tar.br) for local example, see github.com/roc/unicode/releases | ||
} | ||
|
||
import pf.Stdout | ||
import unicode.Grapheme | ||
|
||
string = "🇦🇺🦘🪃" | ||
|
||
expect Grapheme.split(string) == Ok(["🇦🇺", "🦘", "🪃"]) | ||
|
||
main! = |_args| | ||
string | ||
|> Grapheme.split | ||
|> Inspect.to_str | ||
|> |splitted| | ||
Stdout.line!("\n\nThe string \"${string}\" has following graphemes:")? | ||
Stdout.line!(splitted) |
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.