diff --git a/CMakeLists.txt b/CMakeLists.txt index 223e04d..979c5b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -46,6 +46,7 @@ option(OPT_COMPILE_TESTS "Compile collada tests" OFF) option(OPT_BUILD_PACKAGES "Set to ON to generate CPack configuration files and packaging targets" OFF) option(OPT_BUILD_PACKAGE_DEFAULT "Set to ON to generate a default openrave package that creates symlinks" ON) option(OPT_DOUBLE_PRECISION "Use double precision for everything (daeFloat included)" ON) +option(OPT_USE_PCRECPP "Use pcrecpp library to find basename and parse uri, otherwise use parseruri and basename function" OFF) set(COLLADA_DOM_EXTERNAL_FLAGS) if( OPT_COLLADA14 ) @@ -226,25 +227,30 @@ else() set(MINIZIP_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/dom/external-libs/minizip-1.1 ${ZLIB_INCLUDE_DIR}) endif() -pkg_check_modules(libpcrecpp libpcrecpp) -if( libpcrecpp_FOUND ) - set(CMAKE_REQUIRED_INCLUDES ${libpcrecpp_INCLUDE_DIRS}) - check_include_file_cxx(pcrecpp.h HAVE_PCRECPP_H) - set(CMAKE_REQUIRED_INCLUDES) - if( NOT HAVE_PCRECPP_H ) - set(libpcrecpp_FOUND 0) +if(OPT_USE_PCRECPP) + pkg_check_modules(libpcrecpp libpcrecpp) + if( libpcrecpp_FOUND ) + set(CMAKE_REQUIRED_INCLUDES ${libpcrecpp_INCLUDE_DIRS}) + check_include_file_cxx(pcrecpp.h HAVE_PCRECPP_H) + set(CMAKE_REQUIRED_INCLUDES) + if( NOT HAVE_PCRECPP_H ) + set(libpcrecpp_FOUND 0) + endif() endif() -endif() -if( NOT libpcrecpp_FOUND ) - message(STATUS "System pcre not found, using local from sources") - # include the local pcre - add_subdirectory(dom/external-libs/pcre-8.02) - set(libpcrecpp_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/dom/external-libs/pcre-8.02) - set(libpcrecpp_LIBRARY_DIRS) - set(libpcrecpp_LIBRARIES pcrecpp_local) - set(libpcrecpp_CFLAGS_OTHERS "-DPCRE_STATIC") - set(libpcrecpp_LDFLAGS_OTHERS) + if( NOT libpcrecpp_FOUND ) + message(STATUS "System pcre not found, using local from sources") + # include the local pcre + add_subdirectory(dom/external-libs/pcre-8.02) + set(libpcrecpp_INCLUDE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}/dom/external-libs/pcre-8.02) + set(libpcrecpp_LIBRARY_DIRS) + set(libpcrecpp_LIBRARIES pcrecpp_local) + set(libpcrecpp_CFLAGS_OTHERS "-DPCRE_STATIC") + set(libpcrecpp_LDFLAGS_OTHERS) + endif() +else() + pkg_check_modules(liburiparser liburiparser REQUIRED) + set(liburiparser_CFLAGS_OTHERS "-DUSE_URIPARSER") endif() # declare minizip/zlib before libxml2! (for some reason the precompiled libxml2 libraries have zlib.h/zconf.h) diff --git a/dom/CMakeLists.txt b/dom/CMakeLists.txt index afee0db..f7ffb27 100644 --- a/dom/CMakeLists.txt +++ b/dom/CMakeLists.txt @@ -1,6 +1,6 @@ set(COLLADA_INTERNAL_INCLUDE ${CMAKE_CURRENT_SOURCE_DIR}/include) include_directories(${COLLADA_INTERNAL_INCLUDE}) -set(COLLADA_LIBS minizip ${libpcrecpp_LIBRARIES} ${ZLIB_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}) +set(COLLADA_LIBS minizip ${liburiparser_LIBRARIES} ${libpcrecpp_LIBRARIES} ${ZLIB_LIBRARIES} ${Boost_FILESYSTEM_LIBRARY} ${Boost_SYSTEM_LIBRARY}) file(GLOB dae_files ${CMAKE_CURRENT_SOURCE_DIR}/src/dae/*.cpp) if( LIBXML2_FOUND ) @@ -13,7 +13,7 @@ file(GLOB stddatabase_files ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/STLDatabase/ file(GLOB stderrplugin_files ${CMAKE_CURRENT_SOURCE_DIR}/src/modules/stdErrPlugin/*.cpp) set(COLLADA_BASE_SOURCES ${dae_files} ${libxmlplugin_files} ${stddatabase_files} ${stderrplugin_files}) -set(COLLADA_COMPILE_FLAGS "${libpcrecpp_CFLAGS_OTHERS} ${EXTRA_COMPILE_FLAGS} ${Boost_CFLAGS}") +set(COLLADA_COMPILE_FLAGS "${liburiparser_CFLAGS_OTHERS} ${libpcrecpp_CFLAGS_OTHERS} ${EXTRA_COMPILE_FLAGS} ${Boost_CFLAGS}") # create dynamic libraries set(COLLADA_COMPILE_FLAGS "${COLLADA_COMPILE_FLAGS} -DDOM_DYNAMIC -DDOM_EXPORT") diff --git a/dom/src/dae/daeURI.cpp b/dom/src/dae/daeURI.cpp index 7f10005..3a8f815 100644 --- a/dom/src/dae/daeURI.cpp +++ b/dom/src/dae/daeURI.cpp @@ -13,7 +13,28 @@ #include #include #include + +#ifdef USE_URIPARSER +#include +std::string fromRange(const UriTextRangeA & rng) +{ + return std::string(rng.first, rng.afterLast); +} +std::string fromList(UriPathSegmentA * xs, const std::string & delim) +{ + UriPathSegmentStructA * head(xs); + std::string accum; + while (head) + { + accum += delim + fromRange(head->text); + head = head->next; + } + + return accum; +} +#else #include +#endif using namespace std; using namespace cdom; @@ -141,12 +162,26 @@ void parsePath(const string& path, //dir = baseName = extension = ""; //re.FullMatch(path, &dir, &baseName, &extension); +#ifdef USE_URIPARSER + if ( path.size() <= 1) { + dir = path; + baseName = ""; + } else { + dir= path.substr(0, path.rfind('/')+1); + baseName = path.substr(path.rfind('/')+1); + } + if ( baseName.rfind('.') != std::string::npos ) { + extension = baseName.substr(baseName.find('.')); + baseName = baseName.substr(0, baseName.find('.')); + } +#else static pcrecpp::RE findDir("(.*/)?(.*)?"); static pcrecpp::RE findExt("([^.]*)?(\\..*)?"); string tmpFile; dir = baseName = extension = tmpFile = ""; findDir.PartialMatch(path, &dir, &tmpFile); findExt.PartialMatch(tmpFile, &baseName, &extension); +#endif } } @@ -746,12 +781,30 @@ bool cdom::parseUriRef(const string& uriRef, string& path, string& query, string& fragment) { + +#ifdef USE_URIPARSER + UriParserStateA state; + UriUriA uri; + state.uri = &uri; + if ( uriParseUriA(&state, uriRef.c_str()) == 0 ) { + scheme = fromRange(uri.scheme); + authority = fromRange(uri.hostText); + path = fromList(uri.pathHead, "/"); + if (uri.absolutePath != URI_TRUE and uri.hostText.first == NULL) + path = path.erase(0, 1); + query = fromRange(uri.query); + fragment = fromRange(uri.fragment); + uriFreeUriMembersA(&uri); + return true; + } +#else // This regular expression for parsing URI references comes from the URI spec: // http://tools.ietf.org/html/rfc3986#appendix-B static pcrecpp::RE re("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); string s1, s3, s6, s8; if (re.FullMatch(uriRef, &s1, &scheme, &s3, &authority, &path, &s6, &query, &s8, &fragment)) return true; +#endif return false; }