-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringing.h
More file actions
44 lines (33 loc) · 862 Bytes
/
stringing.h
File metadata and controls
44 lines (33 loc) · 862 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// Created by Vova on 14.10.2020.
//
#pragma once
#include <string>
inline constexpr unsigned long long get_last_slash_index(const char* const string) {
size_t res { 0 };
const char * str_pnt = string;
size_t index { 0 };
while(*str_pnt) {
if (*str_pnt == '\\' || *str_pnt == '/') {
res = index;
}
str_pnt++;
index++;
}
return res;
}
inline std::string get_path_folder(const char* child_filename) {
/// D:/data/file.txt -> D:/data/
/// D:\data\file.txt -> D:\data\
// size_t last_slash_index = get_last_slash_index(child_filename);
std::string res = child_filename;
res.erase(res.begin() + res.find_last_of("\\/"), res.end());
return res;
}
inline fs::path safe_get_parent(const fs::path& child) {
auto res = child.parent_path();
if (std::string{res.string().back()} == "."s) {
res = res.parent_path();
}
return res;
}