[sword-svn] r2975 - in trunk: . src/modules

scribe at crosswire.org scribe at crosswire.org
Tue Sep 10 05:11:47 MST 2013


Author: scribe
Date: 2013-09-10 05:11:46 -0700 (Tue, 10 Sep 2013)
New Revision: 2975

Modified:
   trunk/configure.ac
   trunk/src/modules/swmodule.cpp
   trunk/usrinst.sh
Log:
added compile option to build with c++11 std::regex support


Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2013-09-10 11:56:23 UTC (rev 2974)
+++ trunk/configure.ac	2013-09-10 12:11:46 UTC (rev 2975)
@@ -55,6 +55,8 @@
 	AC_HELP_STRING([--with-icusword],[use custom SWORD ICU (default=no)]),,with_icusword=no)
 AC_ARG_WITH(conf,
 	AC_HELP_STRING([--with-conf],[install a new sword.conf (default=yes)]),,with_conf=yes)
+AC_ARG_WITH(cxx11regex,
+	AC_HELP_STRING([--with-cxx11regex],[build regex support using c++11 regex (default=no)]),,with_cxx11regex=no)
 AC_ARG_WITH(curl,
 	AC_HELP_STRING([--with-curl],[build install manager support using libcurl (default=yes)]),,with_curl=yes)
 AC_ARG_WITH(curl_sftp,
@@ -258,6 +260,10 @@
 	with_internalftplib=yes
 fi
 
+if test x$with_cxx11regex = xyes; then
+	AM_CXXFLAGS="$AM_CXXFLAGS -DUSECXX11REGEX -std=c++11 -ftemplate-depth=100"
+fi
+
 # ---------------------------------------------------------------------
 # Check for clucene for lucene searching support
 # ---------------------------------------------------------------------
@@ -356,7 +362,6 @@
 # Conditional variables
 # ---------------------------------------------------------------------
 
-# don't #ifdef in .cpp files HAVE_ stuff because non-ac compiles won't be able to switch them since we include config.h
 AM_CONDITIONAL(HAVE_LIBZ, test x$with_zlib = xyes)
 AM_CONDITIONAL(HAVE_ICU, test x$with_icu = xyes)
 AM_CONDITIONAL(HAVE_ICUSWORD, test x$with_icusword = xyes)
@@ -365,6 +370,7 @@
 AM_CONDITIONAL(USELUCENE, test "x$with_clucene" != xno)
 AM_CONDITIONAL(SHAREDLIB, test x$enable_shared = xyes)
 AM_CONDITIONAL(INSTCONF, test x$with_conf = xyes)
+AM_CONDITIONAL(USECXX11REGEX, test x$with_cxx11regex = xyes)
 AM_CONDITIONAL(WITHCURL, test x$with_curl = xyes)
 AM_CONDITIONAL(WITHCURLSFTP, test x$with_curl_sftp = xyes)
 AM_CONDITIONAL(INTERNALFTPLIB, test x$with_internalftplib = xyes)
@@ -393,6 +399,7 @@
 echo     "     LIBZ:             $with_zlib"
 echo     "     ICU:              $with_icu"
 echo     "     ICUSWORD:         $with_icusword"
+echo     "     CXX11REGEX:       $with_cxx11regex"
 echo     "     CURL:             $with_curl"
 echo     "     CURL SFTP:        $with_curl_sftp"
 echo     "     INTERNAL FTPLIB:  $with_internalftplib"

Modified: trunk/src/modules/swmodule.cpp
===================================================================
--- trunk/src/modules/swmodule.cpp	2013-09-10 11:56:23 UTC (rev 2974)
+++ trunk/src/modules/swmodule.cpp	2013-09-10 12:11:46 UTC (rev 2975)
@@ -29,7 +29,6 @@
 #include <sysdata.h>
 #include <swmodule.h>
 #include <utilstr.h>
-#include <regex.h>	// GNU
 #include <swfilter.h>
 #include <versekey.h>	// KLUDGE for Search
 #include <treekeyidx.h>	// KLUDGE for Search
@@ -40,6 +39,15 @@
 #include <iostream>
 #endif
 
+#ifdef USECXX11REGEX
+#include <regex>
+#ifndef REG_ICASE
+#define REG_ICASE std::regex::icase
+#endif
+#else
+#include <regex.h>	// GNU
+#endif
+
 #ifdef USELUCENE
 #include <CLucene.h>
 
@@ -393,7 +401,16 @@
 	SWKey *resultKey = createKey();
 	SWKey *lastKey   = createKey();
 	SWBuf lastBuf = "";
+
+#ifdef USECXX11REGEX
+    std::locale oldLocale;
+    std::locale::global(std::locale("en_US.UTF-8"));
+
+    std::regex preg;
+#else
 	regex_t preg;
+#endif
+
 	vector<SWBuf> words;
 	vector<SWBuf> window;
 	const char *sres;
@@ -431,8 +448,12 @@
 		highIndex = 1;		// avoid division by zero errors.
 	*this = TOP;
 	if (searchType >= 0) {
+#ifdef USECXX11REGEX
+		preg = std::regex((SWBuf(".*")+istr+".*").c_str(), std::regex_constants::extended & flags);
+#else
 		flags |=searchType|REG_NOSUB|REG_EXTENDED;
 		regcomp(&preg, istr, flags);
+#endif
 	}
 
 	(*percent)(++perc, percentUserData);
@@ -564,13 +585,21 @@
 		}
 		if (searchType >= 0) {
 			SWBuf textBuf = stripText();
+#ifdef USECXX11REGEX
+			if (std::regex_match(std::string(textBuf.c_str()), preg)) {
+#else
 			if (!regexec(&preg, textBuf, 0, 0, 0)) {
+#endif
 				*resultKey = *getKey();
 				resultKey->clearBound();
 				listKey << *resultKey;
 				lastBuf = "";
 			}
+#ifdef USECXX11REGEX
+			else if (std::regex_match(std::string((lastBuf + ' ' + textBuf).c_str()), preg)) {
+#else
 			else if (!regexec(&preg, lastBuf + ' ' + textBuf, 0, 0, 0)) {
+#endif
 				lastKey->clearBound();
 				listKey << *lastKey;
 				lastBuf = textBuf;
@@ -757,8 +786,13 @@
 	
 
 	// cleaup work
-	if (searchType >= 0)
+	if (searchType >= 0) {
+#ifdef USECXX11REGEX
+		std::locale::global(oldLocale);
+#else
 		regfree(&preg);
+#endif
+	}
 
 	setKey(*saveKey);
 

Modified: trunk/usrinst.sh
===================================================================
--- trunk/usrinst.sh	2013-09-10 11:56:23 UTC (rev 2974)
+++ trunk/usrinst.sh	2013-09-10 12:11:46 UTC (rev 2975)
@@ -34,8 +34,9 @@
 OPTIONS="--enable-debug $OPTIONS"
 #OPTIONS="--enable-profile $OPTIONS"
 
+#OPTIONS="--with-cxx11regex $OPTIONS"
+#OPTIONS="--with-icusword $OPTIONS"
 #OPTIONS="--without-icu $OPTIONS"
-#OPTIONS="--with-icusword $OPTIONS"
 #OPTIONS="--without-clucene $OPTIONS"
 #OPTIONS="--without-curl $OPTIONS"
 




More information about the sword-cvs mailing list