-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprojectcore.cpp
More file actions
45 lines (35 loc) · 1.02 KB
/
Copy pathprojectcore.cpp
File metadata and controls
45 lines (35 loc) · 1.02 KB
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
45
#include "projectcore.h"
#include <algorithm>
#include <cctype>
#include <ranges>
namespace frame {
namespace {
[[nodiscard]] bool isSpace(const unsigned char ch)
{
return std::isspace(ch) != 0;
}
} // namespace
std::string trimCopy(std::string_view text)
{
const auto first = std::ranges::find_if_not(
text, [](const char ch) { return isSpace(static_cast<unsigned char>(ch)); });
const auto last = std::ranges::find_if_not(std::views::reverse(text), [](const char ch) {
return isSpace(static_cast<unsigned char>(ch));
}).base();
if (first >= last) {
return {};
}
return {first, last};
}
std::string normalizedProjectName(std::string_view rawName)
{
std::string value = trimCopy(rawName);
std::ranges::transform(value, value.begin(), [](const unsigned char ch) {
if (std::isspace(ch) != 0) {
return '_';
}
return static_cast<char>(std::tolower(ch));
});
return value;
}
} // namespace frame