GCC Code Coverage Report


Directory: cvmfs/
File: cvmfs/shortstring.cc
Date: 2024-04-28 02:33:07
Exec Total Coverage
Lines: 20 20 100.0%
Branches: 13 14 92.9%

Line Branch Exec Source
1 /**
2 * This file is part of the CernVM File System.
3 *
4 * Some common functions.
5 */
6
7
8 #include "cvmfs_config.h"
9 #include "shortstring.h"
10
11 #ifdef CVMFS_NAMESPACE_GUARD
12 namespace CVMFS_NAMESPACE_GUARD {
13 #endif
14
15 1035 PathString GetParentPath(const PathString &path) {
16 1035 int length = static_cast<int>(path.GetLength());
17
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1034 times.
1035 if (length == 0)
18 1 return path;
19 1034 const char *chars = path.GetChars();
20
21
2/2
✓ Branch 0 taken 4070 times.
✓ Branch 1 taken 1 times.
4071 for (int i = length-1; i >= 0; --i) {
22
2/2
✓ Branch 0 taken 1033 times.
✓ Branch 1 taken 3037 times.
4070 if (chars[i] == '/')
23 1033 return PathString(chars, i);
24 }
25
26 1 return path;
27 }
28
29 4 NameString GetFileName(const PathString &path) {
30 4 NameString name;
31 4 int length = static_cast<int>(path.GetLength());
32 4 const char *chars = path.GetChars();
33
34 int i;
35
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 1 times.
17 for (i = length-1; i >= 0; --i) {
36
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 13 times.
16 if (chars[i] == '/')
37 3 break;
38 }
39 4 i++;
40
2/2
✓ Branch 0 taken 3 times.
✓ Branch 1 taken 1 times.
4 if (i < length) {
41
1/2
✓ Branch 1 taken 3 times.
✗ Branch 2 not taken.
3 name.Append(chars+i, length-i);
42 }
43
44 4 return name;
45 }
46
47 #ifdef CVMFS_NAMESPACE_GUARD
48 } // namespace CVMFS_NAMESPACE_GUARD
49 #endif
50