Skip to content

Commit fc46ac3

Browse files
committed
fix: improve enum prettify
1 parent 1196475 commit fc46ac3

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

include/plg/enum.hpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,16 @@ namespace plg {
2828
std::array<char, N + 1> content_{};
2929
};
3030

31-
constexpr auto is_pretty(char ch) noexcept {
32-
return (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
33-
}
34-
3531
constexpr auto pretty_name(std::string_view sv) noexcept {
36-
for (std::size_t n = sv.size() - 1; n > 0; --n) {
37-
if (!is_pretty(sv[n])) {
38-
sv.remove_prefix(n + 1);
39-
break;
40-
}
32+
// Find last non-pretty character from the end
33+
auto pos = sv.find_last_not_of(
34+
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_"
35+
);
36+
37+
if (pos != std::string_view::npos) {
38+
sv.remove_prefix(pos + 1);
4139
}
40+
4241
return sv;
4342
}
4443

0 commit comments

Comments
 (0)