UrlUtil.cpp
Go to the documentation of this file.
00001 
00005 #include "UrlUtil.h"
00006 
00007 #include <boost/version.hpp>
00008 #if (BOOST_VERSION <= 103301)
00009 #include <boost/filesystem/path.hpp>
00010 #include <boost/filesystem/operations.hpp>
00011 #else
00012 #include <boost/filesystem.hpp>
00013 #endif
00014 
00015 using namespace boost;
00016 
00017 
00025 string hrp::deleteURLScheme(string url)
00026 {
00027     static const string fileProtocolHeader1("file://");
00028     static const string fileProtocolHeader2("file:");
00029 
00030     size_t pos = url.find( fileProtocolHeader1 );
00031     if( 0 == pos ) {
00032         url.erase( 0, fileProtocolHeader1.size() );
00033     } else {
00034         size_t pos = url.find( fileProtocolHeader2 );
00035         if( 0 == pos ) {
00036             url.erase( 0, fileProtocolHeader2.size() );
00037         }
00038     }
00039 
00040     // Windows ドライブ文字列の時はディレクトリ区切り文字分をさらに削除//
00041     if ( url.find(":") == 2 && url.find("/") ==0 )
00042         url.erase ( 0, 1 );
00043 
00044     return url;
00045 }
00046 
00047 
00057 void hrp::getPathFromUrl(string& refUrl, const string& rootDir, string srcUrl)
00058 {
00059 
00060     if ( isFileProtocol(srcUrl) ){   // ローカルファイル //
00061 #if (BOOST_VERSION < 104600)
00062         filesystem::path filepath( deleteURLScheme(srcUrl), filesystem::native);
00063         if(exists(filepath)){    // 元が絶対パス //
00064             refUrl = filesystem::system_complete(filepath).file_string();
00065         }else{               // 元が相対パス //
00066             filesystem::path filepath(rootDir + deleteURLScheme(srcUrl), filesystem::native);
00067             if(filesystem::exists(filepath)){
00068                 refUrl = system_complete(filepath).file_string();
00069             }
00070         }
00071 #elif (BOOST_VERSION >= 105000)
00072         filesystem::path filepath( deleteURLScheme(srcUrl), (void *)filesystem::native);
00073         if(exists(filepath)){    // 元が絶対パス //
00074             refUrl = filesystem::system_complete(filepath).string();
00075         }else{               // 元が相対パス //
00076             filesystem::path filepath(rootDir + deleteURLScheme(srcUrl), (void *)filesystem::native);
00077             if(filesystem::exists(filepath)){
00078                 refUrl = system_complete(filepath).string();
00079             }
00080         }
00081 #else
00082         filesystem3::path filepath( deleteURLScheme(srcUrl), (void *)filesystem3::native);
00083         if(exists(filepath)){    // 元が絶対パス //
00084             refUrl = filesystem3::system_complete(filepath).string();
00085         }else{               // 元が相対パス //
00086             filesystem3::path filepath(rootDir + deleteURLScheme(srcUrl), (void *)filesystem3::native);
00087             if(filesystem::exists(filepath)){
00088                 refUrl = system_complete(filepath).string();
00089             }
00090         }
00091 #endif
00092     } else {
00093         // ファイルスキーム以外の処理 //
00094     }
00095 }
00096 
00097 
00105 bool hrp::isFileProtocol(const string& ref)
00106 {
00107     bool ret = false;
00108     string::size_type pos = ref.find(":");
00109     if ( pos == string::npos || pos == 1 )
00110     {
00111         // Directly local path || Windows drive letter separator
00112         ret = true;
00113     } else {
00114         if( ref.find("file:") == 0 )
00115             ret = true;
00116     }
00117     return ret;
00118 }


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Apr 11 2019 03:30:19