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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 3081 by schoenebeck, Thu Dec 15 12:47:45 2016 UTC revision 3082 by schoenebeck, Mon Jan 9 18:39:35 2017 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2007-2016 Christian Schoenebeck                         *   *   Copyright (C) 2007-2017 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  *
# Line 48  void Path::setDrive(const char& Drive) { Line 48  void Path::setDrive(const char& Drive) {
48      absolute = true;      absolute = true;
49  }  }
50    
51    std::string Path::toNativeFSPath() const {
52        #if WIN32
53        return toWindows();
54        #else
55        return toPosix();
56        #endif
57    }
58    
59  std::string Path::toPosix() const {  std::string Path::toPosix() const {
60      // POSIX paths consist of forward slash separators and requires forward      // POSIX paths consist of forward slash separators and requires forward
61      // slashes in path and file names to be encoded as "%2f", the file names      // slashes in path and file names to be encoded as "%2f", the file names
# Line 154  Path Path::operator+(const Path* p) { Line 162  Path Path::operator+(const Path* p) {
162      return *this + *p;      return *this + *p;
163  }  }
164    
165    Path Path::fromUnknownFS(std::string path) {
166        bool hasDrive = false;
167        int nSlash = 0, nBackSlash = 0;
168    
169        if (path.length() >= 2)
170            hasDrive = (path[1] == ':');
171    
172        for (size_t i = 0; i < path.size(); ++i) {
173            if (path[i] == '/')  nSlash++;
174            if (path[i] == '\\') nBackSlash++;
175        }
176    
177        if (!hasDrive && nSlash > nBackSlash)
178            return Path::fromPosix(path);
179        else if (hasDrive || nBackSlash > nSlash)
180            return Path::fromWindows(path);
181        else
182            return Path(path); // expect local file system encoding
183    }
184    
185  Path Path::fromPosix(std::string path) {  Path Path::fromPosix(std::string path) {
186      Path result;      Path result;
187      // first split the nodes      // first split the nodes
# Line 271  std::string Path::getName(std::string pa Line 299  std::string Path::getName(std::string pa
299      return p.getName();      return p.getName();
300  }  }
301    
302  std::string Path::getName() {  std::string Path::getName() const {
303      if(elements.empty()) return "";      if(elements.empty()) return "";
304      return elements[elements.size() - 1];      return elements[elements.size() - 1];
305  }  }
# Line 287  std::string Path::getBaseName(std::strin Line 315  std::string Path::getBaseName(std::strin
315      return p.getBaseName();      return p.getBaseName();
316  }  }
317    
318  std::string Path::getBaseName() {  std::string Path::getBaseName() const {
319      std::string name = getName();      std::string name = getName();
320      size_t lastdot = name.find_last_of('.');      size_t lastdot = name.find_last_of('.');
321      if(lastdot == std::string::npos) return name;      if(lastdot == std::string::npos) return name;
# Line 298  std::string Path::stripLastName() { Line 326  std::string Path::stripLastName() {
326      if (elements.size() > 0) elements.pop_back();      if (elements.size() > 0) elements.pop_back();
327      #if WIN32      #if WIN32
328      return toWindows();      return toWindows();
329      #endif      #else
   
330      return toPosix();      return toPosix();
331        #endif
332  }  }
333    
334  std::string Path::stripLastName(std::string path) {  std::string Path::stripLastName(std::string path) {

Legend:
Removed from v.3081  
changed lines
  Added in v.3082

  ViewVC Help
Powered by ViewVC