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

NAME

6       BytesLabels - Byte sequence operations.
7

Module

9       Module   BytesLabels
10

Documentation

12       Module BytesLabels
13        : sig end
14
15
16       Byte sequence operations.
17
18
19       Since 4.02.0
20
21           This  module  is  intended  to  be  used through {!StdLabels} which
22       replaces
23           {!Array}, {!Bytes}, {!List} and {!String} with their labeled  coun‐
24       terparts.
25
26           For example:
27           {[
28              open StdLabels
29
30              let first = Bytes.sub ~pos:0 ~len:1
31           ]}
32
33
34
35
36
37
38       val length : bytes -> int
39
40       Return the length (number of bytes) of the argument.
41
42
43
44       val get : bytes -> int -> char
45
46
47       get s n returns the byte at index n in argument s .
48
49       Raise Invalid_argument if n is not a valid index in s .
50
51
52
53       val set : bytes -> int -> char -> unit
54
55
56       set s n c modifies s in place, replacing the byte at index n with c .
57
58       Raise Invalid_argument if n is not a valid index in s .
59
60
61
62       val create : int -> bytes
63
64
65       create  n  returns  a  new  byte sequence of length n . The sequence is
66       uninitialized and contains arbitrary bytes.
67
68       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
69
70
71
72       val make : int -> char -> bytes
73
74
75       make n c returns a new byte sequence of length n , filled with the byte
76       c .
77
78       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
79
80
81
82       val init : int -> f:(int -> char) -> bytes
83
84
85       init  n  f returns a fresh byte sequence of length n , with character i
86       initialized to the result of f i .
87
88       Raise Invalid_argument if n < 0 or n > Sys.max_string_length .
89
90
91
92       val empty : bytes
93
94       A byte sequence of size 0.
95
96
97
98       val copy : bytes -> bytes
99
100       Return a new byte sequence that contains the same bytes  as  the  argu‐
101       ment.
102
103
104
105       val of_string : string -> bytes
106
107       Return  a  new  byte sequence that contains the same bytes as the given
108       string.
109
110
111
112       val to_string : bytes -> string
113
114       Return a new string that contains the same  bytes  as  the  given  byte
115       sequence.
116
117
118
119       val sub : bytes -> pos:int -> len:int -> bytes
120
121
122       sub  s start len returns a new byte sequence of length len , containing
123       the subsequence of s that starts at position start and has length len .
124
125       Raise Invalid_argument if start and len do not designate a valid  range
126       of s .
127
128
129
130       val sub_string : bytes -> pos:int -> len:int -> string
131
132       Same as sub but return a string instead of a byte sequence.
133
134
135
136       val extend : bytes -> left:int -> right:int -> bytes
137
138
139       extend s left right returns a new byte sequence that contains the bytes
140       of s , with left uninitialized bytes prepended and right  uninitialized
141       bytes  appended  to  it.  If  left or right is negative, then bytes are
142       removed (instead of appended) from the corresponding side of s .
143
144       Raise Invalid_argument if the result length is negative or longer  than
145       Sys.max_string_length bytes.
146
147
148       Since 4.05.0
149
150
151
152       val fill : bytes -> pos:int -> len:int -> char -> unit
153
154
155       fill s start len c modifies s in place, replacing len characters with c
156       , starting at start .
157
158       Raise Invalid_argument if start and len do not designate a valid  range
159       of s .
160
161
162
163       val  blit  :  src:bytes  ->  src_pos:int -> dst:bytes -> dst_pos:int ->
164       len:int -> unit
165
166
167       blit src srcoff dst dstoff len copies len bytes  from  sequence  src  ,
168       starting at index srcoff , to sequence dst , starting at index dstoff .
169       It works correctly even if src and dst are the same byte sequence,  and
170       the source and destination intervals overlap.
171
172       Raise Invalid_argument if srcoff and len do not designate a valid range
173       of src , or if dstoff and len do not designate a valid range of dst .
174
175
176
177       val blit_string : src:string -> src_pos:int -> dst:bytes -> dst_pos:int
178       -> len:int -> unit
179
180
181       blit  src  srcoff  dst  dstoff  len  copies len bytes from string src ,
182       starting at index srcoff , to byte sequence dst  ,  starting  at  index
183       dstoff .
184
185       Raise Invalid_argument if srcoff and len do not designate a valid range
186       of src , or if dstoff and len do not designate a valid range of dst .
187
188
189       Since 4.05.0
190
191
192
193       val concat : sep:bytes -> bytes list -> bytes
194
195
196       concat sep sl concatenates the list of byte sequences  sl  ,  inserting
197       the separator byte sequence sep between each, and returns the result as
198       a new byte sequence.
199
200
201
202       val cat : bytes -> bytes -> bytes
203
204
205       cat s1 s2 concatenates s1 and s2 and returns the  result  as  new  byte
206       sequence.
207
208       Raise    Invalid_argument    if    the    result    is    longer   than
209       Sys.max_string_length bytes.
210
211
212       Since 4.05.0
213
214
215
216       val iter : f:(char -> unit) -> bytes -> unit
217
218
219       iter f s applies function f in turn to all the bytes  of  s  .   It  is
220       equivalent to f (get s 0); f (get s 1); ...; f (get s
221           (length s - 1)); () .
222
223
224
225       val iteri : f:(int -> char -> unit) -> bytes -> unit
226
227       Same  as  Bytes.iter  , but the function is applied to the index of the
228       byte as first argument and the byte itself as second argument.
229
230
231
232       val map : f:(char -> char) -> bytes -> bytes
233
234
235       map f s applies function f in turn to all the bytes of s and stores the
236       resulting bytes in a new sequence that is returned as the result.
237
238
239
240       val mapi : f:(int -> char -> char) -> bytes -> bytes
241
242
243       mapi  f s calls f with each character of s and its index (in increasing
244       index order) and stores the resulting bytes in a new sequence  that  is
245       returned as the result.
246
247
248
249       val trim : bytes -> bytes
250
251       Return a copy of the argument, without leading and trailing whitespace.
252       The bytes regarded as whitespace are the ASCII characters ' ' ,  '\012'
253       , '\n' , '\r' , and '\t' .
254
255
256
257       val escaped : bytes -> bytes
258
259       Return  a  copy of the argument, with special characters represented by
260       escape sequences, following the lexical conventions of OCaml.
261
262
263
264       val index : bytes -> char -> int
265
266
267       index s c returns the index of the first occurrence of byte c in s .
268
269       Raise Not_found if c does not occur in s .
270
271
272
273       val index_opt : bytes -> char -> int option
274
275
276       index_opt s c returns the index of the first occurrence of byte c in  s
277       or None if c does not occur in s .
278
279
280       Since 4.05
281
282
283
284       val rindex : bytes -> char -> int
285
286
287       rindex s c returns the index of the last occurrence of byte c in s .
288
289       Raise Not_found if c does not occur in s .
290
291
292
293       val rindex_opt : bytes -> char -> int option
294
295
296       rindex_opt  s c returns the index of the last occurrence of byte c in s
297       or None if c does not occur in s .
298
299
300       Since 4.05
301
302
303
304       val index_from : bytes -> int -> char -> int
305
306
307       index_from s i c returns the index of the first occurrence of byte c in
308       s after position i .  Bytes.index s c is equivalent to Bytes.index_from
309       s 0 c .
310
311       Raise Invalid_argument if i is not a  valid  position  in  s  .   Raise
312       Not_found if c does not occur in s after position i .
313
314
315
316       val index_from_opt : bytes -> int -> char -> int option
317
318
319       index_from  _opts i c returns the index of the first occurrence of byte
320       c in s after position i or None if c does not occur in s after position
321       i .  Bytes.index_opt s c is equivalent to Bytes.index_from_opt s 0 c .
322
323       Raise Invalid_argument if i is not a valid position in s .
324
325
326       Since 4.05
327
328
329
330       val rindex_from : bytes -> int -> char -> int
331
332
333       rindex_from s i c returns the index of the last occurrence of byte c in
334       s before position i+1 .  rindex s c  is  equivalent  to  rindex_from  s
335       (Bytes.length s - 1) c .
336
337       Raise  Invalid_argument  if  i+1  is not a valid position in s .  Raise
338       Not_found if c does not occur in s before position i+1 .
339
340
341
342       val rindex_from_opt : bytes -> int -> char -> int option
343
344
345       rindex_from_opt s i c returns the index of the last occurrence of  byte
346       c  in  s  before  position  i+1 or None if c does not occur in s before
347       position  i+1  .   rindex_opt  s  c  is  equivalent  to  rindex_from  s
348       (Bytes.length s - 1) c .
349
350       Raise Invalid_argument if i+1 is not a valid position in s .
351
352
353       Since 4.05
354
355
356
357       val contains : bytes -> char -> bool
358
359
360       contains s c tests if byte c appears in s .
361
362
363
364       val contains_from : bytes -> int -> char -> bool
365
366
367       contains_from  s  start  c  tests if byte c appears in s after position
368       start .  contains s c is equivalent to contains_from
369           s 0 c .
370
371       Raise Invalid_argument if start is not a valid position in s .
372
373
374
375       val rcontains_from : bytes -> int -> char -> bool
376
377
378       rcontains_from s stop c tests if byte c appears in  s  before  position
379       stop+1 .
380
381       Raise Invalid_argument if stop < 0 or stop+1 is not a valid position in
382       s .
383
384
385
386       val uppercase : bytes -> bytes
387
388       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
389       cated.
390
391
392       Return a copy of the argument, with all lowercase letters translated to
393       uppercase, including accented letters of the ISO Latin-1 (8859-1) char‐
394       acter set.
395
396
397
398       val lowercase : bytes -> bytes
399
400       Deprecated.   Functions  operating  on Latin-1 character set are depre‐
401       cated.
402
403
404       Return a copy of the argument, with all uppercase letters translated to
405       lowercase, including accented letters of the ISO Latin-1 (8859-1) char‐
406       acter set.
407
408
409
410       val capitalize : bytes -> bytes
411
412       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
413       cated.
414
415
416       Return  a  copy of the argument, with the first character set to upper‐
417       case, using the ISO Latin-1 (8859-1) character set..
418
419
420
421       val uncapitalize : bytes -> bytes
422
423       Deprecated.  Functions operating on Latin-1 character  set  are  depre‐
424       cated.
425
426
427       Return  a  copy of the argument, with the first character set to lower‐
428       case, using the ISO Latin-1 (8859-1) character set..
429
430
431
432       val uppercase_ascii : bytes -> bytes
433
434       Return a copy of the argument, with all lowercase letters translated to
435       uppercase, using the US-ASCII character set.
436
437
438       Since 4.05.0
439
440
441
442       val lowercase_ascii : bytes -> bytes
443
444       Return a copy of the argument, with all uppercase letters translated to
445       lowercase, using the US-ASCII character set.
446
447
448       Since 4.05.0
449
450
451
452       val capitalize_ascii : bytes -> bytes
453
454       Return a copy of the argument, with the first character set  to  upper‐
455       case, using the US-ASCII character set.
456
457
458       Since 4.05.0
459
460
461
462       val uncapitalize_ascii : bytes -> bytes
463
464       Return  a  copy of the argument, with the first character set to lower‐
465       case, using the US-ASCII character set.
466
467
468       Since 4.05.0
469
470
471       type t = bytes
472
473
474       An alias for the type of byte sequences.
475
476
477
478       val compare : t -> t -> int
479
480       The comparison function for byte sequences, with the same specification
481       as  compare .  Along with the type t , this function compare allows the
482       module Bytes to be passed as argument  to  the  functors  Set.Make  and
483       Map.Make .
484
485
486
487       val equal : t -> t -> bool
488
489       The equality function for byte sequences.
490
491
492       Since 4.05.0
493
494
495
496
497   Iterators
498       val to_seq : t -> char Seq.t
499
500       Iterate  on the string, in increasing index order. Modifications of the
501       string during iteration will be reflected in the iterator.
502
503
504       Since 4.07
505
506
507
508       val to_seqi : t -> (int * char) Seq.t
509
510       Iterate on the string, in  increasing  order,  yielding  indices  along
511       chars
512
513
514       Since 4.07
515
516
517
518       val of_seq : char Seq.t -> t
519
520       Create a string from the generator
521
522
523       Since 4.07
524
525
526
527
528   Binary encoding/decoding of integers
529       The  functions in this section binary encode and decode integers to and
530       from byte sequences.
531
532       All following functions raise Invalid_argument if the space  needed  at
533       index i to decode or encode the integer is not available.
534
535       Little-endian (resp. big-endian) encoding means that least (resp. most)
536       significant bytes are stored first.  Big-endian is also known  as  net‐
537       work  byte  order.   Native-endian  encoding is either little-endian or
538       big-endian depending on Sys.big_endian .
539
540       32-bit and 64-bit integers are  represented  by  the  int32  and  int64
541       types, which can be interpreted either as signed or unsigned numbers.
542
543       8-bit  and  16-bit  integers are represented by the int type, which has
544       more bits than the binary encoding.  These extra bits  are  handled  as
545       follows:
546
547       -Functions that decode signed (resp. unsigned) 8-bit or 16-bit integers
548       represented by int values sign-extend (resp. zero-extend) their result.
549
550       -Functions that encode 8-bit or 16-bit integers represented by int val‐
551       ues truncate their input to their least significant bytes.
552
553
554       val get_uint8 : bytes -> int -> int
555
556
557       get_uint8 b i is b 's unsigned 8-bit integer starting at byte index i .
558
559
560       Since 4.08
561
562
563
564       val get_int8 : bytes -> int -> int
565
566
567       get_int8 b i is b 's signed 8-bit integer starting at byte index i .
568
569
570       Since 4.08
571
572
573
574       val get_uint16_ne : bytes -> int -> int
575
576
577       get_uint16_ne  b i is b 's native-endian unsigned 16-bit integer start‐
578       ing at byte index i .
579
580
581       Since 4.08
582
583
584
585       val get_uint16_be : bytes -> int -> int
586
587
588       get_uint16_be b i is b 's big-endian unsigned 16-bit  integer  starting
589       at byte index i .
590
591
592       Since 4.08
593
594
595
596       val get_uint16_le : bytes -> int -> int
597
598
599       get_uint16_le  b i is b 's little-endian unsigned 16-bit integer start‐
600       ing at byte index i .
601
602
603       Since 4.08
604
605
606
607       val get_int16_ne : bytes -> int -> int
608
609
610       get_int16_ne b i is b 's native-endian signed 16-bit  integer  starting
611       at byte index i .
612
613
614       Since 4.08
615
616
617
618       val get_int16_be : bytes -> int -> int
619
620
621       get_int16_be  b  i is b 's big-endian signed 16-bit integer starting at
622       byte index i .
623
624
625       Since 4.08
626
627
628
629       val get_int16_le : bytes -> int -> int
630
631
632       get_int16_le b i is b 's little-endian signed 16-bit  integer  starting
633       at byte index i .
634
635
636       Since 4.08
637
638
639
640       val get_int32_ne : bytes -> int -> int32
641
642
643       get_int32_ne  b i is b 's native-endian 32-bit integer starting at byte
644       index i .
645
646
647       Since 4.08
648
649
650
651       val get_int32_be : bytes -> int -> int32
652
653
654       get_int32_be b i is b 's big-endian 32-bit  integer  starting  at  byte
655       index i .
656
657
658       Since 4.08
659
660
661
662       val get_int32_le : bytes -> int -> int32
663
664
665       get_int32_le  b i is b 's little-endian 32-bit integer starting at byte
666       index i .
667
668
669       Since 4.08
670
671
672
673       val get_int64_ne : bytes -> int -> int64
674
675
676       get_int64_ne b i is b 's native-endian 64-bit integer starting at  byte
677       index i .
678
679
680       Since 4.08
681
682
683
684       val get_int64_be : bytes -> int -> int64
685
686
687       get_int64_be  b  i  is  b 's big-endian 64-bit integer starting at byte
688       index i .
689
690
691       Since 4.08
692
693
694
695       val get_int64_le : bytes -> int -> int64
696
697
698       get_int64_le b i is b 's little-endian 64-bit integer starting at  byte
699       index i .
700
701
702       Since 4.08
703
704
705
706       val set_uint8 : bytes -> int -> int -> unit
707
708
709       set_uint8 b i v sets b 's unsigned 8-bit integer starting at byte index
710       i to v .
711
712
713       Since 4.08
714
715
716
717       val set_int8 : bytes -> int -> int -> unit
718
719
720       set_int8 b i v sets b 's signed 8-bit integer starting at byte index  i
721       to v .
722
723
724       Since 4.08
725
726
727
728       val set_uint16_ne : bytes -> int -> int -> unit
729
730
731       set_uint16_ne  b  i  v  sets b 's native-endian unsigned 16-bit integer
732       starting at byte index i to v .
733
734
735       Since 4.08
736
737
738
739       val set_uint16_be : bytes -> int -> int -> unit
740
741
742       set_uint16_be b i v sets b 's big-endian unsigned 16-bit integer start‐
743       ing at byte index i to v .
744
745
746       Since 4.08
747
748
749
750       val set_uint16_le : bytes -> int -> int -> unit
751
752
753       set_uint16_le  b  i  v  sets b 's little-endian unsigned 16-bit integer
754       starting at byte index i to v .
755
756
757       Since 4.08
758
759
760
761       val set_int16_ne : bytes -> int -> int -> unit
762
763
764       set_int16_ne b i v sets b 's native-endian signed 16-bit integer start‐
765       ing at byte index i to v .
766
767
768       Since 4.08
769
770
771
772       val set_int16_be : bytes -> int -> int -> unit
773
774
775       set_int16_be  b i v sets b 's big-endian signed 16-bit integer starting
776       at byte index i to v .
777
778
779       Since 4.08
780
781
782
783       val set_int16_le : bytes -> int -> int -> unit
784
785
786       set_int16_le b i v sets b 's little-endian signed 16-bit integer start‐
787       ing at byte index i to v .
788
789
790       Since 4.08
791
792
793
794       val set_int32_ne : bytes -> int -> int32 -> unit
795
796
797       set_int32_ne  b  i v sets b 's native-endian 32-bit integer starting at
798       byte index i to v .
799
800
801       Since 4.08
802
803
804
805       val set_int32_be : bytes -> int -> int32 -> unit
806
807
808       set_int32_be b i v sets b 's big-endian 32-bit integer starting at byte
809       index i to v .
810
811
812       Since 4.08
813
814
815
816       val set_int32_le : bytes -> int -> int32 -> unit
817
818
819       set_int32_le  b  i v sets b 's little-endian 32-bit integer starting at
820       byte index i to v .
821
822
823       Since 4.08
824
825
826
827       val set_int64_ne : bytes -> int -> int64 -> unit
828
829
830       set_int64_ne b i v sets b 's native-endian 64-bit integer  starting  at
831       byte index i to v .
832
833
834       Since 4.08
835
836
837
838       val set_int64_be : bytes -> int -> int64 -> unit
839
840
841       set_int64_be b i v sets b 's big-endian 64-bit integer starting at byte
842       index i to v .
843
844
845       Since 4.08
846
847
848
849       val set_int64_le : bytes -> int -> int64 -> unit
850
851
852       set_int64_le b i v sets b 's little-endian 64-bit integer  starting  at
853       byte index i to v .
854
855
856       Since 4.08
857
858
859
860
861
862OCamldoc                          2020-02-27                    BytesLabels(3)
Impressum