| 233 | } |
| 234 | |
| 235 | void keywordCompletion(std::string buf, std::string prefix, std::string keyword, |
| 236 | linenoiseCompletions* lc) { |
| 237 | std::string bufEscaped = regex_replace(buf, specialChars, R"(\$&)"); |
| 238 | if (regex_search(keyword, std::regex("^" + bufEscaped, std::regex_constants::icase))) { |
| 239 | std::string transformedKeyword = keyword; |
| 240 | for (size_t i = 0; i < buf.size() && i < keyword.size(); ++i) { |
| 241 | if (islower(buf[i])) { |
| 242 | transformedKeyword[i] = tolower(keyword[i]); |
| 243 | } else if (isupper(buf[i])) { |
| 244 | transformedKeyword[i] = toupper(keyword[i]); |
| 245 | } |
| 246 | } |
| 247 | // make the rest of the keyword the same case as the last character of buf |
| 248 | auto caseTransform = islower(buf.back()) ? ::tolower : ::toupper; |
| 249 | std::transform(keyword.begin() + buf.size(), keyword.end(), |
| 250 | transformedKeyword.begin() + buf.size(), caseTransform); |
| 251 | |
| 252 | linenoiseAddCompletion(lc, (prefix + transformedKeyword).c_str()); |
| 253 | } |
| 254 | } |
| 255 | |
| 256 | void completion(const char* buffer, linenoiseCompletions* lc) { |
| 257 | std::string buf = std::string(buffer); |
no test coverage detected