Closed hhugo closed 3 years ago
Great! Would love to see someone contribute the Str change!
I think there might be value in having two packages, even if they have the same contents, as this may let us specialize some implementations or types for js_of_ocaml. Though for our codebase, we don't really pay attention to the js_of_ocaml build, it "just works". WDYT?
Having a single package allows one to build libraries without having to specialize for a specific target.
Without that, one would need to provide multiple copies for every library ? like library_for_doing_blah_js
, library_for_doing_blah_native
, .. ?
Yeah, good point. Ok, let's not have a separate js_of_ocaml lib until we have a good reason to do otherwise.
(If anyone is interested in fixing this, it can be fixed by removing the Str dependency, and updating the readme to indicate we don't need a js_of_ocaml version).
Here is an inefficient POC.
let split ~(on : string) (s : string) : string list =
let pat = String.Search_pattern.create on in
let len = String.length on in
String.Search_pattern.index_all pat ~may_overlap:false ~in_:s
|> List.fold_map ~init:0 ~f:(fun x y -> y + len , (x,y))
|> (fun (last,l) -> l @ [last, String.length s ])
|> List.map ~f:(fun (x,y) -> String.sub ~pos:x ~len:(y - x) s)
Str
is now compatible with js_of_ocaml. Tablecloth should work out of the box with js_of_ocaml
Thanks @hhugo!
I don't think one need to differentiate 'native' and 'js_of_ocaml'. Just removing the dependency on
Str
will make the lib fully usable with js_of_ocaml.Str
is only used to split strings. One should be able to achieve the same thing with a bit of glue aroundString.Search_pattern.index_all