Skip to content

Commit

Permalink
Renames
Browse files Browse the repository at this point in the history
  • Loading branch information
WardBrian committed Mar 7, 2024
1 parent 0c7621f commit e2bf53a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions src/common/Unicode.ml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let is_ascii s =

let normalize = Uunf_string.normalize_utf_8 `NFKC

let fold_uchars f acc str =
let foldi_uchars ~f acc str =
let len = String.length str in
let rec loop pos acc =
if pos == len then acc
Expand All @@ -25,19 +25,19 @@ let fold_uchars f acc str =
loop (pos + char_length) acc in
loop 0 acc

let iter_uchars s f =
let iteri_uchars ~f str =
let f' buf pos c =
f pos c;
Buffer.add_utf_8_uchar buf c;
buf in
let s_after =
Buffer.contents @@ fold_uchars f' (Buffer.create (String.length s)) s in
Buffer.contents @@ foldi_uchars ~f:f' (Buffer.create (String.length str)) str in
(* another sanity check *)
if not (String.equal s s_after) then
if not (String.equal str s_after) then
Core.(
ICE.internal_compiler_error
[%message
"Failed to round-trip unicode string!" (s : string) (s_after : string)])
"Failed to round-trip unicode string!" (str : string) (s_after : string)])

(* WIP:
Expand All @@ -60,7 +60,7 @@ let confusable x y =
(* TODO!! replace with prototype - need data? *)
Buffer.add_utf_8_uchar acc c;
acc in
let buf = fold_uchars f (Buffer.create (String.length x)) x in
let buf = foldi_uchars ~f (Buffer.create (String.length x)) x in
let x = Buffer.contents buf in
let x = Uunf_string.normalize_utf_8 `NFD x in
x in
Expand Down Expand Up @@ -98,7 +98,7 @@ let restriction_level x =
let scripts =
Uucp.Script.script_extensions c |> ScriptSet.of_list |> extended in
scripts :: acc in
let soss = fold_uchars f [] x in
let soss = foldi_uchars ~f [] x in
let resolved = List.fold_right ScriptSet.inter soss all in
if not @@ ScriptSet.is_empty resolved then `Single
else `Unrestricted (* TODO implement levels 3-5 *)
2 changes: 1 addition & 1 deletion src/frontend/Identifiers.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ let validate_utf8_id ~loc id =
error ~loc
(Fmt.str "Invalid character in identifier at offset %d: '%a'" pos
pp_uchar uchar) in
iter_uchars id f;
iteri_uchars ~f id;
id

let validate loc id =
Expand Down
2 changes: 1 addition & 1 deletion src/stan_math_backend/Cpp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ module Printing = struct
let uchar_int = Uchar.to_scalar c in
if uchar_int < 128 then Fmt.char ppf (Char.of_int_exn uchar_int)
else Fmt.pf ppf "\\u%04X" (Uchar.to_scalar c) in
Common.Unicode.iter_uchars s f
Common.Unicode.iteri_uchars ~f s

let rec pp_type_ ppf t =
match t with
Expand Down

0 comments on commit e2bf53a

Please sign in to comment.