82 |
|
|
83 |
std::string Path::toLscp() const { |
std::string Path::toLscp() const { |
84 |
std::string result; |
std::string result; |
85 |
|
#if WIN32 |
86 |
|
if(drive) { |
87 |
|
result.assign(&drive,1); |
88 |
|
result += ":"; |
89 |
|
} |
90 |
|
#endif |
91 |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
92 |
// replace "special characters" by LSCP escape sequences |
// replace "special characters" by LSCP escape sequences |
93 |
std::string e = elements[iElement]; |
std::string e = elements[iElement]; |
121 |
|
|
122 |
std::string Path::toWindows() const { |
std::string Path::toWindows() const { |
123 |
std::stringstream result; |
std::stringstream result; |
124 |
result << |
const char cDrive = |
125 |
((drive >= 'A' && drive <= 'Z') || (drive >= 'a' && drive <= 'z')) |
((drive >= 'A' && drive <= 'Z') || (drive >= 'a' && drive <= 'z')) |
126 |
? drive : '?'; |
? drive : '?'; |
127 |
|
result << cDrive; |
128 |
result << ':'; |
result << ':'; |
129 |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
for (int iElement = 0; iElement < elements.size(); iElement++) { |
130 |
// append encoded node to full encoded path |
// append encoded node to full encoded path |
131 |
result << "\\" << elements[iElement]; |
result << "\\" << elements[iElement]; |
132 |
} |
} |
133 |
|
if (elements.empty()) result << '\\'; |
134 |
return result.str(); |
return result.str(); |
135 |
} |
} |
136 |
|
|
214 |
return result; |
return result; |
215 |
} |
} |
216 |
|
|
217 |
Path Path::fromWindowsPath(std::string path) { |
Path Path::fromWindows(std::string path) { |
218 |
Path result; |
Path result; |
219 |
|
|
220 |
int nodeEnd = 0; |
int nodeEnd = 0; |
244 |
return result; |
return result; |
245 |
} |
} |
246 |
|
|
247 |
|
std::string Path::getName(std::string path) { |
248 |
|
Path p; |
249 |
|
#if WIN32 |
250 |
|
p.fromWindows(path); |
251 |
|
#else |
252 |
|
p.fromPosix(path); |
253 |
|
#endif |
254 |
|
|
255 |
|
return p.getName(); |
256 |
|
} |
257 |
|
|
258 |
|
std::string Path::getName() { |
259 |
|
if(elements.empty()) return ""; |
260 |
|
return elements[elements.size() - 1]; |
261 |
|
} |
262 |
|
|
263 |
|
std::string Path::getBaseName(std::string path) { |
264 |
|
Path p; |
265 |
|
#if WIN32 |
266 |
|
p = fromWindows(path); |
267 |
|
#else |
268 |
|
p = fromPosix(path); |
269 |
|
#endif |
270 |
|
|
271 |
|
return p.getBaseName(); |
272 |
|
} |
273 |
|
|
274 |
|
std::string Path::getBaseName() { |
275 |
|
std::string name = getName(); |
276 |
|
size_t lastdot = name.find_last_of('.'); |
277 |
|
if(lastdot == std::string::npos) return name; |
278 |
|
return name.substr(0, lastdot); |
279 |
|
} |
280 |
|
|
281 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |