From 16b2ffa97ea8b2872306bc4400605821440f6589 Mon Sep 17 00:00:00 2001 From: "Richard W.M. Jones" Date: Wed, 11 Apr 2012 16:20:23 +0100 Subject: [PATCH] sysprep: Make a common Utils.compare_command_line_args function. This isn't quite code motion, since the new function also ignores case (which previously we didn't ignore). --- sysprep/sysprep_operation.ml | 6 ++---- sysprep/utils.ml | 3 +++ sysprep/utils.mli | 5 +++++ 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sysprep/sysprep_operation.ml b/sysprep/sysprep_operation.ml index a77b66d21..b48d8f8b6 100644 --- a/sysprep/sysprep_operation.ml +++ b/sysprep/sysprep_operation.ml @@ -138,10 +138,8 @@ let dump_pod_options () = | Arg.Rest _ -> assert false (* XXX not implemented *) ) args in - let args = List.sort ( - fun (a, _) (b, _) -> - compare (skip_dashes a) (skip_dashes b) - ) args in + let args = + List.sort (fun (a, _) (b, _) -> compare_command_line_args a b) args in List.iter ( fun (arg_name, (op_name, heading, pod)) -> diff --git a/sysprep/utils.ml b/sysprep/utils.ml index ad265984e..003ae8651 100644 --- a/sysprep/utils.ml +++ b/sysprep/utils.ml @@ -81,3 +81,6 @@ let skip_dashes str = let i = loop 0 in if i = 0 then str else String.sub str i (n-i) + +let compare_command_line_args a b = + compare (String.lowercase (skip_dashes a)) (String.lowercase (skip_dashes b)) diff --git a/sysprep/utils.mli b/sysprep/utils.mli index 51426f44f..2b7e32082 100644 --- a/sysprep/utils.mli +++ b/sysprep/utils.mli @@ -44,3 +44,8 @@ val skip_dashes : string -> string If the string contains only dash characters, this raises [Invalid_argument "skip_dashes"]. *) + +val compare_command_line_args : string -> string -> int +(** Compare two command line arguments (eg. ["-a"] and ["--V"]), + ignoring leading dashes and case. Note this assumes the + strings are 7 bit ASCII. *)