package containers
Install
Dune Dependency
Authors
Maintainers
Sources
md5=d84e09c5d0abc501aa17cd502e31a038
sha512=8b832f4ada6035e80d81be0cfb7bdffb695ec67d465ed6097a144019e2b8a8f909095e78019c3da2d8181cc3cd730cd48f7519e87d3162442562103b7f36aabb
doc/containers/CCStringLabels/index.html
Module CCStringLabels
Source
Basic String Utils
Fast internal iterator.
Common Signature
Strings
include module type of struct include StringLabels end
Strings
The type for strings.
make n c
is a string of length n
with each index holding the character c
.
The empty string.
Return a new string that contains the same bytes as the given byte sequence.
Return a new byte sequence that contains the same bytes as the given string.
get s i
is the character at index i
in s
. This is the same as writing s.[i]
.
Concatenating
Note. The Stdlib.(^)
binary operator concatenates two strings.
concat ~sep ss
concatenates the list of strings ss
, inserting the separator string sep
between each.
cat s1 s2
concatenates s1 and s2 (s1 ^ s2
).
Predicates and comparisons
starts_with
~prefix s
is true
if and only if s
starts with prefix
.
ends_with
~suffix s
is true
if and only if s
ends with suffix
.
contains_from s start c
is true
if and only if c
appears in s
after position start
.
rcontains_from s stop c
is true
if and only if c
appears in s
before position stop+1
.
contains s c
is String.contains_from
s 0 c
.
Extracting substrings
sub s ~pos ~len
is a string of length len
, containing the substring of s
that starts at position pos
and has length len
.
Transforming
fold_left f x s
computes f (... (f (f x s.[0]) s.[1]) ...) s.[n-1]
, where n
is the length of the string s
.
fold_right f s x
computes f s.[0] (f s.[1] ( ... (f s.[n-1] x) ...))
, where n
is the length of the string s
.
trim s
is s
without leading and trailing whitespace. Whitespace characters are: ' '
, '\x0C'
(form feed), '\n'
, '\r'
, and '\t'
.
escaped s
is s
with special characters represented by escape sequences, following the lexical conventions of OCaml.
All characters outside the US-ASCII printable range [0x20;0x7E] are escaped, as well as backslash (0x2F) and double-quote (0x22).
The function Scanf.unescaped
is a left inverse of escaped
, i.e. Scanf.unescaped (escaped s) = s
for any string s
(unless escaped s
fails).
Traversing
Searching
index_from s i c
is the index of the first occurrence of c
in s
after position i
.
index_from_opt s i c
is the index of the first occurrence of c
in s
after position i
(if any).
rindex_from s i c
is the index of the last occurrence of c
in s
before position i+1
.
rindex_from_opt s i c
is the index of the last occurrence of c
in s
before position i+1
(if any).
index s c
is String.index_from
s 0 c
.
index_opt s c
is String.index_from_opt
s 0 c
.
rindex s c
is String.rindex_from
s (length s - 1) c
.
rindex_opt s c
is String.rindex_from_opt
s (length s - 1) c
.
Strings and Sequences
to_seqi s
is like to_seq
but also tuples the corresponding index.
UTF decoding and validations
UTF-8
get_utf_8_uchar b i
decodes an UTF-8 character at index i
in b
.
is_valid_utf_8 b
is true
if and only if b
contains valid UTF-8 data.
UTF-16BE
get_utf_16be_uchar b i
decodes an UTF-16BE character at index i
in b
.
is_valid_utf_16be b
is true
if and only if b
contains valid UTF-16BE data.
UTF-16LE
get_utf_16le_uchar b i
decodes an UTF-16LE character at index i
in b
.
is_valid_utf_16le b
is true
if and only if b
contains valid UTF-16LE data.
Deprecated functions
create n
returns a fresh byte sequence of length n
. The sequence is uninitialized and contains arbitrary bytes.
Return a copy of the given string.
fill s ~pos ~len c
modifies byte sequence s
in place, replacing len
bytes by c
, starting at pos
.
Return a copy of the argument, with all lowercase letters translated to uppercase, including accented letters of the ISO Latin-1 (8859-1) character set.
Return a copy of the argument, with all uppercase letters translated to lowercase, including accented letters of the ISO Latin-1 (8859-1) character set.
Return a copy of the argument, with the first character set to uppercase, using the ISO Latin-1 (8859-1) character set..
Return a copy of the argument, with the first character set to lowercase, using the ISO Latin-1 (8859-1) character set.
Binary decoding of integers
The functions in this section binary decode integers from strings.
All following functions raise Invalid_argument
if the characters needed at index i
to decode the integer are not available.
Little-endian (resp. big-endian) encoding means that least (resp. most) significant bytes are stored first. Big-endian is also known as network byte order. Native-endian encoding is either little-endian or big-endian depending on Sys.big_endian
.
32-bit and 64-bit integers are represented by the int32
and int64
types, which can be interpreted either as signed or unsigned numbers.
8-bit and 16-bit integers are represented by the int
type, which has more bits than the binary encoding. These extra bits are sign-extended (or zero-extended) for functions which decode 8-bit or 16-bit integers and represented them with int
values.
get_uint8 b i
is b
's unsigned 8-bit integer starting at character index i
.
get_int8 b i
is b
's signed 8-bit integer starting at character index i
.
get_uint16_ne b i
is b
's native-endian unsigned 16-bit integer starting at character index i
.
get_uint16_be b i
is b
's big-endian unsigned 16-bit integer starting at character index i
.
get_uint16_le b i
is b
's little-endian unsigned 16-bit integer starting at character index i
.
get_int16_ne b i
is b
's native-endian signed 16-bit integer starting at character index i
.
get_int16_be b i
is b
's big-endian signed 16-bit integer starting at character index i
.
get_int16_le b i
is b
's little-endian signed 16-bit integer starting at character index i
.
get_int32_ne b i
is b
's native-endian 32-bit integer starting at character index i
.
get_int32_be b i
is b
's big-endian 32-bit integer starting at character index i
.
get_int32_le b i
is b
's little-endian 32-bit integer starting at character index i
.
get_int64_ne b i
is b
's native-endian 64-bit integer starting at character index i
.
get_int64_be b i
is b
's big-endian 64-bit integer starting at character index i
.
get_int64_le b i
is b
's little-endian 64-bit integer starting at character index i
.
Equality function on strings.
is_empty s
returns true
iff s
is empty (i.e. its length is 0).
Like Array.init
.
rev s
returns the reverse of s
.
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.
of_char 'a'
is "a"
.
Convert a list of characters to a string.
Convert an array of characters to a string.
Return the array of characters contained in the string.
Find sub
in string, returns its first index or -1
.
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.
mem ~sub s
is true
iff sub
is a substring of s
.
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 ~len
returns true
iff the substring of sub
starting at position i
and of length len
is a substring of s
starting at position j
.
The same string, repeated n times.
prefix ~pre s
returns true
iff pre
is a prefix of s
.
suffix ~suf s
returns true
iff suf
is a suffix of s
.
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.
take n s
keeps only the n
first chars of s
.
drop n s
removes the n
first chars of s
.
take_drop n s = take n s, drop n s
.
lines s
returns a list of the lines of s
(splits along '\n').
lines_gen s
returns a generator of the lines of s
(splits along '\n').
concat_gen ~sep g
concatenates all strings of g
, separated with sep
.
unlines l
concatenates all strings of l
, separated with '\n'.
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
.
Iter on chars with their index.
Map chars.
Map chars with their index.
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).
filter f s
discards characters not satisfying f
.
Map each chars to a string, then concatenates them all.
True for all chars?
True for some char?
include S with type t := string
Return the length (number of characters) of the given string.
Like String.blit
. Compatible with the -safe-string
option.
Fold on chars by increasing index.
Conversions
Return the list of characters contained in the string.
Print the string within quotes.
Renamed from print
since 2.0.
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
Map pairs of chars.
Iterate on pairs of chars.
Iterate on pairs of chars with their index.
Fold on pairs of chars.
All pairs of chars respect the predicate?
Exists a pair of chars?
Ascii functions
Those functions are deprecated in String
since 4.03, so we provide a stable alias for them even in older versions.
Comparison without respect to ascii lowercase.
Finding
A relatively efficient algorithm for finding sub-strings.
Splitting
Split the string along the given char.
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