Commits

Anonymous committed a33ac41

+ Strings.Utf8.String.is_prefix

Comments (0)

Files changed (4)

 Library cadastr
   Path:       src
   BuildDepends: num
-  Modules:    Cadastr, Monoid, Cd_All, Cd_Int, Cd_List, Cd_Ops, Cd_Byte, Cd_Bytes, Cd_Chars, Cd_Strings, Cd_Array, Cd_Typeinfo, Cdt, Cd_Types, Cd_Option, Cd_Num, Cd_Tuples, Cd_Bool, TlsArray, TlsArray_st, TlsArray_mt, TlsRef, Cd_Ref, Cd_Partapp, Cd_Int64, Cd_Ser, Cd_SortedArray, Cd_SortedArraySet
+  Modules:    Cadastr, Monoid, Cd_All, Cd_Int, Cd_List, Cd_Ops, Cd_Byte, Cd_Bytes, Cd_Chars, Cd_Strings, Cd_Array, Cd_Typeinfo, Cdt, Cd_Types, Cd_Option, Cd_Num, Cd_Tuples, Cd_Bool, TlsArray, TlsArray_st, TlsArray_mt, TlsRef, Cd_Ref, Cd_Partapp, Cd_Int64, Cd_Ser, Cd_SortedArray, Cd_SortedArraySet, Cd_Utf8
   NativeOpt:       -w A
   ByteOpt:         -w A
 
 (* setup.ml generated for the first time by OASIS v0.2.1~alpha1 *)
 
 (* OASIS_START *)
-(* DO NOT EDIT (digest: cb7f64f2b0d00905a9e6f5123774e139) *)
+(* DO NOT EDIT (digest: 111c334fd57d418d56fbcf6c7e5d3ccd) *)
 (*
    Regenerated by OASIS v0.2.1~alpha1
    Visit http://oasis.forge.ocamlcore.org for more information and
                            "Cd_Int64";
                            "Cd_Ser";
                            "Cd_SortedArray";
-                           "Cd_SortedArraySet"
+                           "Cd_SortedArraySet";
+                           "Cd_Utf8"
                         ];
                       lib_internal_modules = [];
                       lib_findlib_parent = None;

src/cadastr.mllib

 # OASIS_START
-# DO NOT EDIT (digest: 430975efb491cffb6b12b046c2aed954)
+# DO NOT EDIT (digest: f5b86c8c387d7e4e1b259e92e5e4cfbc)
 Cadastr
 Monoid
 Cd_All
 Cd_Ser
 Cd_SortedArray
 Cd_SortedArraySet
+Cd_Utf8
 # OASIS_STOP

src/cd_Strings.ml

 
             include TFUNCS;
 
+            value is_prefix : ~string:string -> ~prefix:string -> bool;
+
           end
          =
           struct
 
             include TFuncs;
 
+
+            (* some real utf8 work *)
+
+            module U = Cd_Utf8;
+
+            (* does not check bounds! *)
+            value substring_eq ~s1 ~ofs1 ~s2 ~ofs2 ~len =
+              inner 0
+              where rec inner i =
+                if i = len
+                then True
+                else
+                  if s1.[ofs1 + i] = s2.[ofs2 + i]
+                  then inner (i + 1)
+                  else False
+            ;
+
+            value prefix_bytes ~string ~prefix =
+              let sb = length_bytes string
+              and pb = length_bytes prefix in
+              loop 0
+              where rec loop i =
+                if i = pb || i = sb
+                then i
+                else
+                  let sc = U.char_length string i
+                  and pc = U.char_length prefix i in
+                  if sc <> pc
+                  then
+                    i
+                  else
+                    let i' = i + sc in
+                    if i' > pb || i' > sb
+                    then raise
+                      (U.Bad_utf8 "end of string, incomplete character")
+                    else
+                      if substring_eq
+                           ~s1:string ~ofs1:i
+                           ~s2:prefix ~ofs2:i
+                           ~len:sc
+                      then
+                        loop i'
+                      else
+                        i
+            ;
+
+            value is_prefix ~string ~prefix =
+              prefix_bytes ~string ~prefix = length_bytes prefix
+            ;
+
           end  (* Utf8.String *)
         ;