[PATCH 1/2] firstboot: Factor out regular expression constant.
Don't need to evaluate this every time we call the function. --- customize/firstboot.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/customize/firstboot.ml b/customize/firstboot.ml index b12d616..c4af7a9 100644 --- a/customize/firstboot.ml +++ b/customize/firstboot.ml @@ -27,8 +27,10 @@ open Regedit let unix2dos s = String.concat "\r\n" (Str.split_delim (Str.regexp_string "\n") s) -let sanitize_name n = - Str.global_replace (Str.regexp "[^A-Za-z0-9_]") "-" n +let sanitize_name = + let rex = Str.regexp "[^A-Za-z0-9_]" in + fun n -> + Str.global_replace rex "-" n (* For Linux guests. *) module Linux = struct -- 2.3.1
--- customize/firstboot.ml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/customize/firstboot.ml b/customize/firstboot.ml index c4af7a9..29ec544 100644 --- a/customize/firstboot.ml +++ b/customize/firstboot.ml @@ -30,7 +30,9 @@ let unix2dos s = let sanitize_name = let rex = Str.regexp "[^A-Za-z0-9_]" in fun n -> - Str.global_replace rex "-" n + let n = Str.global_replace rex "-" n in + let len = String.length n and max = 60 in + if len >= max then String.sub n 0 max else n (* For Linux guests. *) module Linux = struct -- 2.3.1
On Monday 27 April 2015 15:15:06 Richard W.M. Jones wrote:
Don't need to evaluate this every time we call the function. --- customize/firstboot.ml | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/customize/firstboot.ml b/customize/firstboot.ml index b12d616..c4af7a9 100644 --- a/customize/firstboot.ml +++ b/customize/firstboot.ml @@ -27,8 +27,10 @@ open Regedit let unix2dos s = String.concat "\r\n" (Str.split_delim (Str.regexp_string "\n") s)
-let sanitize_name n = - Str.global_replace (Str.regexp "[^A-Za-z0-9_]") "-" n +let sanitize_name = + let rex = Str.regexp "[^A-Za-z0-9_]" in + fun n -> + Str.global_replace rex "-" n
(* For Linux guests. *) module Linux = struct
LGTM. -- Pino Toscano
participants (2)
-
Pino Toscano -
Richard W.M. Jones