MCPcopy Create free account
hub / github.com/LadybugDB/ladybug / keywordCompletion

Function keywordCompletion

tools/shell/embedded_shell.cpp:235–254  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

233}
234
235void 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
256void completion(const char* buffer, linenoiseCompletions* lc) {
257 std::string buf = std::string(buffer);

Callers 1

completionFunction · 0.85

Calls 4

linenoiseAddCompletionFunction · 0.85
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected