-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Synchronise functions in Bytes and String #9448
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
50392b1
Add String.empty as dual of Bytes.empty
dra27 d63347d
Add String.{of,to}_bytes
dra27 28dc873
Add String.cat as dual of Bytes.cat
dra27 011be23
Add Bytes.split_on_char
dra27 8574ad4
Add binary integer decoding functions to String
dra27 34606a5
Add Bytes.{starts,ends}_with
dra27 File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -41,8 +41,11 @@ let make n c = | |
B.make n c |> bts | ||
let init n f = | ||
B.init n f |> bts | ||
let empty = "" | ||
let copy s = | ||
B.copy (bos s) |> bts | ||
let of_bytes = B.to_string | ||
let to_bytes = B.of_string | ||
let sub s ofs len = | ||
B.sub (bos s) ofs len |> bts | ||
let fill = | ||
|
@@ -73,6 +76,8 @@ let concat sep = function | |
(B.create (sum_lengths 0 seplen l)) | ||
0 sep seplen l | ||
|
||
let cat = ( ^ ) | ||
|
||
(* duplicated in bytes.ml *) | ||
let iter f s = | ||
for i = 0 to length s - 1 do f (unsafe_get s i) done | ||
|
@@ -197,6 +202,7 @@ let capitalize_ascii s = | |
let uncapitalize_ascii s = | ||
B.uncapitalize_ascii (bos s) |> bts | ||
|
||
(* duplicated in bytes.ml *) | ||
let starts_with ~prefix s = | ||
let len_s = length s | ||
and len_pre = length prefix in | ||
|
@@ -206,6 +212,7 @@ let starts_with ~prefix s = | |
else aux (i + 1) | ||
in len_s >= len_pre && aux 0 | ||
|
||
(* duplicated in bytes.ml *) | ||
let ends_with ~suffix s = | ||
let len_s = length s | ||
and len_suf = length suffix in | ||
|
@@ -216,6 +223,7 @@ let ends_with ~suffix s = | |
else aux (i + 1) | ||
in diff >= 0 && aux 0 | ||
|
||
(* duplicated in bytes.ml *) | ||
let split_on_char sep s = | ||
let r = ref [] in | ||
let j = ref (length s) in | ||
|
@@ -250,3 +258,21 @@ let to_seq s = bos s |> B.to_seq | |
let to_seqi s = bos s |> B.to_seqi | ||
|
||
let of_seq g = B.of_seq g |> bts | ||
|
||
(** {6 Binary encoding/decoding of integers} *) | ||
|
||
external get_uint8 : string -> int -> int = "%string_safe_get" | ||
external get_uint16_ne : string -> int -> int = "%caml_string_get16" | ||
external get_int32_ne : string -> int -> int32 = "%caml_string_get32" | ||
external get_int64_ne : string -> int -> int64 = "%caml_string_get64" | ||
Comment on lines
+264
to
+267
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The runtime already has the correctly-named primitives for the |
||
|
||
let get_int8 s i = B.get_int8 (bos s) i | ||
let get_uint16_le s i = B.get_uint16_le (bos s) i | ||
let get_uint16_be s i = B.get_uint16_be (bos s) i | ||
let get_int16_ne s i = B.get_int16_ne (bos s) i | ||
let get_int16_le s i = B.get_int16_le (bos s) i | ||
let get_int16_be s i = B.get_int16_be (bos s) i | ||
let get_int32_le s i = B.get_int32_le (bos s) i | ||
let get_int32_be s i = B.get_int32_be (bos s) i | ||
let get_int64_le s i = B.get_int64_le (bos s) i | ||
let get_int64_be s i = B.get_int64_be (bos s) i |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is literally a copy of
String.split_on_char
, since it lexically draws in Bytes.sub and Bytes.unsafe_get instead.