Canola
0.8.D001
|
00001 // 00002 // canola - canon canola 1614p emulator 00003 // Copyright (C) 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License, version 3, as 00007 // published by the Free Software Foundation. 00008 // 00009 // This program is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License along 00015 // with this program. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 00018 #include <lib/path_join.h> 00019 00020 00021 std::string 00022 path_join(const std::string &lhs, const std::string &rhs) 00023 { 00024 if (lhs == "." || lhs.empty()) 00025 return rhs; 00026 if (rhs == "." || rhs.empty()) 00027 return lhs; 00028 if (lhs[lhs.size() - 1] == '/' || rhs[0] == '/') 00029 { 00030 if (lhs[lhs.size() - 1] == '/' && rhs[0] == '/') 00031 return lhs + rhs.substr(1, rhs.size() - 1); 00032 return (lhs + rhs); 00033 } 00034 return (lhs + "/" + rhs); 00035 } 00036 00037 00038 std::string 00039 path_join(const std::string &s1, const std::string &s2, const std::string &s3) 00040 { 00041 return path_join(path_join(s1, s2), s3); 00042 } 00043 00044 00045 std::string 00046 path_join(const std::string &s1, const std::string &s2, const std::string &s3, 00047 const std::string &s4) 00048 { 00049 return path_join(path_join(s1, s2), path_join(s3, s4)); 00050 }