9 return std::ranges::count(line, open) - std::ranges::count(line, close);
14 const std::size_t string_begin = line.find_first_not_of(
" \t");
15 if (std::string::npos != string_begin)
17 const std::size_t string_end = line.find_last_not_of(
" \t");
18 line = line.substr(string_begin, string_end - string_begin + 1);
25 for (
const auto c : str)
26 len += (c & 0xc0) != 0x80;
32 const std::string word_break =
" \t\n\r\v\f=+*&^%$#@!,./?<>;`~'\"[]{}()\\|";
33 int i = prefix.size() - 1;
34 std::size_t count = 0;
38 if (word_break.find(prefix[i]) != std::string::npos)
48 replxx::Replxx::completions_t
hookCompletion(
const std::string& context,
int& length)
50 replxx::Replxx::completions_t completions;
51 std::size_t utf8_context_len =
contextLen(context);
52 std::size_t prefix_len = context.size() - utf8_context_len;
54 if (prefix_len > 0 && context[prefix_len - 1] ==
'\\')
60 length =
static_cast<int>(
codepointLength(context.substr(prefix_len, utf8_context_len)));
62 const std::string prefix = context.substr(prefix_len);
65 if (e.starts_with(prefix) == 0)
66 completions.emplace_back(e.c_str());
72 void hookColor(
const std::string& context, replxx::Replxx::colors_t& colors)
78 std::string str = context;
81 while (std::regex_search(str, match, std::regex(regex)))
83 std::string c = match[0];
84 std::string prefix = match.prefix().str();
88 for (std::size_t i = 0; i < len; ++i)
89 colors.at(pos + i) = color;
97 replxx::Replxx::hints_t
hookHint(
const std::string& context,
int& length, replxx::Replxx::Color& color)
99 replxx::Replxx::hints_t hints;
102 const std::size_t utf8_context_len =
contextLen(context);
103 const std::size_t prefix_len = context.size() - utf8_context_len;
104 length =
static_cast<int>(
codepointLength(context.substr(prefix_len, utf8_context_len)));
105 const std::string prefix = context.substr(prefix_len);
107 if (prefix.size() >= 2 || (!prefix.empty() && prefix.at(0) ==
'.'))
111 if (e.compare(0, prefix.size(), prefix) == 0)
112 hints.emplace_back(e.c_str());
116 if (hints.size() == 1)
117 color = replxx::Replxx::Color::GREEN;
std::size_t codepointLength(const std::string &str)
const std::vector< std::string > KeywordsDict
std::size_t contextLen(const std::string &prefix)
long countOpenEnclosures(const std::string &line, char open, char close)
Count the open enclosure and its counterpart: (), {}, [].
replxx::Replxx::hints_t hookHint(const std::string &context, int &length, replxx::Replxx::Color &color)
void hookColor(const std::string &context, replxx::Replxx::colors_t &colors)
replxx::Replxx::completions_t hookCompletion(const std::string &context, int &length)
void trimWhitespace(std::string &line)
Remove whitespaces at the start and end of a string.
const std::vector< std::pair< std::string, replxx::Replxx::Color > > ColorsRegexDict