CernVM-FS  2.13.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
shortstring.cc
Go to the documentation of this file.
1 
8 #include "shortstring.h"
9 
10 #ifdef CVMFS_NAMESPACE_GUARD
11 namespace CVMFS_NAMESPACE_GUARD {
12 #endif
13 
15  const int length = static_cast<int>(path.GetLength());
16  if (length == 0)
17  return path;
18  const char *chars = path.GetChars();
19 
20  for (int i = length - 1; i >= 0; --i) {
21  if (chars[i] == '/')
22  return PathString(chars, i);
23  }
24 
25  return path;
26 }
27 
29  NameString name;
30  const int length = static_cast<int>(path.GetLength());
31  const char *chars = path.GetChars();
32 
33  int i;
34  for (i = length - 1; i >= 0; --i) {
35  if (chars[i] == '/')
36  break;
37  }
38  i++;
39  if (i < length) {
40  name.Append(chars + i, length - i);
41  }
42 
43  return name;
44 }
45 
46 
47 bool IsSubPath(const PathString& parent, const PathString& path) {
48  // If parent is "", then any path is a subpath
49  if (parent.GetLength() == 0) {
50  return true;
51  }
52 
53  // If the parent string is the prefix of the path string and either
54  // the strings are identical or the separator character is a "/",
55  // then the path is a subpath
56  if (path.StartsWith(parent) &&
57  ((path.GetLength() == parent.GetLength()) ||
58  (path.GetChars()[parent.GetLength()] == '/') ||
59  (path.GetChars()[parent.GetLength() - 1] == '/'))) {
60  return true;
61  }
62 
63  return false;
64 }
65 
66 #ifdef CVMFS_NAMESPACE_GUARD
67 } // namespace CVMFS_NAMESPACE_GUARD
68 #endif
bool IsSubPath(const PathString &parent, const PathString &path)
Definition: shortstring.cc:47
NameString GetFileName(const PathString &path)
Definition: shortstring.cc:28
void Append(const char *chars, const unsigned length)
Definition: shortstring.h:80
ShortString< kDefaultMaxPath, 0 > PathString
Definition: shortstring.h:213
PathString GetParentPath(const PathString &path)
Definition: shortstring.cc:14
bool StartsWith(const ShortString &other) const
Definition: shortstring.h:185
unsigned GetLength() const
Definition: shortstring.h:131
const char * GetChars() const
Definition: shortstring.h:123