22using std::string_view;
26static bool formatHelper(std::span<const string_view> input,
size_t columnLimit,
27 vector<string>& result)
30 auto it =
begin(input);
32 size_t maxColumn = column;
33 for (
size_t i = 0; (i < result.size()) && (it !=
end(input));
37 maxColumn = std::max(maxColumn,
39 if (maxColumn > columnLimit)
return false;
41 column = maxColumn + 2;
42 }
while (it !=
end(input));
46static vector<string> format(std::span<const string_view> input,
size_t columnLimit)
48 vector<string> result;
50 result.assign(lines,
string());
51 if (formatHelper(input, columnLimit, result)) {
64bool Completer::equalHead(string_view s1, string_view s2,
bool caseSensitive)
66 if (s2.size() < s1.size())
return false;
70 return strncasecmp(s1.data(), s2.data(), s1.size()) == 0;
74bool Completer::completeImpl(
string& str, vector<string_view>
matches,
78 return equalHead(str, m, caseSensitive);
99 bool expanded =
false;
102 if (str.size() == it->size()) {
108 auto e = b + str.size();
110 string_view string2(std::to_address(b), e - b);
112 if (!equalHead(string2, *it, caseSensitive)) {
121 if (!expanded && output) {
133 completeFileNameImpl(tokens, context, vector<string_view>());
136void Completer::completeFileNameImpl(vector<string>& tokens,
140 string& filename = tokens.back();
145 std::span<const string> paths;
147 static const std::array<std::string, 1> EMPTY = {
""};
153 vector<string> filenames;
154 for (
const auto& p : paths) {
155 auto pLen = p.size();
156 if (!p.empty() && (p.back() !=
'/')) ++pLen;
157 auto fileAction = [&](std::string_view path) {
159 std::string(path.substr(pLen)));
160 if (equalHead(filename, nm,
true)) {
161 filenames.push_back(nm);
164 auto dirAction = [&](
string& path) {
171 fileAction, dirAction);
174 bool t = completeImpl(filename,
matches,
true);
175 if (
t && !filename.empty() && (filename.back() !=
'/')) {
177 tokens.emplace_back();
198 if (tokens.size() == exactly)
return;
204 if (tokens.size() >= atLeast.
min)
return;
210 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
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)
constexpr bool all_of(InputRange &&range, UnaryPredicate pred)
auto unique(ForwardRange &&range)
constexpr 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)
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)