23 |
// for function hexsToNumber() |
// for function hexsToNumber() |
24 |
#include "global_private.h" |
#include "global_private.h" |
25 |
|
|
26 |
|
#include <sstream> |
27 |
|
|
28 |
namespace LinuxSampler { |
namespace LinuxSampler { |
29 |
|
|
30 |
|
Path::Path() : drive(0) { |
31 |
|
} |
32 |
|
|
33 |
void Path::appendNode(std::string Name) { |
void Path::appendNode(std::string Name) { |
34 |
if (!Name.size()) return; |
if (!Name.size()) return; |
35 |
elements.push_back(Name); |
elements.push_back(Name); |
36 |
} |
} |
37 |
|
|
38 |
std::string Path::toPosix() { |
void Path::setDrive(const char& Drive) { |
39 |
|
drive = Drive; |
40 |
|
} |
41 |
|
|
42 |
|
std::string Path::toPosix() const { |
43 |
// POSIX paths consist of forward slash separators and requires forward |
// POSIX paths consist of forward slash separators and requires forward |
44 |
// slashes in path and file names to be encoded as "%2f", the file names |
// slashes in path and file names to be encoded as "%2f", the file names |
45 |
// "." and ".." have special meanings |
// "." and ".." have special meanings |
65 |
return result; |
return result; |
66 |
} |
} |
67 |
|
|
68 |
std::string Path::toDbPath() { |
std::string Path::toDbPath() const { |
69 |
std::string result; |
std::string result; |
70 |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
71 |
// replace all slashes with '\0' |
// replace all slashes with '\0' |
80 |
return result; |
return result; |
81 |
} |
} |
82 |
|
|
83 |
std::string Path::toLscp() { |
std::string Path::toLscp() const { |
84 |
std::string result; |
std::string result; |
85 |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
86 |
// replace "special characters" by LSCP escape sequences |
// replace "special characters" by LSCP escape sequences |
113 |
return result; |
return result; |
114 |
} |
} |
115 |
|
|
116 |
|
std::string Path::toWindows() const { |
117 |
|
std::stringstream result; |
118 |
|
result << |
119 |
|
((drive >= 'A' && drive <= 'Z') || (drive >= 'a' && drive <= 'z')) |
120 |
|
? drive : '?'; |
121 |
|
result << ':'; |
122 |
|
for (int iElement = 0; iElement < elements.size(); iElement++) { |
123 |
|
// append encoded node to full encoded path |
124 |
|
result << "\\" << elements[iElement]; |
125 |
|
} |
126 |
|
return result.str(); |
127 |
|
} |
128 |
|
|
129 |
Path Path::operator+(const Path& p) { |
Path Path::operator+(const Path& p) { |
130 |
Path result = *this; |
Path result = *this; |
131 |
for (int i = 0; i < p.elements.size(); i++) |
for (int i = 0; i < p.elements.size(); i++) |
206 |
return result; |
return result; |
207 |
} |
} |
208 |
|
|
209 |
|
Path Path::fromWindowsPath(std::string path) { |
210 |
|
Path result; |
211 |
|
|
212 |
|
int nodeEnd = 0; |
213 |
|
|
214 |
|
// first retrieve drive |
215 |
|
if (path.size() >= 2 && path.c_str()[1] == ':') { |
216 |
|
result.setDrive(path.c_str()[0]); |
217 |
|
nodeEnd = 2; |
218 |
|
} |
219 |
|
|
220 |
|
// split the nodes |
221 |
|
{ |
222 |
|
for ( |
223 |
|
int nodeBegin = path.find_first_not_of('\\', nodeEnd); |
224 |
|
nodeBegin != std::string::npos; |
225 |
|
nodeBegin = path.find_first_not_of('\\', nodeEnd) |
226 |
|
) { |
227 |
|
nodeEnd = path.find_first_of('\\', nodeBegin); |
228 |
|
result.appendNode( |
229 |
|
(nodeEnd != std::string::npos) ? |
230 |
|
path.substr(nodeBegin, nodeEnd - nodeBegin) : |
231 |
|
path.substr(nodeBegin) |
232 |
|
); |
233 |
|
} |
234 |
|
} |
235 |
|
|
236 |
|
return result; |
237 |
|
} |
238 |
|
|
239 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |