18using std::string_view;
22static bool formatHelper(std::span<const string_view> input,
size_t columnLimit,
23 vector<string>& result)
26 auto it =
begin(input);
28 size_t maxColumn = column;
29 for (
size_t i = 0; (i < result.size()) && (it !=
end(input));
35 if (maxColumn > columnLimit)
return false;
37 column = maxColumn + 2;
38 }
while (it !=
end(input));
42static vector<string> format(std::span<const string_view> input,
size_t columnLimit)
44 vector<string> result;
45 for (
auto lines :
xrange(1u, input.size())) {
46 result.assign(lines,
string());
47 if (formatHelper(input, columnLimit, result)) {
60bool Completer::equalHead(string_view s1, string_view s2,
bool caseSensitive)
62 if (s2.size() < s1.size())
return false;
66 return strncasecmp(s1.data(), s2.data(), s1.size()) == 0;
70bool Completer::completeImpl(
string& str, vector<string_view>
matches,
74 return equalHead(str, m, caseSensitive);
95 bool expanded =
false;
98 if (str.size() == it->size()) {
104 auto e = b + str.size();
106 string_view string2(&*b,
e - b);
108 if (!equalHead(string2, *it, caseSensitive)) {
117 if (!expanded && output) {
129 completeFileNameImpl(tokens,
context, vector<string_view>());
132void Completer::completeFileNameImpl(vector<string>& tokens,
136 string& filename = tokens.back();
141 std::span<const string> paths;
143 static const std::array<std::string, 1> EMPTY = {
""};
149 vector<string> filenames;
150 for (
const auto& p : paths) {
151 auto pLen = p.size();
152 if (!p.empty() && (p.back() !=
'/')) ++pLen;
153 auto fileAction = [&](
const string& path) {
156 if (equalHead(filename, nm,
true)) {
157 filenames.push_back(nm);
160 auto dirAction = [&](
string& path) {
167 fileAction, dirAction);
170 bool t = completeImpl(filename,
matches,
true);
171 if (
t && !filename.empty() && (filename.back() !=
'/')) {
173 tokens.emplace_back();
194 if (tokens.size() == exactly)
return;
200 if (tokens.size() >= atLeast.
min)
return;
206 if (tokens.size() >= between.
min && tokens.size() <= between.
max)
return;
static void completeFileName(std::vector< std::string > &tokens, const FileContext &context, const RANGE &extra)
static std::vector< std::string > formatListInColumns(std::span< const std::string_view > input)
virtual Interpreter & getInterpreter() const =0
void checkNumArgs(std::span< const TclObject > tokens, unsigned exactly, const char *errMessage) const
virtual unsigned getOutputColumns() const =0
virtual void output(std::string_view text)=0
void wrongNumArgs(unsigned argc, std::span< const TclObject > tokens, const char *message)
std::optional< Context > context
constexpr vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
string expandTilde(string path)
Expand the '~' character to the users home directory.
string_view getDirName(string_view path)
Returns the directory portion of a path.
const std::string & expandCurrentDirFromDrive(const std::string &path)
Get the current directory of the specified drive Linux: return the given string unchanged.
bool isAbsolutePath(string_view path)
Checks whether it's a absolute path or not.
const std::string & getConventionalPath(const std::string &path)
Returns the path in conventional path-delimiter.
string join(string_view part1, string_view part2)
Join two paths.
This file implemented 3 utility functions:
bool matches(const Event &self, const Event &other)
Does this event 'match' the given event.
bool foreach_file_and_directory(std::string path, FileAction fileAction, DirAction dirAction)
auto unique(ForwardRange &&range)
bool all_of(InputRange &&range, UnaryPredicate pred)
bool equal(InputRange1 &&range1, InputRange2 &&range2, Pred pred={}, Proj1 proj1={}, Proj2 proj2={})
constexpr void sort(RandomAccessRange &&range)
size_t size(std::string_view utf8)
uint32_t next(octet_iterator &it)
constexpr auto subspan(Range &&range, size_t offset, size_t count=std::dynamic_extent)
strCatImpl::ConcatSpaces spaces(size_t n)
void strAppend(std::string &result, Ts &&...ts)
constexpr auto xrange(T e)
constexpr auto begin(const zstring_view &x)
constexpr auto end(const zstring_view &x)