mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-21 03:21:16 -03:00
[clang-tidy] Convert loops to range based
Found with modernize-loop-convert Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
committed by
ridiculousfish
parent
1055ff321c
commit
586ac3dfa7
@@ -464,8 +464,8 @@ proc_status_t builtin_run(parser_t &parser, int job_pgid, wchar_t **argv, io_str
|
|||||||
wcstring_list_t builtin_get_names() {
|
wcstring_list_t builtin_get_names() {
|
||||||
wcstring_list_t result;
|
wcstring_list_t result;
|
||||||
result.reserve(BUILTIN_COUNT);
|
result.reserve(BUILTIN_COUNT);
|
||||||
for (size_t i = 0; i < BUILTIN_COUNT; i++) {
|
for (const auto &builtin_data : builtin_datas) {
|
||||||
result.push_back(builtin_datas[i].name);
|
result.push_back(builtin_data.name);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@@ -474,8 +474,8 @@ wcstring_list_t builtin_get_names() {
|
|||||||
void builtin_get_names(std::vector<completion_t> *list) {
|
void builtin_get_names(std::vector<completion_t> *list) {
|
||||||
assert(list != nullptr);
|
assert(list != nullptr);
|
||||||
list->reserve(list->size() + BUILTIN_COUNT);
|
list->reserve(list->size() + BUILTIN_COUNT);
|
||||||
for (size_t i = 0; i < BUILTIN_COUNT; i++) {
|
for (const auto &builtin_data : builtin_datas) {
|
||||||
append_completion(list, builtin_datas[i].name);
|
append_completion(list, builtin_data.name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -671,8 +671,8 @@ static void set_argparse_result_vars(env_stack_t &vars, const argparse_cmd_opts_
|
|||||||
// We do a simple replacement of all non alphanum chars rather than calling
|
// We do a simple replacement of all non alphanum chars rather than calling
|
||||||
// escape_string(long_flag, 0, STRING_STYLE_VAR).
|
// escape_string(long_flag, 0, STRING_STYLE_VAR).
|
||||||
wcstring long_flag = opt_spec->long_flag;
|
wcstring long_flag = opt_spec->long_flag;
|
||||||
for (size_t pos = 0; pos < long_flag.size(); pos++) {
|
for (auto &pos : long_flag) {
|
||||||
if (!iswalnum(long_flag[pos])) long_flag[pos] = L'_';
|
if (!iswalnum(pos)) pos = L'_';
|
||||||
}
|
}
|
||||||
vars.set(var_name_prefix + long_flag, ENV_LOCAL, opt_spec->vals);
|
vars.set(var_name_prefix + long_flag, ENV_LOCAL, opt_spec->vals);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -89,8 +89,7 @@ bool builtin_bind_t::list_one(const wcstring &seq, const wcstring &bind_mode, bo
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Now show the list of commands.
|
// Now show the list of commands.
|
||||||
for (size_t i = 0; i < ecmds.size(); i++) {
|
for (const auto &ecmd : ecmds) {
|
||||||
const wcstring &ecmd = ecmds.at(i);
|
|
||||||
const wcstring escaped_ecmd = escape_string(ecmd, ESCAPE_ALL);
|
const wcstring escaped_ecmd = escape_string(ecmd, ESCAPE_ALL);
|
||||||
streams.out.push_back(' ');
|
streams.out.push_back(' ');
|
||||||
streams.out.append(escaped_ecmd);
|
streams.out.append(escaped_ecmd);
|
||||||
@@ -143,8 +142,8 @@ void builtin_bind_t::key_names(bool all, io_streams_t &streams) {
|
|||||||
void builtin_bind_t::function_names(io_streams_t &streams) {
|
void builtin_bind_t::function_names(io_streams_t &streams) {
|
||||||
wcstring_list_t names = input_function_get_names();
|
wcstring_list_t names = input_function_get_names();
|
||||||
|
|
||||||
for (size_t i = 0; i < names.size(); i++) {
|
for (const auto &name : names) {
|
||||||
const wchar_t *seq = names.at(i).c_str();
|
auto seq = name.c_str();
|
||||||
streams.out.append_format(L"%ls\n", seq);
|
streams.out.append_format(L"%ls\n", seq);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -102,8 +102,8 @@ int builtin_builtin(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
wcstring_list_t names = builtin_get_names();
|
wcstring_list_t names = builtin_get_names();
|
||||||
std::sort(names.begin(), names.end());
|
std::sort(names.begin(), names.end());
|
||||||
|
|
||||||
for (size_t i = 0; i < names.size(); i++) {
|
for (const auto &name : names) {
|
||||||
const wchar_t *el = names.at(i).c_str();
|
auto el = name.c_str();
|
||||||
|
|
||||||
streams.out.append(el);
|
streams.out.append(el);
|
||||||
streams.out.append(L"\n");
|
streams.out.append(L"\n");
|
||||||
|
|||||||
@@ -99,7 +99,7 @@ int builtin_command(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
const wchar_t *command_name = argv[idx];
|
const wchar_t *command_name = argv[idx];
|
||||||
if (opts.all_paths) {
|
if (opts.all_paths) {
|
||||||
wcstring_list_t paths = path_get_paths(command_name, parser.vars());
|
wcstring_list_t paths = path_get_paths(command_name, parser.vars());
|
||||||
for (auto path : paths) {
|
for (const auto &path : paths) {
|
||||||
if (!opts.quiet) streams.out.append_format(L"%ls\n", path.c_str());
|
if (!opts.quiet) streams.out.append_format(L"%ls\n", path.c_str());
|
||||||
++found;
|
++found;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -291,10 +291,9 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
false /* do not accept incomplete */)) {
|
false /* do not accept incomplete */)) {
|
||||||
streams.err.append_format(L"%ls: Condition '%ls' contained a syntax error", cmd,
|
streams.err.append_format(L"%ls: Condition '%ls' contained a syntax error", cmd,
|
||||||
condition);
|
condition);
|
||||||
for (size_t i = 0; i < errors.size(); i++) {
|
for (const auto &error : errors) {
|
||||||
streams.err.append_format(L"\n%ls: ", cmd);
|
streams.err.append_format(L"\n%ls: ", cmd);
|
||||||
streams.err.append(
|
streams.err.append(error.describe(condition_string, parser.is_interactive()));
|
||||||
errors.at(i).describe(condition_string, parser.is_interactive()));
|
|
||||||
}
|
}
|
||||||
return STATUS_CMD_ERROR;
|
return STATUS_CMD_ERROR;
|
||||||
}
|
}
|
||||||
@@ -351,9 +350,7 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
complete(do_complete_param, &comp, completion_request_t::fuzzy_match, parser.vars(),
|
complete(do_complete_param, &comp, completion_request_t::fuzzy_match, parser.vars(),
|
||||||
parser.shared());
|
parser.shared());
|
||||||
|
|
||||||
for (size_t i = 0; i < comp.size(); i++) {
|
for (const auto &next : comp) {
|
||||||
const completion_t &next = comp.at(i);
|
|
||||||
|
|
||||||
// Make a fake commandline, and then apply the completion to it.
|
// Make a fake commandline, and then apply the completion to it.
|
||||||
const wcstring faux_cmdline = token;
|
const wcstring faux_cmdline = token;
|
||||||
size_t tmp_cursor = faux_cmdline.size();
|
size_t tmp_cursor = faux_cmdline.size();
|
||||||
@@ -414,11 +411,9 @@ int builtin_complete(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle wrap targets (probably empty). We only wrap commands, not paths.
|
// Handle wrap targets (probably empty). We only wrap commands, not paths.
|
||||||
for (size_t w = 0; w < wrap_targets.size(); w++) {
|
for (const auto &wrap_target : wrap_targets) {
|
||||||
const wcstring &wrap_target = wrap_targets.at(w);
|
for (const auto &i : cmd_to_complete) {
|
||||||
for (size_t i = 0; i < cmd_to_complete.size(); i++) {
|
(remove ? complete_remove_wrapper : complete_add_wrapper)(i, wrap_target);
|
||||||
(remove ? complete_remove_wrapper : complete_add_wrapper)(cmd_to_complete.at(i),
|
|
||||||
wrap_target);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -368,14 +368,14 @@ int builtin_functions(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
bool is_screen = !streams.out_is_redirected && isatty(STDOUT_FILENO);
|
bool is_screen = !streams.out_is_redirected && isatty(STDOUT_FILENO);
|
||||||
if (is_screen) {
|
if (is_screen) {
|
||||||
wcstring buff;
|
wcstring buff;
|
||||||
for (size_t i = 0; i < names.size(); i++) {
|
for (const auto &name : names) {
|
||||||
buff.append(names.at(i));
|
buff.append(name);
|
||||||
buff.append(L", ");
|
buff.append(L", ");
|
||||||
}
|
}
|
||||||
streams.out.append(reformat_for_screen(buff));
|
streams.out.append(reformat_for_screen(buff));
|
||||||
} else {
|
} else {
|
||||||
for (size_t i = 0; i < names.size(); i++) {
|
for (const auto &name : names) {
|
||||||
streams.out.append(names.at(i).c_str());
|
streams.out.append(name.c_str());
|
||||||
streams.out.append(L"\n");
|
streams.out.append(L"\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -516,8 +516,8 @@ int builtin_read(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
} else {
|
} else {
|
||||||
// Not array mode: assign each char to a separate var with the remainder being
|
// Not array mode: assign each char to a separate var with the remainder being
|
||||||
// assigned to the last var.
|
// assigned to the last var.
|
||||||
for (auto c = chars.begin(); c != chars.end() && vars_left(); ++c) {
|
for (const auto &c : chars) {
|
||||||
vars.set_one(*var_ptr++, opts.place, *c);
|
vars.set_one(*var_ptr++, opts.place, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (opts.array) {
|
} else if (opts.array) {
|
||||||
|
|||||||
@@ -476,8 +476,7 @@ static int builtin_set_list(const wchar_t *cmd, set_cmd_opts_t &opts, int argc,
|
|||||||
wcstring_list_t names = parser.vars().get_names(compute_scope(opts));
|
wcstring_list_t names = parser.vars().get_names(compute_scope(opts));
|
||||||
sort(names.begin(), names.end());
|
sort(names.begin(), names.end());
|
||||||
|
|
||||||
for (size_t i = 0; i < names.size(); i++) {
|
for (const auto &key : names) {
|
||||||
const wcstring key = names.at(i);
|
|
||||||
const wcstring e_key = escape_string(key, 0);
|
const wcstring e_key = escape_string(key, 0);
|
||||||
streams.out.append(e_key);
|
streams.out.append(e_key);
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ class parser_t;
|
|||||||
static void print_colors(io_streams_t &streams) {
|
static void print_colors(io_streams_t &streams) {
|
||||||
outputter_t outp;
|
outputter_t outp;
|
||||||
|
|
||||||
for (wcstring color_name : rgb_color_t::named_color_names()) {
|
for (const auto &color_name : rgb_color_t::named_color_names()) {
|
||||||
if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) {
|
if (!streams.out_is_redirected && isatty(STDOUT_FILENO)) {
|
||||||
rgb_color_t color = rgb_color_t(color_name);
|
rgb_color_t color = rgb_color_t(color_name);
|
||||||
outp.set_color(color, rgb_color_t::none());
|
outp.set_color(color, rgb_color_t::none());
|
||||||
|
|||||||
@@ -1100,8 +1100,8 @@ static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc
|
|||||||
|
|
||||||
// If we are from the right, split_about gave us reversed strings, in reversed order!
|
// If we are from the right, split_about gave us reversed strings, in reversed order!
|
||||||
if (opts.right) {
|
if (opts.right) {
|
||||||
for (size_t j = 0; j < splits.size(); j++) {
|
for (auto &split : splits) {
|
||||||
std::reverse(splits[j].begin(), splits[j].end());
|
std::reverse(split.begin(), split.end());
|
||||||
}
|
}
|
||||||
std::reverse(splits.begin(), splits.end());
|
std::reverse(splits.begin(), splits.end());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -864,8 +864,8 @@ int builtin_test(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
|
|||||||
bool result = expr->evaluate(eval_errors);
|
bool result = expr->evaluate(eval_errors);
|
||||||
if (!eval_errors.empty()) {
|
if (!eval_errors.empty()) {
|
||||||
if (!should_suppress_stderr_for_tests()) {
|
if (!should_suppress_stderr_for_tests()) {
|
||||||
for (size_t i = 0; i < eval_errors.size(); i++) {
|
for (const auto &eval_error : eval_errors) {
|
||||||
streams.err.append_format(L"%ls\n", eval_errors.at(i).c_str());
|
streams.err.append_format(L"%ls\n", eval_error.c_str());
|
||||||
}
|
}
|
||||||
// Add a backtrace but not the "see help" message
|
// Add a backtrace but not the "see help" message
|
||||||
// because this isn't about passing the wrong options.
|
// because this isn't about passing the wrong options.
|
||||||
|
|||||||
@@ -410,8 +410,7 @@ std::string wcs2string(const wcstring &input) {
|
|||||||
mbstate_t state = {};
|
mbstate_t state = {};
|
||||||
char converted[MB_LEN_MAX];
|
char converted[MB_LEN_MAX];
|
||||||
|
|
||||||
for (size_t i = 0; i < input.size(); i++) {
|
for (auto wc : input) {
|
||||||
wchar_t wc = input[i];
|
|
||||||
if (wc == INTERNAL_SEPARATOR) {
|
if (wc == INTERNAL_SEPARATOR) {
|
||||||
; // do nothing
|
; // do nothing
|
||||||
} else if (wc >= ENCODE_DIRECT_BASE && wc < ENCODE_DIRECT_BASE + 256) {
|
} else if (wc >= ENCODE_DIRECT_BASE && wc < ENCODE_DIRECT_BASE + 256) {
|
||||||
|
|||||||
@@ -269,8 +269,8 @@ void completions_sort_and_prioritize(std::vector<completion_t> *comps,
|
|||||||
completion_request_flags_t flags) {
|
completion_request_flags_t flags) {
|
||||||
// Find the best match type.
|
// Find the best match type.
|
||||||
fuzzy_match_type_t best_type = fuzzy_match_none;
|
fuzzy_match_type_t best_type = fuzzy_match_none;
|
||||||
for (size_t i = 0; i < comps->size(); i++) {
|
for (const auto &comp : *comps) {
|
||||||
best_type = std::min(best_type, comps->at(i).match.type);
|
best_type = std::min(best_type, comp.match.type);
|
||||||
}
|
}
|
||||||
// If the best type is an exact match, reduce it to prefix match. Otherwise a tab completion
|
// If the best type is an exact match, reduce it to prefix match. Otherwise a tab completion
|
||||||
// will only show one match if it matches a file exactly. (see issue #959).
|
// will only show one match if it matches a file exactly. (see issue #959).
|
||||||
|
|||||||
@@ -1041,8 +1041,8 @@ static wcstring get_machine_identifier() {
|
|||||||
unsigned char mac_addr[MAC_ADDRESS_MAX_LEN] = {};
|
unsigned char mac_addr[MAC_ADDRESS_MAX_LEN] = {};
|
||||||
if (get_mac_address(mac_addr)) {
|
if (get_mac_address(mac_addr)) {
|
||||||
result.reserve(2 * MAC_ADDRESS_MAX_LEN);
|
result.reserve(2 * MAC_ADDRESS_MAX_LEN);
|
||||||
for (size_t i = 0; i < MAC_ADDRESS_MAX_LEN; i++) {
|
for (auto i : mac_addr) {
|
||||||
append_format(result, L"%02x", mac_addr[i]);
|
append_format(result, L"%02x", i);
|
||||||
}
|
}
|
||||||
} else if (!get_hostname_identifier(result)) {
|
} else if (!get_hostname_identifier(result)) {
|
||||||
result.assign(L"nohost"); // fallback to a dummy value
|
result.assign(L"nohost"); // fallback to a dummy value
|
||||||
|
|||||||
@@ -192,8 +192,8 @@ wcstring event_get_desc(const event_t &evt) {
|
|||||||
#if 0
|
#if 0
|
||||||
static void show_all_handlers(void) {
|
static void show_all_handlers(void) {
|
||||||
std::fwprintf(stdout, L"event handlers:\n");
|
std::fwprintf(stdout, L"event handlers:\n");
|
||||||
for (event_list_t::const_iterator iter = events.begin(); iter != events.end(); ++iter) {
|
for (const auto& event : events) {
|
||||||
const event_t *foo = *iter;
|
auto foo = event;
|
||||||
wcstring tmp = event_get_desc(foo);
|
wcstring tmp = event_get_desc(foo);
|
||||||
std::fwprintf(stdout, L" handler now %ls\n", tmp.c_str());
|
std::fwprintf(stdout, L" handler now %ls\n", tmp.c_str());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ static void append_cmdsub_error(parse_error_list_t *errors, size_t source_start,
|
|||||||
error.text = vformat_string(fmt, va);
|
error.text = vformat_string(fmt, va);
|
||||||
va_end(va);
|
va_end(va);
|
||||||
|
|
||||||
for (auto it : *errors) {
|
for (const auto &it : *errors) {
|
||||||
if (error.text == it.text) return;
|
if (error.text == it.text) return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -757,8 +757,8 @@ static void unexpand_tildes(const wcstring &input, const environment_t &vars,
|
|||||||
// We only operate on completions that replace their contents. If we don't have any, we're done.
|
// We only operate on completions that replace their contents. If we don't have any, we're done.
|
||||||
// In particular, empty vectors are common.
|
// In particular, empty vectors are common.
|
||||||
bool has_candidate_completion = false;
|
bool has_candidate_completion = false;
|
||||||
for (size_t i = 0; i < completions->size(); i++) {
|
for (const auto &completion : *completions) {
|
||||||
if (completions->at(i).flags & COMPLETE_REPLACES_TOKEN) {
|
if (completion.flags & COMPLETE_REPLACES_TOKEN) {
|
||||||
has_candidate_completion = true;
|
has_candidate_completion = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -774,8 +774,7 @@ static void unexpand_tildes(const wcstring &input, const environment_t &vars,
|
|||||||
expand_tilde(home, vars);
|
expand_tilde(home, vars);
|
||||||
|
|
||||||
// Now for each completion that starts with home, replace it with the username_with_tilde.
|
// Now for each completion that starts with home, replace it with the username_with_tilde.
|
||||||
for (size_t i = 0; i < completions->size(); i++) {
|
for (auto &comp : *completions) {
|
||||||
completion_t &comp = completions->at(i);
|
|
||||||
if ((comp.flags & COMPLETE_REPLACES_TOKEN) &&
|
if ((comp.flags & COMPLETE_REPLACES_TOKEN) &&
|
||||||
string_prefixes_string(home, comp.completion)) {
|
string_prefixes_string(home, comp.completion)) {
|
||||||
comp.completion.replace(0, home.size(), username_with_tilde);
|
comp.completion.replace(0, home.size(), username_with_tilde);
|
||||||
@@ -817,15 +816,15 @@ static void remove_internal_separator(wcstring *str, bool conv) {
|
|||||||
// If conv is true, replace all instances of ANY_STRING with '*',
|
// If conv is true, replace all instances of ANY_STRING with '*',
|
||||||
// ANY_STRING_RECURSIVE with '*'.
|
// ANY_STRING_RECURSIVE with '*'.
|
||||||
if (conv) {
|
if (conv) {
|
||||||
for (size_t idx = 0; idx < str->size(); idx++) {
|
for (auto &idx : *str) {
|
||||||
switch (str->at(idx)) {
|
switch (idx) {
|
||||||
case ANY_CHAR: {
|
case ANY_CHAR: {
|
||||||
str->at(idx) = L'?';
|
idx = L'?';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case ANY_STRING:
|
case ANY_STRING:
|
||||||
case ANY_STRING_RECURSIVE: {
|
case ANY_STRING_RECURSIVE: {
|
||||||
str->at(idx) = L'*';
|
idx = L'*';
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default: {
|
default: {
|
||||||
@@ -903,9 +902,9 @@ expand_result_t expander_t::stage_variables(wcstring input, std::vector<completi
|
|||||||
unescape_string(input, &next, UNESCAPE_SPECIAL | UNESCAPE_INCOMPLETE);
|
unescape_string(input, &next, UNESCAPE_SPECIAL | UNESCAPE_INCOMPLETE);
|
||||||
|
|
||||||
if (flags & expand_flag::skip_variables) {
|
if (flags & expand_flag::skip_variables) {
|
||||||
for (size_t i = 0; i < next.size(); i++) {
|
for (auto &i : next) {
|
||||||
if (next.at(i) == VARIABLE_EXPAND) {
|
if (i == VARIABLE_EXPAND) {
|
||||||
next[i] = L'$';
|
i = L'$';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
append_completion(out, std::move(next));
|
append_completion(out, std::move(next));
|
||||||
@@ -942,7 +941,7 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand,
|
|||||||
const bool skip_wildcards = flags & expand_flag::skip_wildcards;
|
const bool skip_wildcards = flags & expand_flag::skip_wildcards;
|
||||||
|
|
||||||
if (has_wildcard && (flags & expand_flag::executables_only)) {
|
if (has_wildcard && (flags & expand_flag::executables_only)) {
|
||||||
; // don't do wildcard expansion for executables, see issue #785
|
// don't do wildcard expansion for executables, see issue #785
|
||||||
} else if ((for_completions && !skip_wildcards) || has_wildcard) {
|
} else if ((for_completions && !skip_wildcards) || has_wildcard) {
|
||||||
// We either have a wildcard, or we don't have a wildcard but we're doing completion
|
// We either have a wildcard, or we don't have a wildcard but we're doing completion
|
||||||
// expansion (so we want to get the completion of a file path). Note that if
|
// expansion (so we want to get the completion of a file path). Note that if
|
||||||
@@ -998,9 +997,9 @@ expand_result_t expander_t::stage_wildcards(wcstring path_to_expand,
|
|||||||
|
|
||||||
result = expand_result_t::wildcard_no_match;
|
result = expand_result_t::wildcard_no_match;
|
||||||
std::vector<completion_t> expanded;
|
std::vector<completion_t> expanded;
|
||||||
for (size_t wd_idx = 0; wd_idx < effective_working_dirs.size(); wd_idx++) {
|
for (const auto &effective_working_dir : effective_working_dirs) {
|
||||||
int local_wc_res = wildcard_expand_string(
|
int local_wc_res =
|
||||||
path_to_expand, effective_working_dirs.at(wd_idx), flags, &expanded);
|
wildcard_expand_string(path_to_expand, effective_working_dir, flags, &expanded);
|
||||||
if (local_wc_res > 0) {
|
if (local_wc_res > 0) {
|
||||||
// Something matched,so overall we matched.
|
// Something matched,so overall we matched.
|
||||||
result = expand_result_t::wildcard_match;
|
result = expand_result_t::wildcard_match;
|
||||||
|
|||||||
@@ -252,8 +252,8 @@ int run_command_list(std::vector<std::string> *cmds, const io_chain_t &io) {
|
|||||||
int res = 1;
|
int res = 1;
|
||||||
parser_t &parser = parser_t::principal_parser();
|
parser_t &parser = parser_t::principal_parser();
|
||||||
|
|
||||||
for (size_t i = 0; i < cmds->size(); i++) {
|
for (const auto &cmd : *cmds) {
|
||||||
const wcstring cmd_wcs = str2wcstring(cmds->at(i));
|
const wcstring cmd_wcs = str2wcstring(cmd);
|
||||||
res = parser.eval(cmd_wcs, io, TOP);
|
res = parser.eval(cmd_wcs, io, TOP);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -163,8 +163,8 @@ static void add_char_to_bind_command(wchar_t wc, std::vector<wchar_t> &bind_char
|
|||||||
static void output_bind_command(std::vector<wchar_t> &bind_chars) {
|
static void output_bind_command(std::vector<wchar_t> &bind_chars) {
|
||||||
if (!bind_chars.empty()) {
|
if (!bind_chars.empty()) {
|
||||||
std::fputws(L"bind ", stdout);
|
std::fputws(L"bind ", stdout);
|
||||||
for (size_t i = 0; i < bind_chars.size(); i++) {
|
for (auto bind_char : bind_chars) {
|
||||||
std::fputws(char_to_symbol(bind_chars[i], true), stdout);
|
std::fputws(char_to_symbol(bind_char, true), stdout);
|
||||||
}
|
}
|
||||||
std::fputws(L" 'do something'\n", stdout);
|
std::fputws(L" 'do something'\n", stdout);
|
||||||
bind_chars.clear();
|
bind_chars.clear();
|
||||||
|
|||||||
@@ -215,8 +215,7 @@ bool is_potential_path(const wcstring &potential_path_fragment, const wcstring_l
|
|||||||
|
|
||||||
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
|
// debug( 1, L"%ls -> %ls ->%ls", path, tilde, unescaped );
|
||||||
|
|
||||||
for (size_t i = 0; i < path_with_magic.size(); i++) {
|
for (auto c : path_with_magic) {
|
||||||
wchar_t c = path_with_magic.at(i);
|
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case PROCESS_EXPAND_SELF:
|
case PROCESS_EXPAND_SELF:
|
||||||
case VARIABLE_EXPAND:
|
case VARIABLE_EXPAND:
|
||||||
@@ -385,8 +384,7 @@ rgb_color_t highlight_get_color(const highlight_spec_t &highlight, bool is_backg
|
|||||||
|
|
||||||
static bool has_expand_reserved(const wcstring &str) {
|
static bool has_expand_reserved(const wcstring &str) {
|
||||||
bool result = false;
|
bool result = false;
|
||||||
for (size_t i = 0; i < str.size(); i++) {
|
for (auto wc : str) {
|
||||||
wchar_t wc = str.at(i);
|
|
||||||
if (wc >= EXPAND_RESERVED_BASE && wc <= EXPAND_RESERVED_END) {
|
if (wc >= EXPAND_RESERVED_BASE && wc <= EXPAND_RESERVED_END) {
|
||||||
result = true;
|
result = true;
|
||||||
break;
|
break;
|
||||||
@@ -1290,10 +1288,7 @@ highlighter_t::color_array_t highlighter_t::highlight() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// If the cursor is over an argument, and that argument is a valid path, underline it.
|
// If the cursor is over an argument, and that argument is a valid path, underline it.
|
||||||
for (parse_node_tree_t::const_iterator iter = parse_tree.begin(); iter != parse_tree.end();
|
for (const auto &node : parse_tree) {
|
||||||
++iter) {
|
|
||||||
const parse_node_t &node = *iter;
|
|
||||||
|
|
||||||
// Must be an argument with source.
|
// Must be an argument with source.
|
||||||
if (node.type != symbol_argument || !node.has_source()) continue;
|
if (node.type != symbol_argument || !node.has_source()) continue;
|
||||||
|
|
||||||
|
|||||||
@@ -709,7 +709,7 @@ bool history_impl_t::rewrite_to_temporary_file(int existing_fd, int dst_fd) cons
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
std::string buffer;
|
std::string buffer;
|
||||||
buffer.reserve(HISTORY_OUTPUT_BUFFER_SIZE + 128);
|
buffer.reserve(HISTORY_OUTPUT_BUFFER_SIZE + 128);
|
||||||
for (const auto &key_item : lru) {
|
for (const auto key_item : lru) {
|
||||||
append_history_item_to_buffer(key_item.second, &buffer);
|
append_history_item_to_buffer(key_item.second, &buffer);
|
||||||
err = flush_to_fd(&buffer, dst_fd, HISTORY_OUTPUT_BUFFER_SIZE);
|
err = flush_to_fd(&buffer, dst_fd, HISTORY_OUTPUT_BUFFER_SIZE);
|
||||||
if (err) break;
|
if (err) break;
|
||||||
|
|||||||
@@ -543,8 +543,7 @@ std::vector<input_mapping_name_t> input_mapping_set_t::get_names(bool user) cons
|
|||||||
std::vector<input_mapping_name_t> result;
|
std::vector<input_mapping_name_t> result;
|
||||||
result.reserve(local_list.size());
|
result.reserve(local_list.size());
|
||||||
|
|
||||||
for (size_t i = 0; i < local_list.size(); i++) {
|
for (const auto &m : local_list) {
|
||||||
const input_mapping_t &m = local_list.at(i);
|
|
||||||
result.push_back((input_mapping_name_t){m.seq, m.mode});
|
result.push_back((input_mapping_name_t){m.seq, m.mode});
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -435,8 +435,7 @@ rgb_color_t best_color(const std::vector<rgb_color_t> &candidates, color_support
|
|||||||
}
|
}
|
||||||
|
|
||||||
rgb_color_t first_rgb = rgb_color_t::none(), first_named = rgb_color_t::none();
|
rgb_color_t first_rgb = rgb_color_t::none(), first_named = rgb_color_t::none();
|
||||||
for (size_t i = 0; i < candidates.size(); i++) {
|
for (const auto &color : candidates) {
|
||||||
const rgb_color_t &color = candidates.at(i);
|
|
||||||
if (first_rgb.is_none() && color.is_rgb()) {
|
if (first_rgb.is_none() && color.is_rgb()) {
|
||||||
first_rgb = color;
|
first_rgb = color;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,8 +324,8 @@ static comp_info_list_t process_completions_into_infos(const completion_list_t &
|
|||||||
|
|
||||||
void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring &prefix) const {
|
void pager_t::measure_completion_infos(comp_info_list_t *infos, const wcstring &prefix) const {
|
||||||
size_t prefix_len = fish_wcswidth(prefix);
|
size_t prefix_len = fish_wcswidth(prefix);
|
||||||
for (size_t i = 0; i < infos->size(); i++) {
|
for (auto &info : *infos) {
|
||||||
comp_t *comp = &infos->at(i);
|
comp_t *comp = &info;
|
||||||
const wcstring_list_t &comp_strings = comp->comp;
|
const wcstring_list_t &comp_strings = comp->comp;
|
||||||
|
|
||||||
for (size_t j = 0; j < comp_strings.size(); j++) {
|
for (size_t j = 0; j < comp_strings.size(); j++) {
|
||||||
@@ -359,9 +359,8 @@ bool pager_t::completion_info_passes_filter(const comp_t &info) const {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Match against the completion strings.
|
// Match against the completion strings.
|
||||||
for (size_t i = 0; i < info.comp.size(); i++) {
|
for (const auto &i : info.comp) {
|
||||||
if (string_fuzzy_match_string(needle, prefix + info.comp.at(i), limit).type !=
|
if (string_fuzzy_match_string(needle, prefix + i, limit).type != fuzzy_match_none) {
|
||||||
fuzzy_match_none) {
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -372,8 +371,7 @@ bool pager_t::completion_info_passes_filter(const comp_t &info) const {
|
|||||||
// Update completion_infos from unfiltered_completion_infos, to reflect the filter.
|
// Update completion_infos from unfiltered_completion_infos, to reflect the filter.
|
||||||
void pager_t::refilter_completions() {
|
void pager_t::refilter_completions() {
|
||||||
this->completion_infos.clear();
|
this->completion_infos.clear();
|
||||||
for (size_t i = 0; i < this->unfiltered_completion_infos.size(); i++) {
|
for (const auto &info : this->unfiltered_completion_infos) {
|
||||||
const comp_t &info = this->unfiltered_completion_infos.at(i);
|
|
||||||
if (this->completion_info_passes_filter(info)) {
|
if (this->completion_info_passes_filter(info)) {
|
||||||
this->completion_infos.push_back(info);
|
this->completion_infos.push_back(info);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -877,8 +877,8 @@ void reader_write_title(const wcstring &cmd, parser_t &parser, bool reset_cursor
|
|||||||
if (exec_subshell(fish_title_command, parser, lst, false /* ignore exit status */) != -1 &&
|
if (exec_subshell(fish_title_command, parser, lst, false /* ignore exit status */) != -1 &&
|
||||||
!lst.empty()) {
|
!lst.empty()) {
|
||||||
std::fputws(L"\x1B]0;", stdout);
|
std::fputws(L"\x1B]0;", stdout);
|
||||||
for (size_t i = 0; i < lst.size(); i++) {
|
for (const auto &i : lst) {
|
||||||
std::fputws(lst.at(i).c_str(), stdout);
|
std::fputws(i.c_str(), stdout);
|
||||||
}
|
}
|
||||||
ignore_result(write(STDOUT_FILENO, "\a", 1));
|
ignore_result(write(STDOUT_FILENO, "\a", 1));
|
||||||
}
|
}
|
||||||
@@ -897,8 +897,8 @@ void reader_data_t::exec_mode_prompt() {
|
|||||||
exec_subshell(MODE_PROMPT_FUNCTION_NAME, parser(), mode_indicator_list, false);
|
exec_subshell(MODE_PROMPT_FUNCTION_NAME, parser(), mode_indicator_list, false);
|
||||||
// We do not support multiple lines in the mode indicator, so just concatenate all of
|
// We do not support multiple lines in the mode indicator, so just concatenate all of
|
||||||
// them.
|
// them.
|
||||||
for (size_t i = 0; i < mode_indicator_list.size(); i++) {
|
for (const auto &i : mode_indicator_list) {
|
||||||
mode_prompt_buff += mode_indicator_list.at(i);
|
mode_prompt_buff += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -939,9 +939,9 @@ void reader_data_t::exec_prompt() {
|
|||||||
wcstring_list_t prompt_list;
|
wcstring_list_t prompt_list;
|
||||||
// Status is ignored.
|
// Status is ignored.
|
||||||
exec_subshell(right_prompt, parser(), prompt_list, apply_exit_status);
|
exec_subshell(right_prompt, parser(), prompt_list, apply_exit_status);
|
||||||
for (size_t i = 0; i < prompt_list.size(); i++) {
|
for (const auto &i : prompt_list) {
|
||||||
// Right prompt does not support multiple lines, so just concatenate all of them.
|
// Right prompt does not support multiple lines, so just concatenate all of them.
|
||||||
right_prompt_buff += prompt_list.at(i);
|
right_prompt_buff += i;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1470,8 +1470,8 @@ static bool reader_can_replace(const wcstring &in, int flags) {
|
|||||||
/// Determine the best match type for a set of completions.
|
/// Determine the best match type for a set of completions.
|
||||||
static fuzzy_match_type_t get_best_match_type(const std::vector<completion_t> &comp) {
|
static fuzzy_match_type_t get_best_match_type(const std::vector<completion_t> &comp) {
|
||||||
fuzzy_match_type_t best_type = fuzzy_match_none;
|
fuzzy_match_type_t best_type = fuzzy_match_none;
|
||||||
for (size_t i = 0; i < comp.size(); i++) {
|
for (const auto &i : comp) {
|
||||||
best_type = std::min(best_type, comp.at(i).match.type);
|
best_type = std::min(best_type, i.match.type);
|
||||||
}
|
}
|
||||||
// If the best type is an exact match, reduce it to prefix match. Otherwise a tab completion
|
// If the best type is an exact match, reduce it to prefix match. Otherwise a tab completion
|
||||||
// will only show one match if it matches a file exactly. (see issue #959).
|
// will only show one match if it matches a file exactly. (see issue #959).
|
||||||
|
|||||||
@@ -201,11 +201,11 @@ static bool is_color_escape_seq(const wchar_t *code, size_t *resulting_length) {
|
|||||||
set_background,
|
set_background,
|
||||||
};
|
};
|
||||||
|
|
||||||
for (size_t p = 0; p < sizeof esc / sizeof *esc; p++) {
|
for (auto p : esc) {
|
||||||
if (!esc[p]) continue;
|
if (!p) continue;
|
||||||
|
|
||||||
for (int k = 0; k < max_colors; k++) {
|
for (int k = 0; k < max_colors; k++) {
|
||||||
size_t esc_seq_len = try_sequence(tparm(const_cast<char *>(esc[p]), k), code);
|
size_t esc_seq_len = try_sequence(tparm(const_cast<char *>(p), k), code);
|
||||||
if (esc_seq_len) {
|
if (esc_seq_len) {
|
||||||
*resulting_length = esc_seq_len;
|
*resulting_length = esc_seq_len;
|
||||||
return true;
|
return true;
|
||||||
@@ -227,12 +227,12 @@ static bool is_visual_escape_seq(const wchar_t *code, size_t *resulting_length)
|
|||||||
exit_shadow_mode, enter_standout_mode, exit_standout_mode, enter_secure_mode,
|
exit_shadow_mode, enter_standout_mode, exit_standout_mode, enter_secure_mode,
|
||||||
enter_dim_mode, enter_blink_mode, enter_alt_charset_mode, exit_alt_charset_mode};
|
enter_dim_mode, enter_blink_mode, enter_alt_charset_mode, exit_alt_charset_mode};
|
||||||
|
|
||||||
for (size_t p = 0; p < sizeof esc2 / sizeof *esc2; p++) {
|
for (auto p : esc2) {
|
||||||
if (!esc2[p]) continue;
|
if (!p) continue;
|
||||||
// Test both padded and unpadded version, just to be safe. Most versions of tparm don't
|
// Test both padded and unpadded version, just to be safe. Most versions of tparm don't
|
||||||
// actually seem to do anything these days.
|
// actually seem to do anything these days.
|
||||||
size_t esc_seq_len = std::max(try_sequence(tparm(const_cast<char *>(esc2[p])), code),
|
size_t esc_seq_len =
|
||||||
try_sequence(esc2[p], code));
|
std::max(try_sequence(tparm(const_cast<char *>(p)), code), try_sequence(p, code));
|
||||||
if (esc_seq_len) {
|
if (esc_seq_len) {
|
||||||
*resulting_length = esc_seq_len;
|
*resulting_length = esc_seq_len;
|
||||||
return true;
|
return true;
|
||||||
@@ -892,8 +892,7 @@ static screen_layout_t compute_layout(screen_t *s, size_t screen_width,
|
|||||||
// Get the width of the first line, and if there is more than one line.
|
// Get the width of the first line, and if there is more than one line.
|
||||||
bool multiline = false;
|
bool multiline = false;
|
||||||
size_t first_line_width = 0;
|
size_t first_line_width = 0;
|
||||||
for (size_t i = 0; i < commandline.size(); i++) {
|
for (auto c : commandline) {
|
||||||
wchar_t c = commandline.at(i);
|
|
||||||
if (c == L'\n') {
|
if (c == L'\n') {
|
||||||
multiline = true;
|
multiline = true;
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -637,9 +637,8 @@ class wildcard_expander_t {
|
|||||||
assert(resolved_completions != nullptr);
|
assert(resolved_completions != nullptr);
|
||||||
|
|
||||||
// Insert initial completions into our set to avoid duplicates.
|
// Insert initial completions into our set to avoid duplicates.
|
||||||
for (std::vector<completion_t>::const_iterator iter = resolved_completions->begin();
|
for (const auto &resolved_completion : *resolved_completions) {
|
||||||
iter != resolved_completions->end(); ++iter) {
|
this->completion_set.insert(resolved_completion.completion);
|
||||||
this->completion_set.insert(iter->completion);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user