1StringLabels(3)                  OCaml library                 StringLabels(3)
2
3
4

NAME

6       StringLabels - String operations.
7

Module

9       Module   StringLabels
10

Documentation

12       Module StringLabels
13        : sig end
14
15
16       String  operations.   This module is intended to be used through StdLa‐
17       bels which replaces Array , Bytes , List and String with their  labeled
18       counterparts
19
20       For example:
21             open StdLabels
22
23             let to_upper = String.map ~f:Char.uppercase_ascii
24
25
26
27
28
29
30
31       val length : string -> int
32
33       Return the length (number of characters) of the given string.
34
35
36
37       val get : string -> int -> char
38
39
40       String.get  s n returns the character at index n in string s .  You can
41       also write s.[n] instead of String.get s n .
42
43       Raise Invalid_argument if n not a valid index in s .
44
45
46
47       val set : bytes -> int -> char -> unit
48
49       Deprecated.  This is a deprecated alias of BytesLabels.set .
50
51
52
53       String.set s n c modifies byte sequence s in place, replacing the  byte
54       at  index  n  with  c  .   You  can  also  write  s.[n] <- c instead of
55       String.set s n c .
56
57       Raise Invalid_argument if n is not a valid index in s .
58
59
60
61       val create : int -> bytes
62
63       Deprecated.  This is a deprecated alias of BytesLabels.create .
64
65
66
67       String.create n returns a fresh  byte  sequence  of  length  n  .   The
68       sequence is uninitialized and contains arbitrary bytes.
69
70       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
71
72
73
74       val make : int -> char -> string
75
76
77       String.make  n  c  returns a fresh string of length n , filled with the
78       character c .
79
80       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
81
82
83
84       val init : int -> f:(int -> char) -> string
85
86
87       init n f returns a string of length n , with character i initialized to
88       the result of f i .
89
90       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
91
92
93       Since 4.02.0
94
95
96
97       val copy : string -> string
98
99       Return a copy of the given string.
100
101
102
103       val sub : string -> pos:int -> len:int -> string
104
105
106       String.sub  s start len returns a fresh string of length len , contain‐
107       ing the substring of s that starts at position start and has length len
108       .
109
110       Raise  Invalid_argument  if start and len do not designate a valid sub‐
111       string of s .
112
113
114
115       val fill : bytes -> pos:int -> len:int -> char -> unit
116
117       Deprecated.  This is a deprecated alias of BytesLabels.fill .
118
119
120
121       String.fill s start len c modifies byte sequence s in place,  replacing
122       len bytes by c , starting at start .
123
124       Raise  Invalid_argument  if start and len do not designate a valid sub‐
125       string of s .
126
127
128
129       val blit : src:string -> src_pos:int ->  dst:bytes  ->  dst_pos:int  ->
130       len:int -> unit
131
132
133       String.blit  src srcoff dst dstoff len copies len bytes from the string
134       src , starting at index srcoff , to byte sequence  dst  ,  starting  at
135       character number dstoff .
136
137       Raise Invalid_argument if srcoff and len do not designate a valid range
138       of src , or if dstoff and len do not designate a valid range of dst .
139
140
141
142       val concat : sep:string -> string list -> string
143
144
145       String.concat sep sl concatenates the list of strings  sl  ,  inserting
146       the separator string sep between each.
147
148
149
150       val iter : f:(char -> unit) -> string -> unit
151
152
153       String.iter f s applies function f in turn to all the characters of s .
154       It is equivalent to f s.[0]; f s.[1]; ...; f s.[String.length s  -  1];
155       () .
156
157
158
159       val iteri : f:(int -> char -> unit) -> string -> unit
160
161       Same  as  String.iter , but the function is applied to the index of the
162       element as first argument (counting from 0), and the  character  itself
163       as second argument.
164
165
166       Since 4.00.0
167
168
169
170       val map : f:(char -> char) -> string -> string
171
172
173       String.map  f  s  applies function f in turn to all the characters of s
174       and stores the results in a new string that is returned.
175
176
177       Since 4.00.0
178
179
180
181       val mapi : f:(int -> char -> char) -> string -> string
182
183
184       String.mapi f s calls f with each character of  s  and  its  index  (in
185       increasing  index order) and stores the results in a new string that is
186       returned.
187
188
189       Since 4.02.0
190
191
192
193       val trim : string -> string
194
195       Return a copy of the argument, without leading and trailing whitespace.
196       The characters regarded as whitespace are: ' ' , '\012' , '\n' , '\r' ,
197       and '\t' .  If there is no leading nor trailing whitespace character in
198       the argument, return the original string itself, not a copy.
199
200
201       Since 4.00.0
202
203
204
205       val escaped : string -> string
206
207       Return  a  copy of the argument, with special characters represented by
208       escape sequences, following the lexical conventions of OCaml.  If there
209       is  no  special  character  in the argument, return the original string
210       itself, not a copy. Its inverse function is Scanf.unescaped.
211
212
213
214       val index : string -> char -> int
215
216
217       String.index s c returns the index of the first occurrence of character
218       c in string s .
219
220       Raise Not_found if c does not occur in s .
221
222
223
224       val index_opt : string -> char -> int option
225
226
227       String.index_opt s c returns the index of the first occurrence of char‐
228       acter c in string s , or None if c does not occur in s .
229
230
231       Since 4.05
232
233
234
235       val rindex : string -> char -> int
236
237
238       String.rindex s c returns the index of the last occurrence of character
239       c in string s .
240
241       Raise Not_found if c does not occur in s .
242
243
244
245       val rindex_opt : string -> char -> int option
246
247
248       String.rindex_opt s c returns the index of the last occurrence of char‐
249       acter c in string s , or None if c does not occur in s .
250
251
252       Since 4.05
253
254
255
256       val index_from : string -> int -> char -> int
257
258
259       String.index_from s i c returns the index of the  first  occurrence  of
260       character c in string s after position i .  String.index s c is equiva‐
261       lent to String.index_from s 0 c .
262
263       Raise Invalid_argument if i is not a  valid  position  in  s  .   Raise
264       Not_found if c does not occur in s after position i .
265
266
267
268       val index_from_opt : string -> int -> char -> int option
269
270
271       String.index_from_opt  s  i c returns the index of the first occurrence
272       of character c in string s after position i or None if c does not occur
273       in s after position i .
274
275
276       String.index_opt  s  c  is  equivalent to String.index_from_opt s 0 c .
277       Raise Invalid_argument if i is not a valid position in s .
278
279
280       Since 4.05
281
282
283
284       val rindex_from : string -> int -> char -> int
285
286
287       String.rindex_from s i c returns the index of the  last  occurrence  of
288       character  c  in  string  s before position i+1 .  String.rindex s c is
289       equivalent to String.rindex_from s (String.length s - 1) c .
290
291       Raise Invalid_argument if i+1 is not a valid position  in  s  .   Raise
292       Not_found if c does not occur in s before position i+1 .
293
294
295
296       val rindex_from_opt : string -> int -> char -> int option
297
298
299       String.rindex_from_opt  s  i c returns the index of the last occurrence
300       of character c in string s before position i+1 or None if  c  does  not
301       occur in s before position i+1 .
302
303
304       String.rindex_opt   s  c  is  equivalent  to  String.rindex_from_opt  s
305       (String.length s - 1) c .
306
307       Raise Invalid_argument if i+1 is not a valid position in s .
308
309
310       Since 4.05
311
312
313
314       val contains : string -> char -> bool
315
316
317       String.contains s c tests if character c appears in the string s .
318
319
320
321       val contains_from : string -> int -> char -> bool
322
323
324       String.contains_from s start c tests if character c appears in s  after
325       position  start  .   String.contains  s  c is equivalent to String.con‐
326       tains_from s 0 c .
327
328       Raise Invalid_argument if start is not a valid position in s .
329
330
331
332       val rcontains_from : string -> int -> char -> bool
333
334
335       String.rcontains_from s stop c tests if character c appears in s before
336       position stop+1 .
337
338       Raise Invalid_argument if stop < 0 or stop+1 is not a valid position in
339       s .
340
341
342
343       val uppercase : string -> string
344
345       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
346       cated.
347
348
349       Return a copy of the argument, with all lowercase letters translated to
350       uppercase, including accented letters of the ISO Latin-1 (8859-1) char‐
351       acter set.
352
353
354
355       val lowercase : string -> string
356
357       Deprecated.   Functions  operating  on Latin-1 character set are depre‐
358       cated.
359
360
361       Return a copy of the argument, with all uppercase letters translated to
362       lowercase, including accented letters of the ISO Latin-1 (8859-1) char‐
363       acter set.
364
365
366
367       val capitalize : string -> string
368
369       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
370       cated.
371
372
373       Return  a  copy of the argument, with the first character set to upper‐
374       case, using the ISO Latin-1 (8859-1) character set..
375
376
377
378       val uncapitalize : string -> string
379
380       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
381       cated.
382
383
384       Return  a  copy of the argument, with the first character set to lower‐
385       case, using the ISO Latin-1 (8859-1) character set..
386
387
388
389       val uppercase_ascii : string -> string
390
391       Return a copy of the argument, with all lowercase letters translated to
392       uppercase, using the US-ASCII character set.
393
394
395       Since 4.05.0
396
397
398
399       val lowercase_ascii : string -> string
400
401       Return a copy of the argument, with all uppercase letters translated to
402       lowercase, using the US-ASCII character set.
403
404
405       Since 4.05.0
406
407
408
409       val capitalize_ascii : string -> string
410
411       Return a copy of the argument, with the first character set  to  upper‐
412       case, using the US-ASCII character set.
413
414
415       Since 4.05.0
416
417
418
419       val uncapitalize_ascii : string -> string
420
421       Return  a  copy of the argument, with the first character set to lower‐
422       case, using the US-ASCII character set.
423
424
425       Since 4.05.0
426
427
428       type t = string
429
430
431       An alias for the type of strings.
432
433
434
435       val compare : t -> t -> int
436
437       The comparison function for strings, with  the  same  specification  as
438       compare  .   Along  with  the type t , this function compare allows the
439       module String to be passed as argument to  the  functors  Set.Make  and
440       Map.Make .
441
442
443
444       val equal : t -> t -> bool
445
446       The equal function for strings.
447
448
449       Since 4.05.0
450
451
452
453       val split_on_char : sep:char -> string -> string list
454
455
456       String.split_on_char  sep  s  returns  the list of all (possibly empty)
457       substrings of s that are delimited by the sep character.
458
459       The function's output is specified by the following invariants:
460
461
462       -The list is not empty.
463
464       -Concatenating its elements using sep as a separator returns  a  string
465       equal to the input ( String.concat (String.make 1 sep)
466             (String.split_on_char sep s) = s ).
467
468       -No string in the result contains the sep character.
469
470
471
472       Since 4.05.0
473
474
475
476
477   Iterators
478       val to_seq : t -> char Seq.t
479
480       Iterate  on the string, in increasing index order. Modifications of the
481       string during iteration will be reflected in the iterator.
482
483
484       Since 4.07
485
486
487
488       val to_seqi : t -> (int * char) Seq.t
489
490       Iterate on the string, in  increasing  order,  yielding  indices  along
491       chars
492
493
494       Since 4.07
495
496
497
498       val of_seq : char Seq.t -> t
499
500       Create a string from the generator
501
502
503       Since 4.07
504
505
506
507
508
509OCamldoc                          2020-02-27                   StringLabels(3)
Impressum