/[svn]/linuxsampler/trunk/src/common/Path.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/common/Path.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1338 - (hide annotations) (download)
Sun Sep 9 23:30:34 2007 UTC (16 years, 7 months ago) by schoenebeck
File size: 3004 byte(s)
* bugfix: files with percent character ('%') in their path or filename
  could not be loaded

1 schoenebeck 1332 /***************************************************************************
2     * *
3     * Copyright (C) 2007 Christian Schoenebeck *
4     * *
5     * 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 *
7     * the Free Software Foundation; either version 2 of the License, or *
8     * (at your option) any later version. *
9     * *
10     * This library is distributed in the hope that it will be useful, *
11     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13     * GNU General Public License for more details. *
14     * *
15     * You should have received a copy of the GNU General Public License *
16     * along with this library; if not, write to the Free Software *
17     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
18     * MA 02111-1307 USA *
19     ***************************************************************************/
20    
21     #include "Path.h"
22    
23     namespace LinuxSampler {
24    
25     void Path::appendNode(std::string Name) {
26     if (!Name.size()) return;
27     elements.push_back(Name);
28     }
29    
30     std::string Path::toPosix() {
31     // POSIX paths consist of forward slash separators and requires forward
32     // slashes in path and file names to be encoded as "%2f", the file names
33     // "." and ".." have special meanings
34     // (see http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_169
35     // and http://www.opengroup.org/onlinepubs/000095399/basedefs/xbd_chap03.html#tag_03_266 )
36     std::string result;
37     for (int iElement = 0; iElement < elements.size(); iElement++) {
38 schoenebeck 1338 // encode percent characters
39 schoenebeck 1332 std::string e = elements[iElement];
40     for (
41 schoenebeck 1338 int pos = e.find("%"); pos != std::string::npos;
42     pos = e.find("%", pos+2)
43     ) e.replace(pos/*offset*/, 1/*length*/, "%%"/*by*/);
44     // encode forward slashes
45     for (
46 schoenebeck 1332 int pos = e.find("/"); pos != std::string::npos;
47 schoenebeck 1338 pos = e.find("/", pos+3)
48 schoenebeck 1332 ) e.replace(pos/*offset*/, 1/*length*/, "%2f"/*by*/);
49     // append encoded node to full encoded path
50     result += "/" + e;
51     }
52     if (!result.size()) result = "/";
53     return result;
54     }
55    
56     Path Path::operator+(const Path& p) {
57     Path result = *this;
58     for (int i = 0; i < p.elements.size(); i++)
59     result.elements.push_back(p.elements[i]);
60     return result;
61     }
62    
63     Path Path::operator+(const Path* p) {
64     return *this + *p;
65     }
66    
67     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC