Last active
January 10, 2018 20:31
-
-
Save IgnoredAmbience/1cdcdaa93319bdac3416eaf8ee958695 to your computer and use it in GitHub Desktop.
int -> string, converting integers into double-struck 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
(** Conversion between integers and unicode \mathbb strings *) | |
(* 0-9 as unicode \mathbb{d} multibyte character strings *) | |
let ustr_bb_digits = | |
Array.init 10 (fun i -> Printf.sprintf "\xf0\x9d\x9F%c" (char_of_int (0x98 + i))) | |
(** Converts an integer into an array of decimal digits *) | |
let int_to_array i = | |
let rec f i acc = if i == 0 then acc else f (i/10) (i mod 10 :: acc) in | |
f i [] | |
(** Converts an integer i into a unicode string representation of \mathbb{i} *) | |
let int_to_bb_ustr i = | |
String.concat "" (List.map (fun d -> ustr_bb_digits.(d)) (int_to_array i)) | |
(* Example usage: | |
# print_string (int_to_bb_ustr 1234567890);; | |
ππππππππ π‘π | |
*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment