My working unpac space for OCaml projects in development
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge opam/patches/stringext

+941
+3
vendor/opam/stringext/.gitignore
··· 1 + _build 2 + .merlin 3 + *.install
+17
vendor/opam/stringext/.travis.yml
··· 1 + language: c 2 + sudo: false 3 + services: 4 + - docker 5 + install: wget https://raw.githubusercontent.com/ocaml/ocaml-travisci-skeleton/master/.travis-docker.sh 6 + script: bash -ex ./.travis-docker.sh 7 + env: 8 + global: 9 + - PACKAGE="stringext" 10 + - PINS="stringext:." 11 + matrix: 12 + - DISTRO="debian-stable" OCAML_VERSION="4.07" 13 + - DISTRO="alpine" OCAML_VERSION="4.06" 14 + - DISTRO="fedora" OCAML_VERSION="4.05" 15 + - DISTRO="ubuntu-lts" OCAML_VERSION="4.04" 16 + - DISTRO="opensuse" OCAML_VERSION="4.03" 17 + - DISTRO="ubuntu" OCAML_VERSION="4.02"
+7
vendor/opam/stringext/CHANGES.md
··· 1 + # 1.6.0 2 + 3 + * Port to dune and opam 2.0 metadata format 4 + 5 + # 1.5.0 and earlier 6 + 7 + No changelogs recorded.
+21
vendor/opam/stringext/LICENSE.md
··· 1 + MIT License 2 + 3 + Copyright (c) 2017 Rudi Grinberg 4 + 5 + Permission is hereby granted, free of charge, to any person obtaining a copy 6 + of this software and associated documentation files (the "Software"), to deal 7 + in the Software without restriction, including without limitation the rights 8 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 + copies of the Software, and to permit persons to whom the Software is 10 + furnished to do so, subject to the following conditions: 11 + 12 + The above copyright notice and this permission notice shall be included in all 13 + copies or substantial portions of the Software. 14 + 15 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 + SOFTWARE.
+10
vendor/opam/stringext/Makefile
··· 1 + .PHONY: all clean test 2 + 3 + all: 4 + dune build 5 + 6 + test: 7 + dune runtest 8 + 9 + clean: 10 + rm -rf _build *.install
+83
vendor/opam/stringext/README.md
··· 1 + ## Stringext -- Extra string functions fo OCaml 2 + 3 + Extra string functions for OCaml. Mainly splitting. All functions are in the 4 + `Stringext` module. Here's a snippet of most useful functions out of the mli: 5 + 6 + ## Api Documentation 7 + 8 + ```ocaml 9 + (** string_after [s] [n] returns the substring of [s] that is after 10 + character [n] *) 11 + val string_after : string -> int -> string 12 + 13 + (** equivalent to [Str.quote] *) 14 + val quote : string -> string 15 + 16 + (** split [?max] [s] [~on] splits [s] on every [on] occurence upto 17 + [max] number of items if [max] is specified. [max] is assumed to 18 + be a small number if specified. To not cause stack overflows *) 19 + val split : ?max:int -> string -> on:char -> string list 20 + 21 + (** full_split [s] [~on] will split [s] on every occurence 22 + of [on] but will add the separators between the tokens. Maintains 23 + the invariant: 24 + 25 + String.concat (full_split s ~on) =s *) 26 + val full_split : string -> on:char -> string list 27 + 28 + (** Trims spaces on the left of the string. In case no trimming is needed 29 + the same string is returned without copying *) 30 + val trim_left : string -> string 31 + 32 + (** split_strim_left [s] [~on] [~trim] splits [s] on every character 33 + in [on]. Characters in [trim] are trimmed from the left of every 34 + result element *) 35 + val split_trim_left : string -> on:string -> trim:string -> string list 36 + 37 + val of_char : char -> string 38 + 39 + val of_list : char list -> string 40 + 41 + val to_list : string -> char list 42 + 43 + val to_array : string -> char array 44 + 45 + val of_array : char array -> string 46 + 47 + val find_from : ?start:int -> string -> pattern:string -> int option 48 + 49 + val replace_all : string -> pattern:string -> with_:string -> string 50 + 51 + val replace_all_assoc : string -> (string * string) list -> string 52 + 53 + val cut : string -> on:string -> (string * string) option 54 + (** [String.cut on s] is either the pair [Some (l,r)] of the two 55 + (possibly empty) substrings of [s] that are delimited by the first 56 + match of the non empty separator string [on] or [None] if [on] 57 + can't be matched in [s]. Matching starts from the beginning of [s]. 58 + 59 + The invariant [l ^ on ^ r = s] holds. 60 + 61 + @raise Invalid_argument if [on] is the empty string. *) 62 + 63 + val rcut : string -> on:string -> (string * string) option 64 + (** [String.rcut on s] is like {!cut} but the matching is done backwards 65 + starting from the end of [s]. 66 + 67 + @raise Invalid_argument if [on] is the empty string. *) 68 + 69 + val chop_prefix : string -> prefix:string -> string option 70 + 71 + val drop : string -> int -> string 72 + 73 + val take : string -> int -> string 74 + 75 + (** [trim_left_sub s ~pos ~len ~chars] Trim all characters inside [chars] 76 + from [s] starting from [pos] and up to [len] *) 77 + val trim_left_sub : string -> pos:int -> len:int -> chars:string -> string 78 + ``` 79 + 80 + ## Examples 81 + 82 + See the directory `examples`. This is a separate dune workspace, so install 83 + Stringext first.
+2
vendor/opam/stringext/dune-project
··· 1 + (lang dune 1.0) 2 + (name stringext)
+17
vendor/opam/stringext/examples/README.md
··· 1 + # stringext 2 + 3 + This example is for the stringext library 4 + 5 + https://opam.ocaml.org/packages/stringext 6 + 7 + # Source file 8 + 9 + `bin/main.ml` 10 + 11 + # Building and running 12 + 13 + `dune exec bin/main.exe` 14 + 15 + # Cleaning up 16 + 17 + `dune clean`
+3
vendor/opam/stringext/examples/bin/dune
··· 1 + (executable 2 + (name main) 3 + (libraries stringext))
+57
vendor/opam/stringext/examples/bin/main.ml
··· 1 + (* Exercise each function in Stringext. *) 2 + 3 + let go () = 4 + Printf.printf "After the space: %S\n" 5 + (Stringext.string_after "Mozart" 3); 6 + Printf.printf "Like Str.quote (but without Str): %S\n" 7 + (Stringext.quote "Some specials *+*+"); 8 + Printf.printf "Split makes %i splits\n" 9 + (List.length (Stringext.split "Mary had a little lamb" ~on:' ')); 10 + Printf.printf "Full split makes %i splits\n" 11 + (List.length (Stringext.full_split "Mary had a little lamb" ~on:' ')); 12 + Printf.printf "Trimming: %S\n" 13 + (Stringext.trim_left " <--- to here"); 14 + Printf.printf "split_trim_left: "; 15 + let strings = Stringext.split_trim_left "+one +two -three" ~on:" " ~trim:"+-" in 16 + List.iter (Printf.printf "%S ") strings; 17 + Printf.printf "\n"; 18 + Printf.printf "'a' with of_char is: %S\n" 19 + (Stringext.of_char 'a'); 20 + Printf.printf "of_list makes: %S\n" 21 + (Stringext.of_list (Stringext.to_list "chimpanzee")); 22 + Printf.printf "of_array and to_array makes: %S\n" 23 + (Stringext.of_array (Stringext.to_array "marzipan")); 24 + Printf.printf "find_from: %s\n" 25 + begin match Stringext.find_from ~start:5 "again and again" ~pattern:"again" with 26 + | None -> "" 27 + | Some x -> string_of_int x 28 + end; 29 + Printf.printf "replace_all: %S\n" 30 + (Stringext.replace_all "Again. And again. And again." ~pattern:"." ~with_:"!!"); 31 + Printf.printf "replace_all_assoc: %S\n" 32 + (Stringext.replace_all_assoc 33 + "Again. And again. And again" [(".", "!!"); ("And", "Yet")]); 34 + begin match Stringext.cut "cut<-->here" ~on:"<-->" with 35 + | Some (l, r) -> Printf.printf "cut: %S %S\n" l r 36 + | None -> () 37 + end; 38 + begin match Stringext.rcut "cut<-->here" ~on:"<-->" with 39 + | Some (l, r) -> Printf.printf "rcut: %S %S\n" l r 40 + | None -> () 41 + end; 42 + Printf.printf "chop_prefix: %S\n" 43 + begin match Stringext.chop_prefix "- list item" ~prefix:"- " with 44 + | None -> "" (* returns none if prefix not found *) 45 + | Some x -> x 46 + end; 47 + Printf.printf "drop: %S\n" 48 + (Stringext.drop "-------->" 5); 49 + Printf.printf "take: %S\n" 50 + (Stringext.take "-------->" 5); 51 + Printf.printf "trim_left_sub: %S\n" 52 + (Stringext.trim_left_sub "-23-56+89+" ~pos:0 ~len:10 ~chars:"+-") 53 + 54 + let () = 55 + match Sys.argv with 56 + | [|_|] -> go () 57 + | _ -> Printf.eprintf "stringext example: unknown command line\n"
+2
vendor/opam/stringext/examples/dune-project
··· 1 + (lang dune 3.14) 2 + (name stringext_example)
+2
vendor/opam/stringext/examples/dune-workspace
··· 1 + (lang dune 3.14) 2 + (env (dev (flags :standard -warn-error -A)))
+4
vendor/opam/stringext/lib/dune
··· 1 + (library 2 + (name stringext) 3 + (public_name stringext) 4 + (wrapped false))
+337
vendor/opam/stringext/lib/stringext.ml
··· 1 + open String 2 + 3 + let string_after s n = String.sub s n (String.length s - n) 4 + 5 + let quote s = 6 + let len = String.length s in 7 + let buf = Buffer.create (2 * len) in 8 + for i = 0 to len - 1 do 9 + match s.[i] with 10 + '[' | ']' | '*' | '.' | '\\' | '?' | '+' | '^' | '$' as c -> 11 + Buffer.add_char buf '\\'; 12 + Buffer.add_char buf c 13 + | c -> Buffer.add_char buf c 14 + done; 15 + Buffer.contents buf 16 + 17 + 18 + (* Not tail recursive for "performance", please choose low values for 19 + [max]. The idea is that max is always small because it's hard 20 + code *) 21 + let split_char_bounded str ~on ~max = 22 + if str = "" then [] 23 + else if max = 1 then [str] 24 + else 25 + let rec loop offset tokens = 26 + if tokens = max - 1 27 + then [sub str offset (length str - offset)] 28 + else 29 + try 30 + let index = index_from str offset on in 31 + if index = offset then 32 + ""::(loop (offset + 1) (tokens + 1)) 33 + else 34 + let token = String.sub str offset (index - offset) in 35 + token::(loop (index + 1) (tokens + 1)) 36 + with Not_found -> [sub str offset (length str - offset)] 37 + in loop 0 0 38 + 39 + let split_char_unbounded str ~on = 40 + if str = "" then [] 41 + else 42 + let rec loop acc offset = 43 + try begin 44 + let index = rindex_from str offset on in 45 + if index = offset then 46 + loop (""::acc) (index - 1) 47 + else 48 + let token = sub str (index + 1) (offset - index) in 49 + loop (token::acc) (index - 1) 50 + end 51 + with Not_found -> (sub str 0 (offset + 1))::acc 52 + in loop [] (length str - 1) 53 + 54 + let of_char = String.make 1 55 + 56 + let full_split str ~on = 57 + if str = "" then [] 58 + else 59 + let sep = of_char on in 60 + let rec loop acc offset = 61 + try begin 62 + let index = rindex_from str offset on in 63 + if index = offset then 64 + loop (sep::acc) (index - 1) 65 + else 66 + let token = sub str (index + 1) (offset - index) in 67 + loop (sep::token::acc) (index - 1) 68 + end 69 + with Not_found -> 70 + if offset >= 0 71 + then (sub str 0 (offset + 1))::acc 72 + else acc 73 + in loop [] (length str - 1) 74 + 75 + (* copying core's convention for String.split but with an optional max 76 + argument *) 77 + let split ?max s ~on = 78 + match max with 79 + | None -> split_char_unbounded s ~on 80 + | Some max -> (* assert (max < 100); *) 81 + split_char_bounded s ~on ~max 82 + 83 + let rindex_from_on s ~offset ~on = 84 + let rec loop i = 85 + if i < 0 then raise Not_found 86 + else if String.contains on s.[i] then i 87 + else loop (i - 1) 88 + in loop offset 89 + 90 + let trim_left_sub s ~pos ~len ~chars = 91 + let start_pos = 92 + let final = pos + len in 93 + let rec loop last_char i = 94 + if i = final then last_char 95 + else if String.contains chars s.[i] then loop (i + 1) (i + 1) 96 + else last_char 97 + in loop pos pos 98 + in 99 + let new_len = len - (start_pos - pos) in 100 + String.sub s start_pos new_len 101 + 102 + let split_trim_left str ~on ~trim = 103 + if str = "" then [] 104 + else 105 + let rec loop acc offset = 106 + try begin 107 + let index = rindex_from_on str ~offset ~on in 108 + if index = offset then 109 + loop (""::acc) (index - 1) 110 + else 111 + let token = trim_left_sub str ~pos:(index + 1) 112 + ~len:(offset - index) ~chars:trim in 113 + loop (token::acc) (index - 1) 114 + end 115 + with Not_found -> 116 + (trim_left_sub str ~pos:0 ~len:(offset + 1) ~chars:trim)::acc 117 + in loop [] (length str - 1) 118 + 119 + exception Found_int of int 120 + 121 + let first_char_ne s c = 122 + String.length s > 0 && s.[0] <> c 123 + 124 + let trim_left s = 125 + if first_char_ne s ' ' then s 126 + else 127 + let len = String.length s in 128 + try 129 + for i=0 to len - 1 do 130 + if s.[i] <> ' ' then raise (Found_int i) 131 + done; 132 + "" 133 + with Found_int non_space -> 134 + sub s non_space (len - non_space) 135 + 136 + let substr_eq ?(start=0) s ~pattern = 137 + try 138 + for i = 0 to String.length pattern - 1 do 139 + if s.[i + start] <> pattern.[i] then raise Exit 140 + done; 141 + true 142 + with _ -> false 143 + 144 + let find_from ?(start=0) str ~pattern = 145 + try 146 + for i = start to (String.length str) - (String.length pattern) do 147 + if substr_eq ~start:i str ~pattern then 148 + raise (Found_int i) 149 + done; 150 + None 151 + with 152 + | Found_int i -> Some i 153 + | _ -> None 154 + 155 + let find_min l ~f = 156 + let rec loop x fx = function 157 + | [] -> Some (x, fx) 158 + | x'::xs -> 159 + let fx' = f x' in 160 + if fx' < fx then loop x' fx' xs 161 + else loop x fx xs 162 + in 163 + match l with 164 + | [] -> None 165 + | x::xs -> loop x (f x) xs 166 + 167 + let replace_all str ~pattern ~with_ = 168 + let (slen, plen) = String.(length str, length pattern) in 169 + let buf = Buffer.create slen in 170 + let rec loop i = 171 + match find_from ~start:i str ~pattern with 172 + | None -> 173 + Buffer.add_substring buf str i (slen - i); 174 + Buffer.contents buf 175 + | Some j -> 176 + Buffer.add_substring buf str i (j - i); 177 + Buffer.add_string buf with_; 178 + loop (j + plen) 179 + in loop 0 180 + 181 + exception Found_replace of int * string * string 182 + 183 + let replace_all_assoc str tbl = 184 + let slen = String.length str in 185 + let buf = Buffer.create slen in 186 + let rec loop i = 187 + if i >= slen then Buffer.contents buf 188 + else 189 + let r = 190 + try 191 + let found = ref false in 192 + let e = 193 + find_min tbl ~f:(fun (pattern, with_) -> 194 + match find_from ~start:i str ~pattern with 195 + | None -> max_int 196 + | Some j when j = i -> raise (Found_replace (j, pattern, with_)) 197 + | Some j -> found := true; j) 198 + in 199 + match e with 200 + | None -> None 201 + | Some ((pattern, with_), j) when !found -> Some (j, pattern, with_) 202 + | Some _ -> None 203 + with Found_replace (j, pattern, with_) -> Some (j, pattern, with_) 204 + in 205 + match r with 206 + | None -> 207 + Buffer.add_substring buf str i (slen - i); 208 + Buffer.contents buf 209 + | Some (j, pattern, with_) -> 210 + Buffer.add_substring buf str i (j - i); 211 + Buffer.add_string buf with_; 212 + loop (j + String.length pattern) 213 + in loop 0 214 + 215 + let iteri f l = 216 + let rec loop i = function 217 + | [] -> () 218 + | x::xs -> (f i x); loop (succ i) xs 219 + in loop 0 l 220 + 221 + let of_list xs = 222 + let l = List.length xs in 223 + let s = Bytes.create l in 224 + iteri (fun i c -> Bytes.set s i c) xs; 225 + Bytes.unsafe_to_string s 226 + 227 + let to_list s = 228 + let rec loop acc i = 229 + if i = -1 then acc 230 + else 231 + loop (s.[i] :: acc) (pred i) 232 + in loop [] (String.length s - 1) 233 + 234 + let of_array a = 235 + let len = Array.length a in 236 + let bytes = Bytes.create len in 237 + for i = 0 to len - 1 do 238 + Bytes.set bytes i a.(i) 239 + done; 240 + Bytes.unsafe_to_string bytes 241 + 242 + let to_array s = Array.init (String.length s) (String.get s) 243 + 244 + (* ripped off from one of dbuenzli's libs *) 245 + let cut s ~on = 246 + let sep_max = length on - 1 in 247 + if sep_max < 0 then invalid_arg "Stringext.cut: empty separator" else 248 + let s_max = length s - 1 in 249 + if s_max < 0 then None else 250 + let k = ref 0 in 251 + let i = ref 0 in 252 + (* We run from the start of [s] to end with [i] trying to match the 253 + first character of [on] in [s]. If this matches, we verify that 254 + the whole [on] is matched using [k]. If it doesn't match we 255 + continue to look for [on] with [i]. If it matches we exit the 256 + loop and extract a substring from the start of [s] to the 257 + position before the [on] we found and another from the position 258 + after the [on] we found to end of string. If [i] is such that no 259 + separator can be found we exit the loop and return the no match 260 + case. *) 261 + try 262 + while (!i + sep_max <= s_max) do 263 + (* Check remaining [on] chars match, access to unsafe s (!i + !k) is 264 + guaranteed by loop invariant. *) 265 + if unsafe_get s !i <> unsafe_get on 0 then incr i else begin 266 + k := 1; 267 + while (!k <= sep_max && unsafe_get s (!i + !k) = unsafe_get on !k) 268 + do incr k done; 269 + if !k <= sep_max then (* no match *) incr i else raise Exit 270 + end 271 + done; 272 + None (* no match in the whole string. *) 273 + with 274 + | Exit -> (* i is at the beginning of the separator *) 275 + let left_end = !i - 1 in 276 + let right_start = !i + sep_max + 1 in 277 + Some (sub s 0 (left_end + 1), 278 + sub s right_start (s_max - right_start + 1)) 279 + 280 + let rcut s ~on = 281 + let sep_max = length on - 1 in 282 + if sep_max < 0 then invalid_arg "Stringext.rcut: empty separator" else 283 + let s_max = length s - 1 in 284 + if s_max < 0 then None else 285 + let k = ref 0 in 286 + let i = ref s_max in 287 + (* We run from the end of [s] to the beginning with [i] trying to 288 + match the last character of [on] in [s]. If this matches, we 289 + verify that the whole [on] is matched using [k] (we do that 290 + backwards). If it doesn't match we continue to look for [on] 291 + with [i]. If it matches we exit the loop and extract a 292 + substring from the start of [s] to the position before the 293 + [on] we found and another from the position after the [on] we 294 + found to end of string. If [i] is such that no separator can 295 + be found we exit the loop and return the no match case. *) 296 + try 297 + while (!i >= sep_max) do 298 + if unsafe_get s !i <> unsafe_get on sep_max then decr i else begin 299 + (* Check remaining [on] chars match, access to unsafe_get 300 + s (sep_start + !k) is guaranteed by loop invariant. *) 301 + let sep_start = !i - sep_max in 302 + k := sep_max - 1; 303 + while (!k >= 0 && unsafe_get s (sep_start + !k) = unsafe_get on !k) 304 + do decr k done; 305 + if !k >= 0 then (* no match *) decr i else raise Exit 306 + end 307 + done; 308 + None (* no match in the whole string. *) 309 + with 310 + | Exit -> (* i is at the end of the separator *) 311 + let left_end = !i - sep_max - 1 in 312 + let right_start = !i + 1 in 313 + Some (sub s 0 (left_end + 1), 314 + sub s right_start (s_max - right_start + 1)) 315 + 316 + let chop_prefix s ~prefix = 317 + let prefix_l = String.length prefix in 318 + let string_l = String.length s in 319 + if prefix_l > string_l then None 320 + else 321 + try 322 + for i = 0 to prefix_l - 1 do 323 + if s.[i] <> prefix.[i] then raise Exit; 324 + done; 325 + Some (String.sub s prefix_l (string_l - prefix_l)) 326 + with _ -> None 327 + 328 + let drop s n = 329 + let l = String.length s in 330 + if n >= l 331 + then "" 332 + else String.sub s n (l - n) 333 + 334 + let take s n = 335 + if n >= String.length s 336 + then s 337 + else String.sub s 0 n
+72
vendor/opam/stringext/lib/stringext.mli
··· 1 + (** Misc. string functions not found in the built in OCaml string 2 + module *) 3 + 4 + (** string_after [s] [n] returns the substring of [s] that is after 5 + character [n] *) 6 + val string_after : string -> int -> string 7 + 8 + (** equivalent to [Str.quote] *) 9 + val quote : string -> string 10 + 11 + (** split [?max] [s] [~on] splits [s] on every [on] occurence upto 12 + [max] number of items if [max] is specified. [max] is assumed to 13 + be a small number if specified. To not cause stack overflows *) 14 + val split : ?max:int -> string -> on:char -> string list 15 + 16 + (** full_split [s] [~on] will split [s] on every occurence 17 + of [on] but will add the separators between the tokens. Maintains 18 + the invariant: 19 + 20 + String.concat (full_split s ~on) =s *) 21 + val full_split : string -> on:char -> string list 22 + 23 + (** Trims spaces on the left of the string. In case no trimming is needed 24 + the same string is returned without copying *) 25 + val trim_left : string -> string 26 + 27 + (** split_strim_left [s] [~on] [~trim] splits [s] on every character 28 + in [on]. Characters in [trim] are trimmed from the left of every 29 + result element *) 30 + val split_trim_left : string -> on:string -> trim:string -> string list 31 + 32 + val of_char : char -> string 33 + 34 + val of_list : char list -> string 35 + 36 + val to_list : string -> char list 37 + 38 + val to_array : string -> char array 39 + 40 + val of_array : char array -> string 41 + 42 + val find_from : ?start:int -> string -> pattern:string -> int option 43 + 44 + val replace_all : string -> pattern:string -> with_:string -> string 45 + 46 + val replace_all_assoc : string -> (string * string) list -> string 47 + 48 + val cut : string -> on:string -> (string * string) option 49 + (** [String.cut on s] is either the pair [Some (l,r)] of the two 50 + (possibly empty) substrings of [s] that are delimited by the first 51 + match of the non empty separator string [on] or [None] if [on] 52 + can't be matched in [s]. Matching starts from the beginning of [s]. 53 + 54 + The invariant [l ^ on ^ r = s] holds. 55 + 56 + @raise Invalid_argument if [on] is the empty string. *) 57 + 58 + val rcut : string -> on:string -> (string * string) option 59 + (** [String.rcut on s] is like {!cut} but the matching is done backwards 60 + starting from the end of [s]. 61 + 62 + @raise Invalid_argument if [on] is the empty string. *) 63 + 64 + val chop_prefix : string -> prefix:string -> string option 65 + 66 + val drop : string -> int -> string 67 + 68 + val take : string -> int -> string 69 + 70 + (** [trim_left_sub s ~pos ~len ~chars] Trim all characters inside [chars] 71 + from [s] starting from [pos] and up to [len] *) 72 + val trim_left_sub : string -> pos:int -> len:int -> chars:string -> string
+17
vendor/opam/stringext/lib_test/dune
··· 1 + (executables 2 + (names test_stringext test_stringext_qcheck) 3 + (libraries stringext ounit2 qcheck)) 4 + 5 + (alias 6 + (name runtest) 7 + (deps 8 + (:< test_stringext.exe)) 9 + (action 10 + (run %{<}))) 11 + 12 + (alias 13 + (name runtest) 14 + (deps 15 + (:< test_stringext_qcheck.exe)) 16 + (action 17 + (run %{<})))
+240
vendor/opam/stringext/lib_test/test_stringext.ml
··· 1 + open OUnit2 2 + 3 + let (|>) x f = f x 4 + 5 + let printer elems = 6 + "[" ^ (elems 7 + |> List.map (fun x -> "\"" ^ x ^ "\"") 8 + |> String.concat ";") 9 + ^ "]" 10 + 11 + let test_split_1 _ = 12 + let strings = Stringext.split "test:one:two" ~on:':' in 13 + assert_equal ~printer ["test";"one";"two"] strings 14 + 15 + let test_split_bounded_1 _ = 16 + let strings = Stringext.split "testing:foo:bar" ~on:':' ~max:2 in 17 + assert_equal ~printer ["testing";"foo:bar"] strings 18 + 19 + let test_split_none _ = 20 + let s = "foo:bar" in 21 + assert_equal ~printer [s] (Stringext.split s ~on:'=') 22 + 23 + let split_trim_left1 _ = 24 + let strings = Stringext.split_trim_left 25 + " testing, stuff; \t again" ~on:",;" ~trim:" \t" in 26 + assert_equal ~printer ["testing";"stuff";"again"] strings 27 + 28 + let split_trim_left2 _ = 29 + let strings = Stringext.split_trim_left 30 + " testing,stuff;\t again" ~on:",;" ~trim:" \t" in 31 + assert_equal ~printer ["testing";"stuff";"again"] strings 32 + 33 + let split_trim_left3 _ = 34 + assert_equal ~printer 35 + ["a ";"b ";"c"] 36 + (Stringext.split_trim_left ~on:"," ~trim:" " "a ,b ,c") 37 + 38 + let split_trim_left4 _ = 39 + assert_equal ~printer 40 + ["vpof "; "hbjeu "; ""; "c"] 41 + (Stringext.split_trim_left ~on:"," ~trim:" " "vpof ,hbjeu , ,c") 42 + 43 + let printer s = "'" ^ (String.concat ";" s) ^ "'" 44 + 45 + let full_split1 _ = 46 + let strings = Stringext.full_split 47 + "//var/test//ocaml/" ~on:'/' in 48 + assert_equal ~printer 49 + ["/";"/";"var";"/";"test";"/";"/";"ocaml";"/"] strings 50 + 51 + let full_split2 _ = 52 + let strings = Stringext.full_split "//foobar.com/quux" ~on:'/' in 53 + assert_equal ~printer 54 + ["/";"/";"foobar.com";"/";"quux"] strings 55 + 56 + let full_split3 _ = 57 + let strings = Stringext.full_split "foobar.com/quux" ~on:'/' in 58 + assert_equal ~printer 59 + ["foobar.com";"/";"quux"] strings 60 + 61 + let full_split4 _ = 62 + let strings = Stringext.full_split "a/path/fragment" ~on:'/' in 63 + assert_equal ~printer 64 + ["a";"/";"path";"/";"fragment"] strings 65 + 66 + let (to_list, of_list) = Stringext.(to_list, of_list) 67 + 68 + let to_list1 _ = assert_equal ['o';'c';'a';'m';'l'] (to_list "ocaml") 69 + 70 + let to_list2 _ = assert_equal [] (to_list "") 71 + 72 + let of_list1 _ = assert_equal "" (of_list []) 73 + 74 + let of_list2 _ = assert_equal "ocaml" (of_list ['o';'c';'a';'m';'l']) 75 + 76 + let s = "testing one two three" 77 + 78 + let opt_int = function 79 + | None -> "none" 80 + | Some x -> string_of_int x 81 + 82 + let find_from1 _ = 83 + let r = Stringext.find_from s ~pattern:"ocaml" in 84 + assert_equal None r 85 + 86 + let find_from2 _ = 87 + let r = Stringext.find_from s ~pattern:"testing" in 88 + assert_equal (Some 0) r 89 + 90 + let find_from3 _ = 91 + let r = Stringext.find_from s ~pattern:"one" in 92 + assert_equal (Some 8) r 93 + 94 + let find_from4 _ = 95 + let r = Stringext.find_from s ~pattern:"threee" in 96 + assert_equal None r 97 + 98 + let find_from5 _ = 99 + let r = Stringext.find_from s ~pattern:" " in 100 + assert_equal (Some 7) r 101 + 102 + let find_from6 _ = 103 + let pattern = "three" in 104 + let r = Stringext.find_from s ~pattern in 105 + assert_equal ~printer:opt_int 106 + (Some (String.length s - String.length pattern)) r 107 + 108 + let replace_all1 _ = 109 + let s = "the quick brown fox brown." in 110 + let s' = Stringext.replace_all s ~pattern:"brown" ~with_:"blue" in 111 + assert_equal ~printer:(fun x -> x) "the quick blue fox blue." s' 112 + 113 + let replace_all2 _ = 114 + let s = "one two three" in 115 + let s' = Stringext.replace_all s ~pattern:" " ~with_:"_" in 116 + assert_equal ~printer:(fun x -> x) "one_two_three" s' 117 + 118 + let replace_all_assoc1 _ = 119 + let s = "hello from ocaml" in 120 + let tbl = [("hello", "goodbye"); ("ocaml", "haskell")] in 121 + let s' = Stringext.replace_all_assoc s tbl in 122 + assert_equal ~printer:(fun x -> x) "goodbye from haskell" s' 123 + 124 + let replace_all_assoc2 _ = 125 + let s = "one two three" in 126 + let t = [("one", "four"); ("two", "five"); ("three", "six"); (" ", "_")] in 127 + let s' = Stringext.replace_all_assoc s t in 128 + assert_equal ~printer:(fun x -> x) "four_five_six" s' 129 + 130 + let replace_all_assoc3 _ = 131 + let s = "one two three" in 132 + let t = [(" ", "_")] in 133 + let s' = Stringext.replace_all_assoc s t in 134 + assert_equal ~printer:(fun x -> x) "one_two_three" s' 135 + 136 + let replace_all_assoc4 _ = 137 + let s = "onetwo" in 138 + let t = [("one", "xxxx"); ("two", "yyy")] in 139 + let s' = Stringext.replace_all_assoc s t in 140 + assert_equal ~printer:(fun x -> x) "xxxxyyy" s' 141 + 142 + let of_array1 _ = 143 + let s = [| 'a'; 'b'; 'c' |] in 144 + assert_equal "abc" (Stringext.of_array s) 145 + 146 + let trim_left_sub1 _ = 147 + let s = "testing" in 148 + assert_equal ~printer:(fun x -> x) 149 + s (Stringext.trim_left_sub s ~pos:0 ~len:(String.length s) ~chars:" ") 150 + 151 + let trim_left_sub2 _ = 152 + let s = " , testing" in 153 + assert_equal ~printer:(fun x -> x) 154 + "testing" 155 + (Stringext.trim_left_sub s ~pos:0 ~len:(String.length s) ~chars:" ,") 156 + 157 + let trim_left_sub3 _ = 158 + let s = " , testing" in 159 + assert_equal ~printer:(fun x -> x) 160 + "test" (Stringext.trim_left_sub s ~pos:0 ~len:(7) ~chars:" ,") 161 + 162 + let trim_left_sub4 _ = 163 + let s = "a a" in 164 + assert_equal ~printer:(fun x -> x) 165 + s (Stringext.trim_left_sub s ~pos:0 ~len:3 ~chars:" ") 166 + 167 + let trim_left_sub5 _ = 168 + assert_equal ~printer:(fun x -> x) 169 + "a" (Stringext.trim_left_sub "a" ~pos:0 ~len:1 ~chars:" ") 170 + 171 + let trim_left1 _ = 172 + assert_equal ~printer:(fun x -> x) "" (Stringext.trim_left " ") 173 + 174 + let trim_left2 _ = 175 + assert_equal ~printer:(fun x -> x) "" (Stringext.trim_left "") 176 + 177 + let test_fixtures = 178 + "test various string functions" >::: 179 + [ "test split char 1" >:: test_split_1 180 + ; "test split bounded 1" >:: test_split_bounded_1 181 + ; "test split none" >:: test_split_none 182 + ; "split trim left1" >:: split_trim_left1 183 + ; "split trim left2" >:: split_trim_left2 184 + ; "split trim left3" >:: split_trim_left3 185 + ; "split trim left4" >:: split_trim_left4 186 + ; "trim left sub1" >:: trim_left_sub1 187 + ; "trim left sub2" >:: trim_left_sub2 188 + ; "trim left sub3" >:: trim_left_sub3 189 + ; "trim left sub4" >:: trim_left_sub4 190 + ; "trim left sub5" >:: trim_left_sub5 191 + ; "trim left1" >:: trim_left1 192 + ; "trim left2" >:: trim_left2 193 + ; "full split1" >:: full_split1 194 + ; "full split2" >:: full_split2 195 + ; "full split3" >:: full_split3 196 + ; "full split4" >:: full_split4 197 + ; "to_list1" >:: to_list1 198 + ; "to_list2" >:: to_list2 199 + ; "of_list1" >:: of_list1 200 + ; "of_list2" >:: of_list2 201 + ; "find_from1" >:: find_from1 202 + ; "find_from2" >:: find_from2 203 + ; "find_from3" >:: find_from3 204 + ; "find_from4" >:: find_from4 205 + ; "find_from5" >:: find_from5 206 + ; "find_from6" >:: find_from6 207 + ; "replace_all1" >:: replace_all1 208 + ; "replace_all2" >:: replace_all2 209 + ; "replace_all_assoc1" >:: replace_all_assoc1 210 + ; "replace_all_assoc2" >:: replace_all_assoc2 211 + ; "replace_all_assoc3" >:: replace_all_assoc3 212 + ; "replace_all_assoc4" >:: replace_all_assoc4 213 + ; "chop_prefix" >:: (fun _ -> 214 + let ae = assert_equal ~printer:(function 215 + | Some x -> "Some " ^ x 216 + | None -> "None") in 217 + ae (Some "bar") (Stringext.chop_prefix "foobar" ~prefix:"foo"); 218 + ae None (Stringext.chop_prefix "foobar" ~prefix:"bar"); 219 + ae (Some "foobar") (Stringext.chop_prefix "foobar" ~prefix:""); 220 + ae (Some "") (Stringext.chop_prefix "foobar" ~prefix:"foobar") 221 + ) 222 + ; "take" >:: (fun _ -> 223 + let ae = assert_equal ~printer:(fun x -> x) in 224 + ae "foo" (Stringext.take "foobar" 3); 225 + ae "bar" (Stringext.take "bar" 5); 226 + ae "" (Stringext.take "" 0); 227 + ae "" (Stringext.take "xxx" 0) 228 + ) 229 + ; "drop" >:: (fun _ -> 230 + let ae = assert_equal ~printer:(fun x -> x) in 231 + ae "foobar" (Stringext.drop "foobar" 0); 232 + ae "bar" (Stringext.drop "foobar" 3); 233 + ae "" (Stringext.drop "" 5); 234 + ae "" (Stringext.drop "foobar" 99) 235 + ) 236 + ; "of_array" >:: of_array1 ] 237 + 238 + let _ = run_test_tt_main test_fixtures 239 + 240 +
+24
vendor/opam/stringext/lib_test/test_stringext_qcheck.ml
··· 1 + open QCheck 2 + 3 + let (|>) x f = f x 4 + 5 + let quoted_str = Printf.sprintf "%S" 6 + 7 + let run lst = 8 + OUnit2.run_test_tt_main (QCheck_runner.to_ounit2_test lst) 9 + 10 + let _ = run ( 11 + let f1 s = Stringext.split_trim_left ~on:"," ~trim:" " s in 12 + let f2 s = Stringext.split ~on:',' s |> List.map Stringext.trim_left in 13 + let pp str = 14 + (quoted_str str) ^ " -> " ^ 15 + (Print.list quoted_str (f1 str)) ^ " != " ^ 16 + (Print.list quoted_str (f2 str)) 17 + in 18 + Test.make ~name:"stringext.split_trim_left == split |> trim_left" ~small:String.length 19 + ((pair (oneofl [",";" ,";", ";" , "]) (list_of_size (Gen.int_bound 3) printable_string)) |> 20 + map (fun (sep,sub) -> String.concat sep sub) |> 21 + set_shrink Shrink.string |> 22 + set_print pp) 23 + (fun s -> f1 s = f2 s) 24 + )
+23
vendor/opam/stringext/stringext.opam
··· 1 + opam-version: "2.0" 2 + maintainer: "rudi.grinberg@gmail.com" 3 + authors: "Rudi Grinberg" 4 + license: "MIT" 5 + homepage: "https://github.com/rgrinberg/stringext" 6 + bug-reports: "https://github.com/rgrinberg/stringext/issues" 7 + depends: [ 8 + "ocaml" {>= "4.02.3"} 9 + "dune" {build & >= "1.0"} 10 + "ounit2" {with-test} 11 + "qtest" {with-test & >= "2.2"} 12 + ] 13 + build: [ 14 + ["dune" "subst"] {pinned} 15 + ["dune" "build" "-p" name "-j" jobs] 16 + ["dune" "runtest" "-p" name "-j" jobs] {with-test} 17 + ] 18 + dev-repo: "git+https://github.com/rgrinberg/stringext.git" 19 + synopsis: "Extra string functions for OCaml" 20 + description: """ 21 + Extra string functions for OCaml. Mainly splitting. All functions are in the 22 + Stringext module. 23 + """