11 inline void suffix(
const std::string& a_string,std::string& a_value,
bool a_back =
true) {
14 std::string::size_type pos = a_back?a_string.rfind(
'.'):a_string.find(
'.');
15 if(pos==std::string::npos) {a_value.clear();
return;}
17 a_value = a_string.substr(pos,a_string.size()-pos);
20 inline void nosuffix(
const std::string& a_string,std::string& a_value,
bool a_back =
true){
24 std::string::size_type pos = a_string.rfind(
'/');
25 if(pos==std::string::npos) pos = a_string.rfind(
'\\');
26 if(pos==std::string::npos) pos = 0;
28 std::string s = a_string.substr(pos,a_string.size()-pos);
29 std::string::size_type dot_pos = a_back?s.rfind(
'.'):s.find(
'.');
30 if(dot_pos==std::string::npos) {
33 a_value = s.substr(0,dot_pos);
37 inline void path_no_suffix(
const std::string& a_string,std::string& a_value){
40 std::string::size_type dot_pos = a_string.rfind(
'.');
41 if(dot_pos==std::string::npos) {
44 a_value = a_string.substr(0,dot_pos);
48 inline bool has_dir(
const std::string& a_string){
49 if(a_string.rfind(
'/')!=std::string::npos)
return true;
50 if(a_string.rfind(
'\\')!=std::string::npos)
return true;
54 inline void base_name(
const std::string& a_path,std::string& a_value) {
55 std::string::size_type pos_slash = a_path.rfind(
'/');
56 std::string::size_type pos_bslash = a_path.rfind(
'\\');
57 std::string::size_type pos = 0;
58 if(pos_slash==std::string::npos) {
59 if(pos_bslash==std::string::npos) {
60 pos = std::string::npos;
65 if(pos_bslash==std::string::npos) {
68 if(pos_slash<=pos_bslash) {
75 if(pos==std::string::npos) {a_value = a_path;
return;}
77 a_value = a_path.substr(pos,a_path.size()-pos);
88 inline std::string
suffix(
const std::string& a_string,
bool a_back =
true) {
94 inline std::string
nosuffix(
const std::string& a_string,
bool a_back =
true){
100 inline std::string
base_name(
const std::string& a_path) {
107 if(a_path.find(
'\\')!=std::string::npos) {
108 if(a_path.find(
':')!=std::string::npos)
return true;
109 return (a_path.size()&&(a_path[0]==
'\\')?
true:
false);
111 return (a_path.size()&&(a_path[0]==
'/')?
true:
false);
115 inline bool path_name_suffix(
const std::string& a_string,std::string& a_path,std::string& a_name,std::string& a_suffix){
157 }
else if(a_string==
"..") {
164 std::string::size_type pos_slash = a_string.rfind(
'/');
165 std::string::size_type pos_bslash = a_string.rfind(
'\\');
166 std::string::size_type pos = 0;
167 if(pos_slash==std::string::npos) {
168 if(pos_bslash==std::string::npos) {
169 pos = std::string::npos;
174 if(pos_bslash==std::string::npos) {
177 if(pos_slash<=pos_bslash) {
185 if(pos==std::string::npos) {
192 a_path = a_string.substr(0,pos);
195 std::string s = a_string.substr(pos,a_string.size()-pos);
197 if(pos==std::string::npos) {
203 a_suffix = s.substr(pos,s.size()-pos);
208 inline std::string
dir_name(
const std::string& a_path,
unsigned int a_num = 1){
209 std::string path = a_path;
210 for(
unsigned int index=0;index<a_num;index++) {
218 inline void quote(std::string& a_path) {
219 if(a_path.find(
' ')==std::string::npos)
return;
221 if(a_path[0]==
'"')
return;
222 a_path = std::string(
"\"")+a_path+
"\"";
226 inline bool is_f77(
const std::string& a_path){
227 std::string sfx =
suffix(a_path);
230 for(std::string::iterator it=sfx.begin();it!=sfx.end();++it) {
232 *it = ((c) >=
'A' && (c) <=
'Z' ? c -
'A' +
'a' : c);
235 if(sfx==
"f")
return true;
236 if(sfx==
"for")
return true;
237 if(sfx==
"ftn")
return true;
238 if(sfx==
"fortran")
return true;
239 if(sfx==
"f77")
return true;
244 inline bool is_cpp(
const std::string& a_path){
245 std::string sfx =
suffix(a_path);
248 for(std::string::iterator it=sfx.begin();it!=sfx.end();++it) {
250 *it = ((c) >=
'A' && (c) <=
'Z' ? c -
'A' +
'a' : c);
253 if(sfx==
"c")
return true;
254 if(sfx==
"cxx")
return true;
255 if(sfx==
"cpp")
return true;
256 if(sfx==
"C")
return true;
262 std::string sfx =
suffix(a_path);
265 for(std::string::iterator it=sfx.begin();it!=sfx.end();++it) {
267 *it = ((c) >=
'A' && (c) <=
'Z' ? c -
'A' +
'a' : c);
270 if(sfx==
"py")
return true;
280 inline bool url_parse(
const std::string& a_url,std::string& a_host,
unsigned int& a_port,std::string& a_path) {
282 if((a_url.size()>=7)&&(a_url.substr(0,7)==
"http://")) {
283 s = a_url.substr(7,a_url.size()-7);
284 }
else if((a_url.size()>=8)&&(a_url.substr(0,8)==
"https://")) {
285 s = a_url.substr(8,a_url.size()-8);
293 {std::string::size_type pos = s.find(
'/');
294 if(pos==std::string::npos) {
298 a_host = s.substr(0,pos);
299 a_path = s.substr(pos,s.size()-pos);
302 {std::string::size_type pos = a_host.find(
':');
303 if(pos==std::string::npos) {
306 std::string sport = a_host.substr(pos+1,a_host.size()-(pos+1));
307 std::istringstream strm(sport.c_str());
315 a_host = a_host.substr(0,pos);