Skip to content

Commit

Permalink
Merge pull request #1644 from contour-terminal/improvement/camel_to_s…
Browse files Browse the repository at this point in the history
…nake

Transform camelCase into snake_case for docs
  • Loading branch information
Yaraslaut authored Oct 26, 2024
2 parents 100902d + 160b0c4 commit 3f86c65
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions src/contour/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -1382,10 +1382,23 @@ struct DocumentationWriter: Writer
template <typename... T>
std::string process(std::string_view doc, std::string_view name, T... val)
{
return format("### `{}`\n"
"{}\n",
name,
format(replaceCommentPlaceholder(std::string { doc }), val...));
return format(
"### `{}`\n"
"{}\n",
[](std::string_view name) -> std::string {
// camelCase into snake_case
auto result = std::string { name };
for (auto i = 0u; i < result.size(); ++i)
{
if (std::isupper(result[i]))
{
result.insert(i, 1, '_');
result[i + 1] = static_cast<char>(std::tolower(result[i + 1]));
}
}
return result;
}(name),
format(replaceCommentPlaceholder(std::string { doc }), val...));
}

template <typename T, documentation::StringLiteral ConfigDoc, documentation::StringLiteral WebDoc>
Expand Down

0 comments on commit 3f86c65

Please sign in to comment.