Skip to content

Commit 3f86c65

Browse files
authored
Merge pull request #1644 from contour-terminal/improvement/camel_to_snake
Transform camelCase into snake_case for docs
2 parents 100902d + 160b0c4 commit 3f86c65

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/contour/Config.h

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,10 +1382,23 @@ struct DocumentationWriter: Writer
13821382
template <typename... T>
13831383
std::string process(std::string_view doc, std::string_view name, T... val)
13841384
{
1385-
return format("### `{}`\n"
1386-
"{}\n",
1387-
name,
1388-
format(replaceCommentPlaceholder(std::string { doc }), val...));
1385+
return format(
1386+
"### `{}`\n"
1387+
"{}\n",
1388+
[](std::string_view name) -> std::string {
1389+
// camelCase into snake_case
1390+
auto result = std::string { name };
1391+
for (auto i = 0u; i < result.size(); ++i)
1392+
{
1393+
if (std::isupper(result[i]))
1394+
{
1395+
result.insert(i, 1, '_');
1396+
result[i + 1] = static_cast<char>(std::tolower(result[i + 1]));
1397+
}
1398+
}
1399+
return result;
1400+
}(name),
1401+
format(replaceCommentPlaceholder(std::string { doc }), val...));
13891402
}
13901403

13911404
template <typename T, documentation::StringLiteral ConfigDoc, documentation::StringLiteral WebDoc>

0 commit comments

Comments
 (0)