From 49381b7f1edb46c26e12e69af4f6fafa4716bc4f Mon Sep 17 00:00:00 2001 From: Brian Ward Date: Thu, 7 Mar 2024 14:38:00 -0500 Subject: [PATCH] Renames --- src/common/Unicode.ml | 17 ++++++++++------- src/frontend/Identifiers.ml | 2 +- src/stan_math_backend/Cpp.ml | 2 +- 3 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/common/Unicode.ml b/src/common/Unicode.ml index 4cd1d3f06..9e5dad967 100644 --- a/src/common/Unicode.ml +++ b/src/common/Unicode.ml @@ -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 @@ -25,19 +25,22 @@ 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: @@ -60,7 +63,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 @@ -98,7 +101,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 *) diff --git a/src/frontend/Identifiers.ml b/src/frontend/Identifiers.ml index 4f0103d9d..8e16ee742 100644 --- a/src/frontend/Identifiers.ml +++ b/src/frontend/Identifiers.ml @@ -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 = diff --git a/src/stan_math_backend/Cpp.ml b/src/stan_math_backend/Cpp.ml index 7f498e7cb..8c52a391a 100644 --- a/src/stan_math_backend/Cpp.ml +++ b/src/stan_math_backend/Cpp.ml @@ -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