[llvm] [llvm][Support] fix convertToSnakeFromCamelCase (PR #68375)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 13:29:41 PDT 2023
================
@@ -98,16 +98,18 @@ std::string llvm::convertToSnakeFromCamelCase(StringRef input) {
std::string snakeCase;
snakeCase.reserve(input.size());
- for (char c : input) {
- if (!std::isupper(c)) {
- snakeCase.push_back(c);
- continue;
- }
-
- if (!snakeCase.empty() && snakeCase.back() != '_')
+ auto check = [&input](size_t j, std::function<bool(int)> check) {
+ return j < input.size() ? check(input[j]) : false;
+ };
+ for (size_t i = 0; i < input.size(); ++i) {
+ snakeCase.push_back(input[i]);
+ if (check(i, isupper) && check(i + 1, isupper) && check(i + 2, islower))
+ snakeCase.push_back('_');
+ if ((check(i, islower) || check(i, isdigit)) && check(i + 1, isupper))
snakeCase.push_back('_');
- snakeCase.push_back(llvm::toLower(c));
}
+ std::transform(snakeCase.begin(), snakeCase.end(), snakeCase.begin(),
+ [](unsigned char c) { return std::tolower(c); });
----------------
rkayaith wrote:
can move the `tolower` into the loop now
https://github.com/llvm/llvm-project/pull/68375
More information about the llvm-commits
mailing list