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

NAME

6       Stdlib.BytesLabels - no description
7

Module

9       Module   Stdlib.BytesLabels
10

Documentation

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