1 |
/*************************************************************************** |
/*************************************************************************** |
2 |
* * |
* * |
3 |
* Copyright (C) 2007-2014 Christian Schoenebeck * |
* Copyright (C) 2007-2016 Christian Schoenebeck * |
4 |
* * |
* * |
5 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
6 |
* it under the terms of the GNU General Public License as published by * |
* it under the terms of the GNU General Public License as published by * |
59 |
// encode percent characters |
// encode percent characters |
60 |
std::string e = elements[iElement]; |
std::string e = elements[iElement]; |
61 |
for ( |
for ( |
62 |
int pos = e.find("%"); pos != std::string::npos; |
int pos = (int)e.find("%"); pos != std::string::npos; |
63 |
pos = e.find("%", pos+2) |
pos = (int)e.find("%", pos+2) |
64 |
) e.replace(pos/*offset*/, 1/*length*/, "%%"/*by*/); |
) e.replace(pos/*offset*/, 1/*length*/, "%%"/*by*/); |
65 |
// encode forward slashes |
// encode forward slashes |
66 |
for ( |
for ( |
67 |
int pos = e.find("/"); pos != std::string::npos; |
int pos = (int)e.find("/"); pos != std::string::npos; |
68 |
pos = e.find("/", pos+3) |
pos = (int)e.find("/", pos+3) |
69 |
) e.replace(pos/*offset*/, 1/*length*/, "%2f"/*by*/); |
) e.replace(pos/*offset*/, 1/*length*/, "%2f"/*by*/); |
70 |
// append encoded node to full encoded path |
// append encoded node to full encoded path |
71 |
result += "/" + e; |
result += "/" + e; |
160 |
{ |
{ |
161 |
int nodeEnd; |
int nodeEnd; |
162 |
for ( |
for ( |
163 |
int nodeBegin = path.find_first_not_of('/'); |
int nodeBegin = (int)path.find_first_not_of('/'); |
164 |
nodeBegin != std::string::npos; |
nodeBegin != std::string::npos; |
165 |
nodeBegin = path.find_first_not_of('/', nodeEnd) |
nodeBegin = (int)path.find_first_not_of('/', nodeEnd) |
166 |
) { |
) { |
167 |
nodeEnd = path.find_first_of('/', nodeBegin); |
nodeEnd = (int)path.find_first_of('/', nodeBegin); |
168 |
result.appendNode( |
result.appendNode( |
169 |
(nodeEnd != std::string::npos) ? |
(nodeEnd != std::string::npos) ? |
170 |
path.substr(nodeBegin, nodeEnd - nodeBegin) : |
path.substr(nodeBegin, nodeEnd - nodeBegin) : |
175 |
// resolve POSIX escape sequences in all nodes |
// resolve POSIX escape sequences in all nodes |
176 |
for (int iNode = 0; iNode < result.elements.size(); iNode++) { |
for (int iNode = 0; iNode < result.elements.size(); iNode++) { |
177 |
std::string& s = result.elements[iNode]; |
std::string& s = result.elements[iNode]; |
178 |
for (int pos = s.find('%'); pos < s.length(); pos = s.find('%', ++pos)) { |
for (size_t pos = s.find('%'); pos < s.length(); pos = s.find('%', ++pos)) { |
179 |
if (pos+1 >= s.length()) { // unexpected character |
if (pos+1 >= s.length()) { // unexpected character |
180 |
//TODO: we might want to throw an exception here, for now we simply replace the character by '?' |
//TODO: we might want to throw an exception here, for now we simply replace the character by '?' |
181 |
s.replace(pos, 1, "?"); |
s.replace(pos, 1, "?"); |
209 |
{ |
{ |
210 |
int nodeEnd; |
int nodeEnd; |
211 |
for ( |
for ( |
212 |
int nodeBegin = path.find_first_not_of('/'); |
int nodeBegin = (int)path.find_first_not_of('/'); |
213 |
nodeBegin != std::string::npos; |
nodeBegin != std::string::npos; |
214 |
nodeBegin = path.find_first_not_of('/', nodeEnd) |
nodeBegin = (int)path.find_first_not_of('/', nodeEnd) |
215 |
) { |
) { |
216 |
nodeEnd = path.find_first_of('/', nodeBegin); |
nodeEnd = (int)path.find_first_of('/', nodeBegin); |
217 |
|
|
218 |
std::string s = (nodeEnd != std::string::npos) ? |
std::string s = (nodeEnd != std::string::npos) ? |
219 |
path.substr(nodeBegin, nodeEnd - nodeBegin) : |
path.substr(nodeBegin, nodeEnd - nodeBegin) : |
240 |
// split the nodes |
// split the nodes |
241 |
{ |
{ |
242 |
for ( |
for ( |
243 |
int nodeBegin = path.find_first_not_of('\\', nodeEnd); |
int nodeBegin = (int)path.find_first_not_of('\\', nodeEnd); |
244 |
nodeBegin != std::string::npos; |
nodeBegin != std::string::npos; |
245 |
nodeBegin = path.find_first_not_of('\\', nodeEnd) |
nodeBegin = (int)path.find_first_not_of('\\', nodeEnd) |
246 |
) { |
) { |
247 |
nodeEnd = path.find_first_of('\\', nodeBegin); |
nodeEnd = (int)path.find_first_of('\\', nodeBegin); |
248 |
result.appendNode( |
result.appendNode( |
249 |
(nodeEnd != std::string::npos) ? |
(nodeEnd != std::string::npos) ? |
250 |
path.substr(nodeBegin, nodeEnd - nodeBegin) : |
path.substr(nodeBegin, nodeEnd - nodeBegin) : |