summaryrefslogtreecommitdiffstats
path: root/sysprep
diff options
context:
space:
mode:
authorRichard W.M. Jones <rjones@redhat.com>2012-04-11 16:18:29 +0100
committerRichard W.M. Jones <rjones@redhat.com>2012-04-11 16:22:58 +0100
commita3d6629a0b54aca6d7b5b38750399b5396cdbf07 (patch)
treeb97d6cf5d6875e807741c41e5f466460cdf28142 /sysprep
parentedca57b49e88d179d996652a44f7d6ba5b9ca729 (diff)
downloadlibguestfs-a3d6629a0b54aca6d7b5b38750399b5396cdbf07.tar.gz
libguestfs-a3d6629a0b54aca6d7b5b38750399b5396cdbf07.tar.xz
libguestfs-a3d6629a0b54aca6d7b5b38750399b5396cdbf07.zip
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.
Diffstat (limited to 'sysprep')
-rw-r--r--sysprep/sysprep_operation.ml14
-rw-r--r--sysprep/utils.ml12
-rw-r--r--sysprep/utils.mli7
3 files changed, 21 insertions, 12 deletions
diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml
index fedf9a04..a77b66d2 100644
--- a/sysprep/sysprep_operation.ml
+++ b/sysprep/sysprep_operation.ml
@@ -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;
diff --git a/sysprep/utils.ml b/sysprep/utils.ml
index dfac57d4..ad265984 100644
--- a/sysprep/utils.ml
+++ b/sysprep/utils.ml
@@ -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)
diff --git a/sysprep/utils.mli b/sysprep/utils.mli
index f9cf16c8..51426f44 100644
--- a/sysprep/utils.mli
+++ b/sysprep/utils.mli
@@ -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"]. *)