Skip to content

Instantly share code, notes, and snippets.

@IgnoredAmbience
Last active January 10, 2018 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IgnoredAmbience/1cdcdaa93319bdac3416eaf8ee958695 to your computer and use it in GitHub Desktop.
Save IgnoredAmbience/1cdcdaa93319bdac3416eaf8ee958695 to your computer and use it in GitHub Desktop.
int -> string, converting integers into double-struck 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