Changeset 9:55a205745993 in rrlib_uri


Ignore:
Timestamp:
09.08.2019 10:40:57 (21 months ago)
Author:
Max Reichardt <max.reichardt@…>
Branch:
17.03
Children:
10:9a77f95a1bad, 11:8865b9eb5efe
Phase:
public
Message:

Adds function to remove dot segments in paths

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • tPath.cpp

    r5 r9  
    109109} 
    110110 
     111size_t tPath::RemoveDotSegments() 
     112{ 
     113  std::vector<tStringRange> elements; 
     114  size_t result = 0; 
     115  for (auto it = this->Begin(); it != this->End(); ++it) 
     116  { 
     117    if (it->Length() == 1 && it->CharPointer()[0] == '.') 
     118    { 
     119      continue; // skip 
     120    } 
     121    else if (it->Length() == 2 && it->CharPointer()[0] == '.' && it->CharPointer()[1] == '.') 
     122    { 
     123      if (elements.size()) 
     124      { 
     125        elements.pop_back(); 
     126      } 
     127      else if (!IsAbsolute()) 
     128      { 
     129        result++; 
     130      } 
     131      continue; 
     132    } 
     133    elements.push_back(*it); 
     134  } 
     135  (*this) = tPath(IsAbsolute(), elements.begin(), elements.end()); 
     136  return result; 
     137} 
     138 
    111139void tPath::Set(const tStringRange& path_string, char separator) 
    112140{ 
  • tPath.h

    r4 r9  
    109109   * Constructs path from iterator over string elements - e.g. 
    110110   *   tPath(string_vector.begin(), string_vector.end()) 
    111    * String elements can either be std::string or const char*. 
     111   * String elements can be std::string, const char*, or tStringRange. 
    112112   * 
    113113   * \param absolute Whether this is an abolute path 
     
    194194    return tPath(false, Begin(), End()); 
    195195  } 
     196 
     197  /*! 
     198   * Removes dot segments ('/./' and '/../') in this path. 
     199   * (as e.g. described in RFC 3986 section 5.2.4 for URIs) 
     200   * 
     201   * \return Number of '..' elements beyond top-level for relative paths (e.g. if path starts with "../../" this would be 2). For absolute paths always returns zero. 
     202   */ 
     203  size_t RemoveDotSegments(); 
    196204 
    197205  /*! 
Note: See TracChangeset for help on using the changeset viewer.