8 unsigned char m4 = 128 + 64 + 32 + 16;
9 unsigned char m3 = 128 + 64 + 32;
10 unsigned char m2 = 128 + 64;
12 for (
int i = 0; i < utf8len; ++i, ++codepointLen)
18 else if ((c & m3) == m3)
20 else if ((c & m2) == m2)
29 char const wb[] =
" \t\n\r\v\f-=+*&^%$#@!,./?<>;:`~'\"[]{}()\\|";
30 int i = std::strlen(prefix) - 1;
35 if (std::strchr(wb, prefix[i]) != NULL)
45Replxx::completions_t
hook_completion(std::string
const& context,
int& contextLen, std::vector<std::string>
const& examples)
47 Replxx::completions_t completions;
49 int prefixLen = context.length() - utf8ContextLen;
51 if ((prefixLen > 0) && (context[prefixLen - 1] ==
'\\'))
59 std::string prefix = context.substr(prefixLen);
60 for (
auto const& e : examples)
62 if (e.compare(0, prefix.size(), prefix) == 0)
63 completions.emplace_back(e.c_str());
69void hook_color(std::string
const& context, Replxx::colors_t& colors, std::vector<std::pair<std::string, Replxx::Color>>
const& regex_color)
72 for (
auto const& e : regex_color)
75 std::string str = context;
78 while (std::regex_search(str, match, std::regex(e.first)))
80 std::string c = match[0];
81 std::string prefix = match.prefix().str();
85 for (
int i = 0; i < len; ++i)
86 colors.at(pos + i) = e.second;
94Replxx::hints_t
hook_hint(std::string
const& context,
int& contextLen, Replxx::Color& color, std::vector<std::string>
const& examples)
96 Replxx::hints_t hints;
100 int prefixLen = context.length() - utf8ContextLen;
102 std::string prefix = context.substr(prefixLen);
104 if (prefix.size() >= 2 || (!prefix.empty() && prefix.at(0) ==
'.'))
106 for (
auto const& e : examples)
108 if (e.compare(0, prefix.size(), prefix) == 0)
109 hints.emplace_back(e.c_str());
113 if (hints.size() == 1)
114 color = Replxx::Color::GREEN;
int utf8str_codepoint_len(char const *s, int utf8len)
Replxx::completions_t hook_completion(std::string const &context, int &contextLen, std::vector< std::string > const &examples)
Replxx::hints_t hook_hint(std::string const &context, int &contextLen, Replxx::Color &color, std::vector< std::string > const &examples)
void hook_color(std::string const &context, Replxx::colors_t &colors, std::vector< std::pair< std::string, Replxx::Color > > const ®ex_color)
int context_len(char const *prefix)