Module Utf_offset_conv

This library facilitates converting offsets in a Unicode string when they are expressed in the wrong units / encoding. An example use case is that you have some offset that was taken w.r.t. text when it was in UTF-16, but the text has since been converted to UTF-8, and you want to find the corresponding offset. Or, conversely, you have text that is currently in UTF-8 and have taken an offset, but know it will be converted into UTF-16 and want the offset to be valid after that happens. This sort of thing is common when interfacing with JavaScript environments, since js_of_ocaml performs string conversion automatically: https://ocaml.org/p/js_of_ocaml/3.3.0/doc/Js/index.html#val-string.

module Offset_units : sig ... end
val convert_offset : int -> from:Offset_units.t -> to_:Offset_units.t -> text_encoding:(module Core.String.Utf with type t = 'utf) -> text:'utf -> int

Convert an offset in text from one type of units to another. from should be an offset in text at a valid Unicode boundary. It is allowed to point to the position after the final character.