Skip to content

Commit

Permalink
improve code to remove namespace
Browse files Browse the repository at this point in the history
  • Loading branch information
philip82148 committed Sep 25, 2024
1 parent c1e2e4d commit d4f692e
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions cpp-dump/hpp/class_name.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,29 +85,30 @@ inline std::string styled_classname_str(std::string_view type_name) {
}

if (options::classname_style & flags::classname_style::no_namespace) {
std::string no_ns;

std::reverse(styled.begin(), styled.end());
for (std::size_t i = 0; i < styled.size(); ++i) {
if (styled[i] != ':') {
// append class name
no_ns.push_back(styled[i]);
continue;
}

// skip namespace
auto get_namespace_end = [&](std::size_t begin) {
int gt_count = 0;
for (++i; i < styled.size(); ++i) {
if (styled[i] == '>') {

std::size_t end;
for (end = begin + 1; end < styled.size(); ++end) {
if (styled[end] == '>') {
++gt_count;
} else if (styled[i] == '<') {
} else if (styled[end] == '<') {
--gt_count;
if (gt_count < 0) {
no_ns.push_back(styled[i]);
break;
}
if (gt_count < 0) break;
}
}

return end;
};

std::string no_ns;
std::reverse(styled.begin(), styled.end());
for (std::size_t i = 0; i < styled.size(); ++i) {
if (styled[i] == ':') {
i = get_namespace_end(i) - 1;
} else {
no_ns.push_back(styled[i]);
}
}
std::reverse(no_ns.begin(), no_ns.end());

Expand Down

0 comments on commit d4f692e

Please sign in to comment.