[clang-tidy] Replace size comparisons with empty

Found with readability-container-size-empty

Signed-off-by: Rosen Penev <rosenp@gmail.com>
This commit is contained in:
Rosen Penev 2019-11-18 16:56:46 -08:00 committed by ridiculousfish
parent 5ca80a61e3
commit 7f62e30731
10 changed files with 17 additions and 17 deletions

View File

@ -237,7 +237,7 @@ int builtin_function(parser_t &parser, io_streams_t &streams, const wcstring_lis
}
if (argc != optind) {
if (opts.named_arguments.size()) {
if (!opts.named_arguments.empty()) {
for (int i = optind; i < argc; i++) {
if (!valid_var_name(argv[i])) {
streams.err.append_format(BUILTIN_ERR_VARNAME, cmd, argv[i]);

View File

@ -87,7 +87,7 @@ static bool check_for_unexpected_hist_args(const history_cmd_opts_t &opts, const
subcmd_str);
return true;
}
if (args.size() != 0) {
if (!args.empty()) {
const wchar_t *subcmd_str = enum_to_str(opts.hist_cmd, hist_enum_map);
streams.err.append_format(BUILTIN_ERR_ARG_COUNT2, cmd, subcmd_str, 0, args.size());
return true;

View File

@ -1109,7 +1109,7 @@ static int string_split_maybe0(parser_t &parser, io_streams_t &streams, int argc
const size_t split_count = splits.size();
if (!opts.quiet) {
if (is_split0 && splits.size()) {
if (is_split0 && !splits.empty()) {
// split0 ignores a trailing \0, so a\0b\0 is two elements.
// In contrast to split, where a\nb\n is three - "a", "b" and "".
//

View File

@ -1519,7 +1519,7 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
// is ANY_STRING, delete the last char and store ANY_STRING_RECURSIVE to
// reflect the fact that ** is the recursive wildcard.
if (string_last_char(result) == ANY_STRING) {
assert(result.size() > 0);
assert(!result.empty());
result.resize(result.size() - 1);
to_append_or_none = ANY_STRING_RECURSIVE;
} else {
@ -1561,10 +1561,10 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
brace_count--;
brace_text_start = brace_text_start && brace_count > 0;
to_append_or_none = BRACE_END;
if (braces.size()) {
if (!braces.empty()) {
// If we didn't have a var or separator since the last '{',
// put the literal back.
if (!vars_or_seps.size() || vars_or_seps.back() < braces.back()) {
if (vars_or_seps.empty() || vars_or_seps.back() < braces.back()) {
result[braces.back()] = L'{';
// We also need to turn all spaces back.
for (size_t i = braces.back() + 1; i < result.size(); i++) {
@ -1575,8 +1575,8 @@ static bool unescape_string_internal(const wchar_t *const input, const size_t in
// Remove all seps inside the current brace pair, so if we have a
// surrounding pair we only get seps inside *that*.
if (vars_or_seps.size()) {
while (vars_or_seps.size() && vars_or_seps.back() > braces.back())
if (!vars_or_seps.empty()) {
while (!vars_or_seps.empty() && vars_or_seps.back() > braces.back())
vars_or_seps.pop_back();
}
braces.pop_back();

View File

@ -393,7 +393,7 @@ static int fish_parse_opt(int argc, char **argv, fish_cmd_opts_t *opts) {
// We are an interactive session if we have not been given an explicit
// command or file to execute and stdin is a tty. Note that the -i or
// --interactive options also force interactive mode.
if (opts->batch_cmds.size() == 0 && optind == argc && isatty(STDIN_FILENO)) {
if (opts->batch_cmds.empty() && optind == argc && isatty(STDIN_FILENO)) {
set_interactive_session(true);
}

View File

@ -160,7 +160,7 @@ 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) {
if (bind_chars.size()) {
if (!bind_chars.empty()) {
std::fputws(L"bind ", stdout);
for (size_t i = 0; i < bind_chars.size(); i++) {
std::fputws(char_to_symbol(bind_chars[i], true), stdout);

View File

@ -407,7 +407,7 @@ void inputter_t::mapping_execute(const input_mapping_t &m, bool allow_commands)
bool inputter_t::mapping_is_match(const input_mapping_t &m) {
const wcstring &str = m.seq;
assert(str.size() > 0 && "zero-length input string passed to mapping_is_match!");
assert(!str.empty() && "zero-length input string passed to mapping_is_match!");
bool timed = false;
for (size_t i = 0; i < str.size(); ++i) {

View File

@ -272,7 +272,7 @@ static void print_profile(const std::vector<std::unique_ptr<profile_item_t>> &it
my_time -= prev->parse + prev->exec;
}
if (me->cmd.size() == 0) {
if (me->cmd.empty()) {
continue;
}

View File

@ -920,7 +920,7 @@ void reader_data_t::exec_prompt() {
(void)get_current_winsize();
// If we have any prompts, they must be run non-interactively.
if (left_prompt.size() || right_prompt.size()) {
if (!left_prompt.empty() || !right_prompt.empty()) {
scoped_push<bool> noninteractive{&parser().libdata().is_interactive, false};
exec_mode_prompt();

View File

@ -182,7 +182,7 @@ tok_t tokenizer_t::read_string() {
expecting.push_back(L'}');
mode |= tok_modes::curly_braces;
} else if (c == L')') {
if (expecting.size() > 0 && expecting.back() == L'}') {
if (!expecting.empty() && expecting.back() == L'}') {
return this->call_error(tokenizer_error_t::expected_bclose_found_pclose,
this->token_cursor, this->token_cursor, 1);
}
@ -196,7 +196,7 @@ tok_t tokenizer_t::read_string() {
}
expecting.pop_back();
} else if (c == L'}') {
if (expecting.size() > 0 && expecting.back() == L')') {
if (!expecting.empty() && expecting.back() == L')') {
return this->call_error(tokenizer_error_t::expected_pclose_found_bclose,
this->token_cursor, this->token_cursor, 1);
}
@ -262,13 +262,13 @@ tok_t tokenizer_t::read_string() {
return this->call_error(tokenizer_error_t::unterminated_slice, buff_start,
this->start + slice_offset);
} else if (mode & tok_modes::subshell) {
assert(paran_offsets.size() > 0);
assert(!paran_offsets.empty());
size_t offset_of_open_paran = paran_offsets.back();
return this->call_error(tokenizer_error_t::unterminated_subshell, buff_start,
this->start + offset_of_open_paran);
} else if (mode & tok_modes::curly_braces) {
assert(brace_offsets.size() > 0);
assert(!brace_offsets.empty());
size_t offset_of_open_brace = brace_offsets.back();
return this->call_error(tokenizer_error_t::unterminated_brace, buff_start,