package regenerate
Library
Module
Module type
Parameter
Class
Class type
include module type of struct include CCString end
Basic String Utils
type 'a klist = unit -> [ `Nil | `Cons of 'a * 'a klist ]
Common Signature
module type S = CCString.S
Strings
include module type of struct include Stdlib.String end
val to_seqi : t -> (int * char) Stdlib.Seq.t
pad n str
ensures that str
is at least n
bytes long, and pads it on the side
with c
if it's not the case.
val of_gen : char gen -> string
Convert a gen
of characters to a string.
val of_iter : char iter -> string
Convert a iter
of characters to a string.
val of_seq : char sequence -> string
val of_klist : char klist -> string
Find sub
in string, returns its first index or -1
.
val find_all : ?start:int -> sub:string -> string -> int gen
find_all ~sub s
finds all occurrences of sub
in s
, even overlapping instances.
find_all_l ~sub s
finds all occurrences of sub
in s
and returns them in a list.
Find sub
in string from the right, returns its first index or -1
. Should only be used with very small sub
.
replace ~sub ~by s
replaces some occurrences of sub
by by
in s
.
is_sub ~sub i s j ~sub_len
returns true
iff the substring of sub
starting at position i
and of length sub_len
is a substring of s
starting at position j
.
chop_prefix ~pre s
removes pre
from s
if pre
really is a prefix of s
, returns None
otherwise.
chop_suffix ~suf s
removes suf
from s
if suf
really is a suffix of s
, returns None
otherwise.
val lines_gen : string -> string gen
lines_gen s
returns a generator of the lines of s
(splits along '\n').
val concat_gen : sep:string -> string gen -> string
concat_gen ~sep g
concatenates all strings of g
, separated with sep
.
val unlines_gen : string gen -> string
unlines_gen g
concatenates all strings of g
, separated with '\n'.
set s i c
creates a new string which is a copy of s
, except for index i
, which becomes c
.
Alias to String.iter
.
filter_map f s
calls (f a0) (f a1) ... (f an)
where a0 ... an
are the characters of s. It returns the string of characters ci
such as f ai = Some ci
(when f
returns None
, the corresponding element of s
is discarded).
Map each chars to a string, then concatenates them all.
include S with type t := string
Like String.blit
. Compatible with the -safe-string
option.
Conversions
val to_gen : string -> char CCString.gen
Return the gen
of characters contained in the string.
val to_iter : string -> char CCString.iter
Return the iter
of characters contained in the string.
val to_klist : string -> char CCString.klist
drop_while f s
discards any characters starting from the left, up to the first character c
not satisfying f c
.
rdrop_while f s
discards any characters starting from the right, up to the first character c
not satisfying f c
.
Trim space on the left (see String.trim
for more details).
Trim space on the right (see String.trim
for more details).
Operations on 2 strings
Iterate on pairs of chars with their index.
All pairs of chars respect the predicate?
Ascii functions
Those functions are deprecated in String
since 4.03, so we provide a stable alias for them even in older versions.
See String
.
See String
.
See String
.
See String
.
Finding
A relatively efficient algorithm for finding sub-strings.
module Find = CCString.Find
Splitting
module Split = CCString.Split
Alias to Split.list_cpy
.
Utils
compare_versions a b
compares version strings a
and b
, considering that numbers are above text.
Natural Sort Order, comparing chunks of digits as natural numbers. https://en.wikipedia.org/wiki/Natural_sort_order
Edition distance between two strings. This satisfies the classical distance axioms: it is always positive, symmetric, and satisfies the formula distance a b + distance b c >= distance a c
.
Slices
A contiguous part of a string
module Sub = CCString.Sub