Selaa lähdekoodia

added regex usage for Linux (NICE_USELIB_REGEX)

Johannes Ruehle 11 vuotta sitten
vanhempi
commit
7c9ad3c53e
2 muutettua tiedostoa jossa 12 lisäystä ja 5 poistoa
  1. 8 0
      CMakeLists.txt
  2. 4 5
      core/basics/StringTools.cpp

+ 8 - 0
CMakeLists.txt

@@ -2,6 +2,7 @@ cmake_minimum_required(VERSION 2.8.6) #version 2.8.6 at least required because o
 project (NICELibrary)
 
 include(CheckSymbolExists)
+include(CheckIncludeFiles)
 
 set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/")
 
@@ -171,6 +172,13 @@ else()
 	  include_directories( ${GLUT_INCLUDE_DIR} )
 	  ADD_DEFINITIONS(-DNICE_USELIB_GLUT)
 	endif()
+
+  #check for available regex stuff
+  CHECK_INCLUDE_FILES(regex.h HAVE_REGEX_H)
+  if(HAVE_REGEX_H)
+    ADD_DEFINITIONS(-DNICE_USELIB_REGEX)  #regular expressions are available per default under linux
+    message(STATUS "Regex found")
+  endif()
 endif()
 
 if(MSVC)

+ 4 - 5
core/basics/StringTools.cpp

@@ -16,8 +16,7 @@
 
 #include "StringTools.h"
 
-//#define USE_REGEX_LIB
-#ifdef USE_REGEX_LIB
+#ifdef NICE_USELIB_REGEX
 #include <regex.h>
 #endif
 
@@ -148,7 +147,7 @@ std::string StringTools::chomp(string s)
 
 bool StringTools::regexSubstitute ( std::string & s, const std::string & regex, const std::string & subst )
 {
-#ifdef USE_REGEX_LIB
+#ifdef NICE_USELIB_REGEX
     vector<string> submatches;
     std::ostringstream os_regex;
     
@@ -180,7 +179,7 @@ bool StringTools::regexSubstitute ( std::string & s, const std::string & regex,
 
 bool StringTools::regexMatch ( const string & s, const string & regex )
 {
-#ifdef USE_REGEX_LIB
+#ifdef NICE_USELIB_REGEX
     vector<string> submatches;
     return regexMatch ( s, regex, submatches );
 #else
@@ -191,7 +190,7 @@ bool StringTools::regexMatch ( const string & s, const string & regex )
 bool StringTools::regexMatch ( const string & s, const string & regex, 
 			 vector<string> & submatches )
 {
-#ifdef USE_REGEX_LIB
+#ifdef NICE_USELIB_REGEX
 	submatches.clear();
 
     int    status;