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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1332 - (show annotations) (download)
Sun Sep 9 12:22:34 2007 UTC (13 years, 2 months ago) by schoenebeck
File size: 2794 byte(s)
* bugfix: files with slash in their path or filename could not be loaded

1 /***************************************************************************
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 // encode forward slashes
39 std::string e = elements[iElement];
40 for (
41 int pos = e.find("/"); pos != std::string::npos;
42 pos = e.find("/", pos+1)
43 ) e.replace(pos/*offset*/, 1/*length*/, "%2f"/*by*/);
44 // append encoded node to full encoded path
45 result += "/" + e;
46 }
47 if (!result.size()) result = "/";
48 return result;
49 }
50
51 Path Path::operator+(const Path& p) {
52 Path result = *this;
53 for (int i = 0; i < p.elements.size(); i++)
54 result.elements.push_back(p.elements[i]);
55 return result;
56 }
57
58 Path Path::operator+(const Path* p) {
59 return *this + *p;
60 }
61
62 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC