16 InterpreterOutput* Completer::output =
nullptr;
33 static bool formatHelper(
const vector<string_ref>& input,
size_t columnLimit,
34 vector<string>& result)
37 auto it = input.begin();
39 size_t maxcolumn = column;
40 for (
size_t i = 0; (i < result.size()) && (it != input.end());
43 result[i] += string(column - curSize,
' ');
44 result[i] += it->str();
45 maxcolumn = std::max(maxcolumn,
47 if (maxcolumn > columnLimit)
return false;
49 column = maxcolumn + 2;
50 }
while (it != input.end());
54 static vector<string> format(
const vector<string_ref>& input,
size_t columnLimit)
56 vector<string> result;
57 for (
size_t lines = 1; lines < input.size(); ++lines) {
58 result.assign(lines,
string());
59 if (formatHelper(input, columnLimit, result)) {
63 for (
auto& s : input) {
64 result.push_back(s.str());
71 if (s2.
size() < s1.
size())
return false;
75 return strncasecmp(s1.
data(), s2.
data(), s1.
size()) == 0;
79 bool Completer::completeImpl(
string& str, vector<string_ref> matches,
82 for (
auto& m : matches) {
83 assert(equalHead(str, m, caseSensitive)); (void)m;
86 if (matches.empty()) {
90 if (matches.size() == 1) {
92 str = matches.front().str();
101 sort(matches.begin(), matches.end());
102 matches.erase(unique(matches.begin(), matches.end()), matches.end());
104 bool expanded =
false;
106 auto it = matches.begin();
107 if (str.size() == it->size()) {
112 auto begin = it->begin();
113 auto end = begin + str.size();
116 for (; it != matches.end(); ++it) {
117 if (!equalHead(string2, *it, caseSensitive)) {
126 if (!expanded && output) {
138 completeFileNameImpl(tokens, context, vector<string_ref>());
141 void Completer::completeFileNameImpl(vector<string>& tokens,
143 vector<string_ref> matches)
145 string& filename = tokens.back();
150 vector<string> paths;
157 vector<string> filenames;
158 for (
auto& p : paths) {
161 while (dirent* de = dir.getEntry()) {
169 if (equalHead(filename, nm,
true)) {
170 filenames.push_back(nm);
175 for (
auto& f : filenames) {
176 matches.push_back(f);
178 bool t = completeImpl(filename, matches,
true);
179 if (t && !filename.empty() && (filename.back() !=
'/')) {
181 tokens.push_back(
"");