• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PredatorCZ / PreCore / 461

pending completion
461

push

github-actions-ci

PredatorCZ
update readme

3204 of 6096 relevant lines covered (52.56%)

354.05 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/include/spike/io/fileinfo.hpp
1
/*  TFileInfo class for parsing/exploding file paths
2

3
    Copyright 2015-2023 Lukas Cone
4

5
    Licensed under the Apache License, Version 2.0 (the "License");
6
    you may not use this file except in compliance with the License.
7
    You may obtain a copy of the License at
8

9
        http://www.apache.org/licenses/LICENSE-2.0
10

11
    Unless required by applicable law or agreed to in writing, software
12
    distributed under the License is distributed on an "AS IS" BASIS,
13
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
    See the License for the specific language governing permissions and
15
    limitations under the License.
16
*/
17

18
#pragma once
19
#include "spike/util/supercore.hpp"
20
#include <string>
21
#include <string_view>
22
#include <vector>
23

24
class FileInfo {
3,477✔
25
public:
26
  using T = char;
27
  typedef std::basic_string_view<T> stringref_type;
28
  typedef std::basic_string<T, std::char_traits<T>, std::allocator<T>>
29
      string_type;
30
  typedef std::vector<stringref_type> explode_type;
31

32
private:
33
  string_type fullPath;
34
  size_t endFolder;
35
  size_t lastDot;
36

37
public:
38
  FileInfo(stringref_type input) { Load(input); }
3,477✔
39
  FileInfo() noexcept = default;
40

41
  void Load(stringref_type input) {
3,482✔
42
    fullPath = input;
3,482✔
43

44
    if (!fullPath.size())
3,482✔
45
      return;
46

47
    for (auto &c : fullPath)
184,618✔
48
      if (c == '\\')
181,136✔
49
        c = '/';
8✔
50

51
    endFolder = fullPath.find_last_of('/');
3,482✔
52
    lastDot = fullPath.find_last_of('.');
3,482✔
53

54
    if (endFolder != fullPath.npos)
3,482✔
55
      endFolder++;
3,466✔
56
    else
57
      endFolder = 0;
16✔
58

59
    if (!lastDot || lastDot == fullPath.npos)
3,482✔
60
      lastDot = fullPath.size();
97✔
61
  }
62

63
  stringref_type GetFullPathNoExt() const { return {fullPath.data(), lastDot}; }
×
64
  stringref_type GetFullPath() const { return fullPath; }
65
  stringref_type GetFilenameExt() const {
66
    return {fullPath.data() + endFolder};
×
67
  }
68
  stringref_type GetFilename() const {
69
    return {fullPath.data() + endFolder, fullPath.data() + lastDot};
6✔
70
  }
71
  stringref_type GetExtension() const { return fullPath.data() + lastDot; }
6✔
72
  stringref_type GetFolder() const { return {fullPath.data(), endFolder}; }
6✔
73
  string_type ChangeExtension(stringref_type newExt) const {
74
    return string_type(GetFullPathNoExt()) + string_type(newExt);
75
  }
76
  string_type ChangeExtension2(stringref_type newExt) const {
77
    return string_type(GetFullPathNoExt()).append(".") + string_type(newExt);
78
  }
79

80
  explode_type Explode() const {
3,483✔
81
    explode_type resVal;
3,483✔
82
    const char *lastOffset = fullPath.data();
3,483✔
83
    const size_t fullSize = fullPath.size();
84
    const char *pathEnd = std::prev(fullPath.end()).operator->() + 1;
85

86
    if (*lastOffset == '/')
3,483✔
87
      lastOffset++;
5✔
88

89
    for (size_t c = 1; c < fullSize; c++)
181,189✔
90
      if (fullPath[c] == '/') {
177,706✔
91
        resVal.emplace_back(lastOffset, fullPath.data() + c);
13,787✔
92
        lastOffset = fullPath.data() + c + 1;
13,787✔
93
      }
94

95
    if (lastOffset != pathEnd)
3,483✔
96
      resVal.emplace_back(lastOffset);
3,482✔
97

98
    return resVal;
3,483✔
99
  }
100

101
  string_type CatchBranch(const stringref_type &path) const {
1✔
102
    explode_type exVec = Explode();
1✔
103
    const size_t found = path.find(exVec[0]);
104

105
    if (found == path.npos) {
1✔
106
      return string_type(path).append(GetFilenameExt());
×
107
    } else if (found == 0) {
1✔
108
      return string_type(GetFullPath());
×
109
    } else {
110
      auto nextPath = GetFullPath();
111
      size_t sub = nextPath.front() == '/';
1✔
112
      return std::string(path.substr(0, found - sub)).append(nextPath);
2✔
113
    }
114
  }
115
};
116

117
using AFileInfo = FileInfo;
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc