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