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