-
Notifications
You must be signed in to change notification settings - Fork 292
xapi-idl: Delete String.{explode,implode} functions #5881
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
---|---|---|
|
@@ -39,10 +39,6 @@ module String = struct | |
done ; | ||
!accu | ||
|
||
let explode string = fold_right (fun h t -> h :: t) string [] | ||
|
||
let implode list = concat "" (List.map of_char list) | ||
|
||
(** True if string 'x' ends with suffix 'suffix' *) | ||
let endswith suffix x = | ||
let x_l = String.length x and suffix_l = String.length suffix in | ||
|
@@ -56,16 +52,6 @@ module String = struct | |
(** Returns true for whitespace characters, false otherwise *) | ||
let isspace = function ' ' | '\n' | '\r' | '\t' -> true | _ -> false | ||
|
||
(** Removes all the characters from the ends of a string for which the predicate is true *) | ||
let strip predicate string = | ||
let rec remove = function | ||
| [] -> | ||
[] | ||
| c :: cs -> | ||
if predicate c then remove cs else c :: cs | ||
in | ||
implode (List.rev (remove (List.rev (remove (explode string))))) | ||
|
||
let escaped ?rules string = | ||
match rules with | ||
| None -> | ||
|
@@ -81,24 +67,28 @@ module String = struct | |
in | ||
concat "" (fold_right aux string []) | ||
|
||
(** Take a predicate and a string, return a list of strings separated by | ||
runs of characters where the predicate was true (excluding those characters from the result) *) | ||
let split_f p str = | ||
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. 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. I'd rather avoid importing Astring if not needed, the function is well tested with unit tests |
||
let not_p x = not (p x) in | ||
let rec split_one p acc = function | ||
| [] -> | ||
(List.rev acc, []) | ||
| c :: cs -> | ||
if p c then split_one p (c :: acc) cs else (List.rev acc, c :: cs) | ||
let split_one seq = | ||
let not_p c = not (p c) in | ||
let a = Seq.take_while not_p seq in | ||
Vincent-lau marked this conversation as resolved.
Show resolved
Hide resolved
|
||
let b = Seq.drop_while not_p seq in | ||
(a, b) | ||
in | ||
let rec alternate acc drop chars = | ||
if chars = [] then | ||
let drop seq = Seq.drop_while p seq in | ||
let rec split acc chars = | ||
if Seq.is_empty chars then | ||
acc | ||
else | ||
let a, b = split_one (if drop then p else not_p) [] chars in | ||
alternate (if drop then acc else a :: acc) (not drop) b | ||
let a, b = split_one chars in | ||
let b = drop b in | ||
let acc = if Seq.is_empty a then acc else Seq.cons a acc in | ||
split acc b | ||
in | ||
List.rev (List.map implode (alternate [] true (explode str))) | ||
String.to_seq str | ||
|> split Seq.empty | ||
|> Seq.map String.of_seq | ||
|> List.of_seq | ||
|> List.rev | ||
|
||
let index_opt s c = | ||
let rec loop i = | ||
|
This file contains hidden or 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 hidden or 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.
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.
Uh oh!
There was an error while loading. Please reload this page.