diff options
author | Philippe Pebay <pppebay@sandia.gov> | 2007-12-05 17:24:27 (GMT) |
---|---|---|
committer | Philippe Pebay <pppebay@sandia.gov> | 2007-12-05 17:24:27 (GMT) |
commit | f18ae2234c6fecedd440670e9651fb06761049df (patch) | |
tree | b4b15dfda017ca2f438f99f0ed71610c2a2746db /Source/kwsys/SystemTools.cxx | |
parent | 8eea168c232463b3623ec621932b689232b98699 (diff) | |
download | CMake-f18ae2234c6fecedd440670e9651fb06761049df.zip CMake-f18ae2234c6fecedd440670e9651fb06761049df.tar.gz CMake-f18ae2234c6fecedd440670e9651fb06761049df.tar.bz2 |
ENH: added two functions for URL parsing:
1. an "abridged" version that separates protocol from dataglom in
an expression with the form protocol://dataglom
2. a "full" version that parses protocol, username, password,
hostname, port, and path in a standard URL (all of these variables
are optional, except for protocol and hostname).
Diffstat (limited to 'Source/kwsys/SystemTools.cxx')
-rw-r--r-- | Source/kwsys/SystemTools.cxx | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/Source/kwsys/SystemTools.cxx b/Source/kwsys/SystemTools.cxx index b3d92e8..3d47c98 100644 --- a/Source/kwsys/SystemTools.cxx +++ b/Source/kwsys/SystemTools.cxx @@ -12,6 +12,7 @@ =========================================================================*/ #include "kwsysPrivate.h" +#include KWSYS_HEADER(RegularExpression.hxx) #include KWSYS_HEADER(SystemTools.hxx) #include KWSYS_HEADER(Directory.hxx) @@ -76,12 +77,16 @@ # define HAVE_TTY_INFO 1 #endif +#define VTK_URL_PROTOCOL_REGEX "([a-zA-Z0-9]*)://(.*)" +#define VTK_URL_REGEX "([a-zA-Z0-9]*)://(([A-Za-z]+)(:([^:@]+))?@)?([^:@/]+)(:([0-9]+))?/(.+)?"; + #ifdef _MSC_VER #include <sys/utime.h> #else #include <utime.h> #endif + // This is a hack to prevent warnings about these functions being // declared but not referenced. #if defined(__sgi) && !defined(__GNUC__) @@ -4252,6 +4257,58 @@ kwsys_stl::string SystemTools::GetOperatingSystemNameAndVersion() return res; } +// ---------------------------------------------------------------------- +bool SystemTools::ParseURLProtocol( const kwsys_stl::string& URL, + kwsys_stl::string& protocol, + kwsys_stl::string& dataglom ) +{ + // match 0 entire url + // match 1 protocol + // match 2 dataglom following protocol:// + vtksys::RegularExpression urlRe( VTK_URL_PROTOCOL_REGEX ); + + if ( ! urlRe.find( URL ) ) return false; + + protocol = urlRe.match( 1 ); + dataglom = urlRe.match( 2 ); + + return true; +} + +// ---------------------------------------------------------------------- +bool SystemTools::ParseURL( const kwsys_stl::string& URL, + kwsys_stl::string& protocol, + kwsys_stl::string& username, + kwsys_stl::string& password, + kwsys_stl::string& hostname, + kwsys_stl::string& dataport, + kwsys_stl::string& database ) +{ + vtksys::RegularExpression urlRe( VTK_URL_PROTOCOL_REGEX ); + if ( ! urlRe.find( URL ) ) return false; + + // match 0 URL + // match 1 protocol + // match 2 mangled user + // match 3 username + // match 4 mangled password + // match 5 password + // match 6 hostname + // match 7 mangled port + // match 8 dataport + // match 9 database name + + protocol = urlRe.match( 1 ); + username = urlRe.match( 3 ); + password = urlRe.match( 5 ); + hostname = urlRe.match( 6 ); + dataport = urlRe.match( 8 ); + database = urlRe.match( 9 ); + + return true; +} + +// ---------------------------------------------------------------------- // These must NOT be initialized. Default initialization to zero is // necessary. unsigned int SystemToolsManagerCount; |