12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061(* [String0] defines string functions that are primitives or can be simply defined in
terms of [Caml.String]. [String0] is intended to completely express the part of
[Caml.String] that [Base] uses -- no other file in Base other than string0.ml should
use [Caml.String]. [String0] has few dependencies, and so is available early in Base's
build order.
All Base files that need to use strings, including the subscript syntax
[x.(i)] or [x.(i) <- e] which the OCaml parser desugars into calls to
[String], and come before [Base.String] in build order should do
{[
module String = String0
]}
Defining [module String = String0] is also necessary because it prevents
ocamldep from mistakenly causing a file to depend on [Base.String]. *)open!Import0moduleBytes=Bytes0moduleSys=Sys0moduleString=structexternalget:string->int->char="%string_safe_get"externallength:string->int="%string_length"externalunsafe_get:string->int->char="%string_unsafe_get"externalset:bytes->int->char->unit="%bytes_safe_set"externalunsafe_set:bytes->int->char->unit="%bytes_unsafe_set"endincludeStringletmax_length=Sys.max_string_lengthlet(^)=(^)letcapitalize=Caml.String.capitalize_asciiletcompare=Caml.String.compareletcopyx=Bytes.unsafe_to_string~no_mutation_while_string_reachable:(Bytes.of_stringx);;letescaped=Caml.String.escapedletlowercase=Caml.String.lowercase_asciiletmake=Caml.String.makeletsub=Caml.String.subletuncapitalize=Caml.String.uncapitalize_asciiletunsafe_blit=Caml.String.unsafe_blitletuppercase=Caml.String.uppercase_asciiletconcat?(sep="")l=matchlwith|[]->""(* The stdlib does not specialize this case because it could break existing projects. *)|[x]->x|l->Caml.String.concat~sepl;;(* These are eta expanded in order to permute parameter order to follow Base
conventions. *)letitert~f=Caml.String.itert~f