/[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 1345 - (hide annotations) (download)
Thu Sep 13 21:46:25 2007 UTC (16 years, 6 months ago) by iliev
File size: 3463 byte(s)
* added support for escape sequences to the instruments database

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 iliev 1345 std::string Path::toDbPath() {
57     std::string result;
58     for (int iElement = 0; iElement < elements.size(); iElement++) {
59     // replace all slashes with '\0'
60     std::string e = elements[iElement];
61     for (int i = 0; i < e.length(); i++) {
62     if (e.at(i) == '/') e.at(i) = '\0';
63     }
64     // append encoded node to full encoded path
65     result += "/" + e;
66     }
67     if (!result.size()) result = "/";
68     return result;
69     }
70    
71 schoenebeck 1332 Path Path::operator+(const Path& p) {
72     Path result = *this;
73     for (int i = 0; i < p.elements.size(); i++)
74     result.elements.push_back(p.elements[i]);
75     return result;
76     }
77    
78     Path Path::operator+(const Path* p) {
79     return *this + *p;
80     }
81    
82     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC