Print Unicode chars only if the locale allows it

Reviewed By: jvillard

Differential Revision: D13118955

fbshipit-source-id: 0d817f45f
master
Mehdi Bouaziz 6 years ago committed by Facebook Github Bot
parent 5fa89e2563
commit acf740e145

@ -17,7 +17,7 @@ let top_bar_size_default = 100
let min_acceptable_progress_bar = 10 let min_acceptable_progress_bar = 10
(** infer rulez *) (** infer rulez *)
let job_prefix = " " let job_prefix = SpecialChars.right_tack ^ " "
(** {2 Task bar} *) (** {2 Task bar} *)

@ -71,7 +71,7 @@ module SymLinear = struct
in in
if Z.(equal c one) then Symb.Symbol.pp f s if Z.(equal c one) then Symb.Symbol.pp f s
else if Z.(equal c minus_one) then F.fprintf f "-%a" Symb.Symbol.pp s else if Z.(equal c minus_one) then F.fprintf f "-%a" Symb.Symbol.pp s
else F.fprintf f "%a%a" Z.pp_print c Symb.Symbol.pp s else F.fprintf f "%a%s%a" Z.pp_print c SpecialChars.dot_operator Symb.Symbol.pp s
let pp : is_beginning:bool -> F.formatter -> t -> unit = let pp : is_beginning:bool -> F.formatter -> t -> unit =

@ -93,11 +93,15 @@ module PositiveInt = struct
let ten = Z.of_int 10 let ten = Z.of_int 10
let exponent_chars = [|""; "¹"; "²"; "³"; ""; ""; ""; ""; ""; ""|] let exponent_prefix, exponent_chars = SpecialChars.superscript_digits
let rec pp_exponent f i = let pp_exponent f i =
let rec aux f i =
if not Z.(i <= zero) then ( if not Z.(i <= zero) then (
let d, r = Z.ediv_rem i ten in let d, r = Z.ediv_rem i ten in
pp_exponent f d ; aux f d ;
F.pp_print_string f exponent_chars.(Z.to_int r) ) F.pp_print_string f exponent_chars.(Z.to_int r) )
in
F.pp_print_string f exponent_prefix ;
aux f i
end end

@ -311,13 +311,16 @@ module MakePolynomial (S : NonNegativeSymbol) = struct
let degree_term p = snd (degree_with_term p) let degree_term p = snd (degree_with_term p)
let multiplication_sep = F.sprintf " %s " SpecialChars.multiplication_sign
let pp : F.formatter -> t -> unit = let pp : F.formatter -> t -> unit =
let add_symb s (((last_s, last_occ) as last), others) = let add_symb s (((last_s, last_occ) as last), others) =
if Int.equal 0 (S.compare s last_s) then ((last_s, PositiveInt.succ last_occ), others) if Int.equal 0 (S.compare s last_s) then ((last_s, PositiveInt.succ last_occ), others)
else ((s, PositiveInt.one), last :: others) else ((s, PositiveInt.one), last :: others)
in in
let pp_coeff fmt (c : NonNegativeInt.t) = let pp_coeff fmt (c : NonNegativeInt.t) =
if Z.((c :> Z.t) > one) then F.fprintf fmt "%a ⋅ " NonNegativeInt.pp c if Z.((c :> Z.t) > one) then
F.fprintf fmt "%a %s " NonNegativeInt.pp c SpecialChars.dot_operator
in in
let pp_exp fmt (e : PositiveInt.t) = let pp_exp fmt (e : PositiveInt.t) =
if Z.((e :> Z.t) > one) then PositiveInt.pp_exponent fmt e if Z.((e :> Z.t) > one) then PositiveInt.pp_exponent fmt e
@ -329,7 +332,7 @@ module MakePolynomial (S : NonNegativeSymbol) = struct
let pp_symb fmt symb = pp_magic_parentheses S.pp fmt symb in let pp_symb fmt symb = pp_magic_parentheses S.pp fmt symb in
let pp_symb_exp fmt (symb, exp) = F.fprintf fmt "%a%a" pp_symb symb pp_exp exp in let pp_symb_exp fmt (symb, exp) = F.fprintf fmt "%a%a" pp_symb symb pp_exp exp in
let pp_symbs fmt (last, others) = let pp_symbs fmt (last, others) =
List.rev_append others [last] |> Pp.seq ~sep:" × " pp_symb_exp fmt List.rev_append others [last] |> Pp.seq ~sep:multiplication_sep pp_symb_exp fmt
in in
let rec pp_sub ~print_plus symbs fmt {const; terms} = let rec pp_sub ~print_plus symbs fmt {const; terms} =
let print_plus = let print_plus =

@ -0,0 +1,34 @@
(*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
let utf8 =
let rec from_vars = function
| [] ->
false
| var :: otherwise -> (
match Sys.getenv var with
| Some ("C" | "POSIX") ->
false
| None | Some "" ->
from_vars otherwise
| Some lc ->
String.is_suffix lc ~suffix:"UTF-8" )
in
from_vars ["LC_ALL"; "LC_CTYPE"; "LANG"]
let dot_operator = if utf8 then "" else "."
let multiplication_sign = if utf8 then "×" else "x"
let right_tack = if utf8 then "" else "|-"
let superscript_digits =
if utf8 then ("", [|""; "¹"; "²"; "³"; ""; ""; ""; ""; ""; ""|])
else ("^", [|"0"; "1"; "2"; "3"; "4"; "5"; "6"; "7"; "8"; "9"|])

@ -0,0 +1,16 @@
(*
* Copyright (c) 2018-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*)
open! IStd
val dot_operator : string
val multiplication_sign : string
val right_tack : string
val superscript_digits : string * string Array.t
Loading…
Cancel
Save