~ubuntu-branches/ubuntu/trusty/ocamlnet/trusty

« back to all changes in this revision

Viewing changes to src/netstring/netstring_pcre.mli

  • Committer: Bazaar Package Importer
  • Author(s): Stéphane Glondu
  • Date: 2011-09-02 14:12:33 UTC
  • mfrom: (18.2.3 sid)
  • Revision ID: james.westby@ubuntu.com-20110902141233-zbj0ygxb92u6gy4z
Tags: 3.4-1
* New upstream release
  - add a new NetcgiRequire directive to ease dependency management
    (Closes: #637147)
  - remove patches that were applied upstream:
    + Added-missing-shebang-lines-in-example-shell-scripts
    + Try-also-ocamlc-for-POSIX-threads

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
(* $Id: netstring_pcre.mli 800 2004-07-09 00:17:47Z stolpmann $ *)
2
 
 
3
 
(** Wrapper for regexps with PCRE syntax
4
 
 *
5
 
 * This module is a version of [Str] with a thread-safe interface,
6
 
 * implemented using Pcre. 
7
 
 *
8
 
 * This modules processes PCRE-style regular expressions. If you like
9
 
 * to write [Str]-like regexps, you can also use {!Netstring_str} with
10
 
 * almost the same signature.
11
 
 *)
12
 
 
13
 
(** Supported regexp syntax: See pcrepattern(3). *)
14
 
 
15
 
type regexp = Pcre.regexp;;
16
 
  (** The type of regular expressions; now based on [Pcre] *)
17
 
 
18
 
type split_result = Pcre.split_result = 
19
 
  | Text of string
20
 
  | Delim of string
21
 
  | Group of int * string
22
 
  | NoGroup
23
 
  (** Here we keep compatiblity with [Pcre] *)
24
 
;;
25
 
 
26
 
type result;;
27
 
  (** The type of matching results *)
28
 
 
29
 
val regexp: string -> regexp
30
 
  (** Parses a regexp *)
31
 
val regexp_case_fold: string -> regexp
32
 
  (** Parses a case-insensitive regexp *)
33
 
val quote: string -> string
34
 
  (** Quotes a string such that it can be included in a regexp *)
35
 
val regexp_string: string -> regexp
36
 
  (** Returns a regexp that matches exactly the string *)
37
 
val regexp_string_case_fold: string -> regexp
38
 
  (** Returns a case-insensitive regexp that matches exactly the string *)
39
 
 
40
 
(** Note: the [groups] argument is ignored in the following functions.
41
 
 * Once upon a time this argument determined how many groups were 
42
 
 * copied to the [result] value.
43
 
 * Now all groups are accessible in the [result] value, no matter
44
 
 * what [groups] says.
45
 
 *)
46
 
 
47
 
val string_match: 
48
 
      ?groups:int -> regexp -> string -> int -> result option
49
 
  (** Matches the string at the position with the regexp. Returns
50
 
   * [None] if no match is found. Returns [Some r] on success,
51
 
   * and [r] describes the match.
52
 
   *)
53
 
 
54
 
val search_forward: 
55
 
      ?groups:int -> regexp -> string -> int -> (int * result)
56
 
  (** Searches a match of the string with the regexp, starting at
57
 
   * the position and in forward direction.
58
 
   * Raises [Not_found] if no match could be found.
59
 
   * Returns [(p,r)] when a match at position [p] is found,
60
 
   * described by [r].
61
 
   *)
62
 
 
63
 
val search_backward:
64
 
      ?groups:int -> regexp -> string -> int -> (int * result)
65
 
  (** Searches a match of the string with the regexp, starting at
66
 
   * the position and in backward direction.
67
 
   * Raises [Not_found] if no match could be found.
68
 
   * Returns [(p,r)] when a match at position [p] is found,
69
 
   * described by [r].
70
 
   *)
71
 
 
72
 
(*
73
 
  string_partial_match: not available
74
 
*)
75
 
 
76
 
(* The ~groups option is ignored *)
77
 
 
78
 
val matched_string : result -> string -> string
79
 
  (** Extracts the matched part from the string. The string argument
80
 
   * must be the same string passed to [string_match] or the search
81
 
   * functions, and the result argument must be the corresponding
82
 
   * result.
83
 
   *)
84
 
 
85
 
val match_beginning : result -> int
86
 
  (** Returns the position where the matched part begins *)
87
 
 
88
 
val match_end : result -> int
89
 
  (** Returns the position where the matched part ends *)
90
 
 
91
 
val matched_group : result -> int -> string -> string
92
 
  (** Extracts the substring the nth group matches from the whole
93
 
   * string. The string argument
94
 
   * must be the same string passed to [string_match] or the search
95
 
   * functions, and the result argument must be the corresponding
96
 
   * result.
97
 
   *)
98
 
 
99
 
val group_beginning : result -> int -> int
100
 
  (** Returns the position where the substring matching the nth
101
 
   * group begins 
102
 
   *)
103
 
 
104
 
val group_end : result -> int -> int
105
 
  (** Returns the position where the substring matching the nth
106
 
   * group ends 
107
 
   *)
108
 
 
109
 
 
110
 
val global_replace: regexp -> string -> string -> string
111
 
  (** [global_replace re templ s]: Replaces all matchings of [re] in
112
 
   * [s] by [templ].
113
 
   *
114
 
   * In [templ] one can refer to matched groups by the backslash notation:
115
 
   * [\1] refers to the first group, [\2] to the second etc.
116
 
   * [\0] is the whole match. [\\ ] is the backslash character.
117
 
   *)
118
 
 
119
 
val replace_first: regexp -> string -> string -> string
120
 
  (** [replace_first re templ s]: Replaces the first match of [re] in
121
 
   * [s] by [templ].
122
 
   *
123
 
   * In [templ] one can refer to matched groups by the backslash notation:
124
 
   * [\1] refers to the first group, [\2] to the second etc.
125
 
   * [\0] is the whole match. [\\ ] is the backslash character.
126
 
   *)
127
 
 
128
 
val global_substitute:
129
 
       ?groups:int -> 
130
 
       regexp -> (result -> string -> string) -> string -> string
131
 
  (** [global_substitute re subst s]: Applies the substitution function
132
 
   * [subst] to all matchings of [re] in [s], and returns the 
133
 
   * transformed string. [subst] is called with the current [result]
134
 
   * of the match and the whole string [s].
135
 
   *)
136
 
 
137
 
val substitute_first:
138
 
       ?groups:int ->
139
 
       regexp -> (result -> string -> string) -> string -> string
140
 
  (** [substitute_first re subst s]: Applies the substitution function
141
 
   * [subst] to the first matching of [re] in [s], and returns the 
142
 
   * transformed string. [subst] is called with the current [result]
143
 
   * of the match and the whole string [s].
144
 
   *)
145
 
 
146
 
 
147
 
(* replace_matched: not available *)
148
 
 
149
 
val split: regexp -> string -> string list
150
 
  (** Splits the string according to the regexp in substrings.
151
 
   * Occurrences of the delimiter at the beginning and the end
152
 
   * are ignored.
153
 
   *)
154
 
 
155
 
val bounded_split: regexp -> string -> int -> string list
156
 
  (** Splits into at most [n] substrings, based on [split] *)
157
 
val split_delim: regexp -> string -> string list
158
 
  (** Same as [split], but occurrences of the delimiter at the beginning 
159
 
   * and the end are returned as empty strings
160
 
   *)
161
 
val bounded_split_delim: regexp -> string -> int -> string list
162
 
  (** Splits into at most [n] substrings, based on [split_delim] *)
163
 
val full_split: regexp -> string -> split_result list
164
 
  (** Like [split_delim], but returns the delimiters in the result *)
165
 
val bounded_full_split: regexp -> string -> int -> split_result list
166
 
  (** Splits into at most [n] substrings, based on [full_split] *)
167
 
 
168
 
val string_before: string -> int -> string
169
 
  (** The first [n] characters of a string *)
170
 
val string_after: string -> int -> string
171
 
  (** The last [n] characters of a string *)
172
 
val first_chars: string -> int -> string
173
 
  (** Same as [string_before] *)
174
 
val last_chars: string -> int -> string
175
 
  (** Same as [string_after] *)
176