[llvm] [llvm][Support] fix convertToSnakeFromCamelCase (PR #68375)
Markus Böck via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 6 13:43:54 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))
----------------
zero9178 wrote:
Could you put a comment here what case this specifically covers?
>From looking at it and seeing the tests I figured it handles the `([A-Z])([A-Z][a-z])` -> `\\0_\\1` aka inserting a `_` right before the last upper case letter, but I feel like that isn't very obvious.
Potentially the same below if you feel like it.
https://github.com/llvm/llvm-project/pull/68375
More information about the llvm-commits
mailing list