[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v2 2/3] builder: Replace small usage of Str with new PCRE module.



---
 builder/Makefile.am  |  6 +++++-
 builder/languages.ml | 13 ++++++-------
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/builder/Makefile.am b/builder/Makefile.am
index e64c8991f..1b51376be 100644
--- a/builder/Makefile.am
+++ b/builder/Makefile.am
@@ -126,6 +126,7 @@ OCAMLPACKAGES = \
 	-I $(top_builddir)/ocaml \
 	-I $(top_builddir)/common/mlstdutils \
 	-I $(top_builddir)/common/mlutils \
+	-I $(top_builddir)/common/mlpcre \
 	-I $(top_builddir)/mllib \
 	-I $(top_builddir)/customize
 OCAMLPACKAGES_TESTS =
@@ -156,6 +157,7 @@ OBJECTS = $(XOBJECTS)
 endif
 
 OCAMLLINKFLAGS = \
+	mlpcre.$(MLARCHIVE) \
 	mlstdutils.$(MLARCHIVE) \
 	mlguestfs.$(MLARCHIVE) \
 	mlcutils.$(MLARCHIVE) \
@@ -165,6 +167,7 @@ OCAMLLINKFLAGS = \
 
 virt_builder_DEPENDENCIES = \
 	$(OBJECTS) \
+	../common/mlpcre/mlpcre.$(MLARCHIVE) \
 	../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
 	../common/mlutils/mlcutils.$(MLARCHIVE) \
 	../mllib/mllib.$(MLARCHIVE) \
@@ -238,6 +241,7 @@ endif
 
 yajl_tests_DEPENDENCIES = \
 	$(yajl_tests_THEOBJECTS) \
+	../common/mlpcre/mlpcre.$(MLARCHIVE) \
 	../common/mlstdutils/mlstdutils.$(MLARCHIVE) \
 	../common/mlutils/mlcutils.$(MLARCHIVE) \
 	../mllib/mllib.$(MLARCHIVE) \
@@ -311,7 +315,7 @@ depend: .depend
 
 .depend: $(wildcard $(abs_srcdir)/*.mli) $(wildcard $(abs_srcdir)/*.ml)
 	rm -f $@ $ -t
-	$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
+	$(OCAMLFIND) ocamldep -I ../ocaml -I $(abs_srcdir) -I $(abs_top_builddir)/common/mlstdutils -I $(abs_top_builddir)/common/mlutils -I $(abs_top_builddir)/common/mlpcre -I $(abs_top_builddir)/mllib -I $(abs_top_builddir)/customize $^ | \
 	  $(SED) 's/ *$$//' | \
 	  $(SED) -e :a -e '/ *\\$$/N; s/ *\\\n */ /; ta' | \
 	  $(SED) -e 's,$(abs_srcdir)/,$(builddir)/,g' | \
diff --git a/builder/languages.ml b/builder/languages.ml
index d94f97c5c..89d173999 100644
--- a/builder/languages.ml
+++ b/builder/languages.ml
@@ -19,15 +19,14 @@
 open Std_utils
 open Common_utils
 
+let re_locale =
+  PCRE.compile "^([A-Za-z]+)(_([A-Za-z]+))?(\\.([A-Za-z0-9-]+))?(@([A-Za-z]+))?$"
+
 let split_locale loc =
-  let regex = Str.regexp "^\\([A-Za-z]+\\)\\(_\\([A-Za-z]+\\)\\)?\\(\\.\\([A-Za-z0-9-]+\\)\\)?\\(@\\([A-Za-z]+\\)\\)?$" in
   let l = ref [] in
-  if Str.string_match regex loc 0 then (
-    let match_or_empty n =
-      try Str.matched_group n loc with
-      | Not_found -> ""
-    in
-    let lang = Str.matched_group 1 loc in
+  if PCRE.matches re_locale loc then (
+    let match_or_empty n = try PCRE.sub n with Not_found -> "" in
+    let lang = PCRE.sub 1 in
     let territory = match_or_empty 3 in
     (match territory with
     | "" -> ()
-- 
2.13.2


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]