File: string_utils.mli

package info (click to toggle)
ocaml-obuild 0.2.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,456 kB
  • sloc: ml: 14,491; sh: 211; ansic: 34; makefile: 11
file content (53 lines) | stat: -rw-r--r-- 2,060 bytes parent folder | download
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
(** {1 String operations} *)

val split : ?limit:int -> char -> string -> string list
(** [split ?limit c s] splits string [s] on character [c]. [limit] controls maximum number of splits
    (-1 for unlimited) *)

val split_pred : ?limit:int -> (char -> bool) -> string -> string list
(** [split_pred ?limit p s] splits string [s] at characters satisfying predicate [p]. [limit]
    controls maximum number of splits (-1 for unlimited) *)

val startswith : string -> string -> bool
(** [startswith prefix s] tests if [s] starts with [prefix] *)

val endswith : string -> string -> bool
(** [endswith suffix s] tests if [s] ends with [suffix] *)

val strip_spaces : string -> string
(** Remove leading and trailing whitespace (space, tab, newline) *)

val split_at : int -> string -> string * string
(** [split_at pos s] splits [s] at position [pos] into [(left, right)].
    @raise Invalid_argument if [pos] > length of [s] *)

val drop : int -> string -> string
(** [drop n s] returns [s] with first [n] characters removed.
    @raise Invalid_argument if [n] > length of [s] *)

val init : int -> string -> string
(** [init n s] returns [s] with last [n] characters removed.
    @raise Invalid_argument if [n] > length of [s] *)

val all : (char -> bool) -> string -> bool
(** [all p s] tests if all characters in [s] satisfy predicate [p] *)

val escape_ocaml_string : string -> string
(** Escape a string for embedding in an OCaml string literal.
    Escapes backslash, double-quote, newline, carriage return and tab. *)

val escape_c_string : string -> string
(** Escape a string for embedding in a C string literal.
    Escapes backslash, double-quote, newline, carriage return, tab and percent. *)

val lines : string -> string list
(** Split string on newline characters *)

val words : string -> string list
(** Split string on whitespace (space, newline, tab) *)

val words_noempty : string -> string list
(** Like {!words} but filters out empty strings *)

val lines_noempty : string -> string list
(** Like {!lines} but filters out empty strings *)