UrlUtil.cpp
Go to the documentation of this file.
1 
5 #include "UrlUtil.h"
6 
7 #include <boost/version.hpp>
8 #if (BOOST_VERSION <= 103301)
9 #include <boost/filesystem/path.hpp>
10 #include <boost/filesystem/operations.hpp>
11 #else
12 #include <boost/filesystem.hpp>
13 #endif
14 
15 using namespace boost;
16 
17 
25 string hrp::deleteURLScheme(string url)
26 {
27  static const string fileProtocolHeader1("file://");
28  static const string fileProtocolHeader2("file:");
29 
30  size_t pos = url.find( fileProtocolHeader1 );
31  if( 0 == pos ) {
32  url.erase( 0, fileProtocolHeader1.size() );
33  } else {
34  size_t pos = url.find( fileProtocolHeader2 );
35  if( 0 == pos ) {
36  url.erase( 0, fileProtocolHeader2.size() );
37  }
38  }
39 
40  // Windows ドライブ文字列の時はディレクトリ区切り文字分をさらに削除//
41  if ( url.find(":") == 2 && url.find("/") ==0 )
42  url.erase ( 0, 1 );
43 
44  return url;
45 }
46 
47 
57 void hrp::getPathFromUrl(string& refUrl, const string& rootDir, string srcUrl)
58 {
59 
60  if ( isFileProtocol(srcUrl) ){ // ローカルファイル //
61 #if (BOOST_VERSION < 104600)
62  filesystem::path filepath( deleteURLScheme(srcUrl), filesystem::native);
63  if(exists(filepath)){ // 元が絶対パス //
64  refUrl = filesystem::system_complete(filepath).file_string();
65  }else{ // 元が相対パス //
66  filesystem::path filepath(rootDir + deleteURLScheme(srcUrl), filesystem::native);
67  if(filesystem::exists(filepath)){
68  refUrl = system_complete(filepath).file_string();
69  }
70  }
71 #elif (BOOST_VERSION >= 105000)
72  filesystem::path filepath( deleteURLScheme(srcUrl), (void *)filesystem::native);
73  if(exists(filepath)){ // 元が絶対パス //
74  refUrl = filesystem::system_complete(filepath).string();
75  }else{ // 元が相対パス //
76  filesystem::path filepath(rootDir + deleteURLScheme(srcUrl), (void *)filesystem::native);
77  if(filesystem::exists(filepath)){
78  refUrl = system_complete(filepath).string();
79  }
80  }
81 #else
82  filesystem3::path filepath( deleteURLScheme(srcUrl), (void *)filesystem3::native);
83  if(exists(filepath)){ // 元が絶対パス //
84  refUrl = filesystem3::system_complete(filepath).string();
85  }else{ // 元が相対パス //
86  filesystem3::path filepath(rootDir + deleteURLScheme(srcUrl), (void *)filesystem3::native);
87  if(filesystem::exists(filepath)){
88  refUrl = system_complete(filepath).string();
89  }
90  }
91 #endif
92  } else {
93  // ファイルスキーム以外の処理 //
94  }
95 }
96 
97 
105 bool hrp::isFileProtocol(const string& ref)
106 {
107  bool ret = false;
108  string::size_type pos = ref.find(":");
109  if ( pos == string::npos || pos == 1 )
110  {
111  // Directly local path || Windows drive letter separator
112  ret = true;
113  } else {
114  if( ref.find("file:") == 0 )
115  ret = true;
116  }
117  return ret;
118 }
Modifications controlling boost library behavior.
Definition: ColladaUtil.h:306
RTC::ReturnCode_t ret(RTC::Local::ReturnCode_t r)
HRP_UTIL_EXPORT void getPathFromUrl(string &refUrl, const string &rootDir, string srcUrl)
Definition: UrlUtil.cpp:57
HRP_UTIL_EXPORT string deleteURLScheme(string url)
Definition: UrlUtil.cpp:25
HRP_UTIL_EXPORT bool isFileProtocol(const string &ref)
Definition: UrlUtil.cpp:105


openhrp3
Author(s): AIST, General Robotix Inc., Nakamura Lab of Dept. of Mechano Informatics at University of Tokyo
autogenerated on Thu Sep 8 2022 02:24:05