mirror of
https://github.com/libguestfs/libguestfs.git
synced 2026-03-21 22:53:37 +00:00
sysprep: Move skip_dashes function into Utils module.
This is mostly code motion, but I also changed the function to use String.unsafe_get and raise Invalid_argument on failure.
This commit is contained in:
@@ -16,6 +16,8 @@
|
||||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*)
|
||||
|
||||
open Utils
|
||||
|
||||
open Printf
|
||||
|
||||
type flag = [ `Created_files ]
|
||||
@@ -106,18 +108,6 @@ let dump_pod () =
|
||||
printf "%s\n\n" op.pod_description
|
||||
) !ops
|
||||
|
||||
(* Skip any leading '-' characters when comparing command line args. *)
|
||||
let skip_dashes str =
|
||||
let n = String.length str in
|
||||
let rec loop i =
|
||||
if i >= n then assert false
|
||||
else if str.[i] = '-' then loop (i+1)
|
||||
else i
|
||||
in
|
||||
let i = loop 0 in
|
||||
if i = 0 then str
|
||||
else String.sub str i (n-i)
|
||||
|
||||
let dump_pod_options () =
|
||||
assert !baked;
|
||||
|
||||
|
||||
@@ -69,3 +69,15 @@ let string_random8 =
|
||||
String.make 1 c
|
||||
) [1;2;3;4;5;6;7;8]
|
||||
)
|
||||
|
||||
(* Skip any leading '-' characters when comparing command line args. *)
|
||||
let skip_dashes str =
|
||||
let n = String.length str in
|
||||
let rec loop i =
|
||||
if i >= n then invalid_arg "skip_dashes"
|
||||
else if String.unsafe_get str i = '-' then loop (i+1)
|
||||
else i
|
||||
in
|
||||
let i = loop 0 in
|
||||
if i = 0 then str
|
||||
else String.sub str i (n-i)
|
||||
|
||||
@@ -37,3 +37,10 @@ val string_random8 : unit -> string
|
||||
(** Return a random 8 character string, suitable as a temporary
|
||||
filename since every filesystem supports at least 8 character
|
||||
filenames. *)
|
||||
|
||||
val skip_dashes : string -> string
|
||||
(** Take a string like ["--str"] and return ["str"], that is, skip
|
||||
any leading dash characters.
|
||||
|
||||
If the string contains only dash characters, this raises
|
||||
[Invalid_argument "skip_dashes"]. *)
|
||||
|
||||
Reference in New Issue
Block a user