1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
include String
@BEGIN_BEFORE_4_07_0@
let of_seq g = Buffer.contents (Stdcompat__buffer.of_seq g)
let to_seq s = Stdcompat__tools.vec_to_seq length unsafe_get s
let to_seqi s = Stdcompat__tools.vec_to_seqi length unsafe_get s
@END_BEFORE_4_07_0@
@BEGIN_BEFORE_4_05_0@
let index_opt s c =
Stdcompat__tools.option_find (index s) c
let rindex_opt s c =
Stdcompat__tools.option_find (rindex s) c
let index_from_opt s i c =
Stdcompat__tools.option_find (index_from s i) c
let rindex_from_opt s i c =
Stdcompat__tools.option_find (rindex_from s i) c
@END_BEFORE_4_05_0@
@BEGIN_BEFORE_4_04_0@
let split_on_char c s =
let previous_index = ref (length s) in
let accu = ref [] in
for i = length s - 1 downto 0 do
if unsafe_get s i = c then
begin
accu := sub s (i + 1) (!previous_index - i - 1) :: !accu;
previous_index := i
end
done;
sub s 0 !previous_index :: !accu
@END_BEFORE_4_04_0@
@BEGIN_BEFORE_4_03_0@
let lowercase_ascii = lowercase
let uppercase_ascii = uppercase
let capitalize_ascii = capitalize
let uncapitalize_ascii = uncapitalize
let equal : t -> t -> bool = ( = )
@END_BEFORE_4_03_0@
@BEGIN_BEFORE_4_02_0@
let init n f =
let s = create n in
for i = 0 to n - 1 do
s.[i] <- f i
done;
s
let mapi f s =
init (length s) (fun i -> f i (unsafe_get s i))
@END_BEFORE_4_02_0@
@BEGIN_BEFORE_4_00_0@
let iteri f s =
for i = 0 to length s - 1 do
f i (unsafe_get s i)
done
let map f s =
init (length s) (fun i -> f (unsafe_get s i))
let is_space = function
| ' ' | '\012' | '\n' | '\r' | '\t' -> true
| _ -> false
let rec rindex_no_space_from i s =
if i >= 0 && is_space (unsafe_get s i) then
rindex_no_space_from (pred i) s
else
i
let rec index_no_space_between i j s =
if i <= j && is_space (unsafe_get s i) then
index_no_space_between (succ i) j s
else
i
let trim s =
let off_end = rindex_no_space_from (length s - 1) s in
let off_start = index_no_space_between 0 off_end s in
if off_start > off_end then
""
else if off_start = 0 && off_end = length s - 1 then
s
else
sub s off_start (off_end - off_start + 1)
@END_BEFORE_4_00_0@
|