diff --git a/src/builtin_function.cpp b/src/builtin_function.cpp index 7c4dec37b..c1b07ee26 100644 --- a/src/builtin_function.cpp +++ b/src/builtin_function.cpp @@ -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]); diff --git a/src/builtin_history.cpp b/src/builtin_history.cpp index 13040d3cf..1c0480263 100644 --- a/src/builtin_history.cpp +++ b/src/builtin_history.cpp @@ -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; diff --git a/src/builtin_string.cpp b/src/builtin_string.cpp index ae21e7cb2..971305ad0 100644 --- a/src/builtin_string.cpp +++ b/src/builtin_string.cpp @@ -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 "". // diff --git a/src/common.cpp b/src/common.cpp index 9e060e2f3..59259496d 100644 --- a/src/common.cpp +++ b/src/common.cpp @@ -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(); diff --git a/src/fish.cpp b/src/fish.cpp index 18e29cb18..3fc6fdcbf 100644 --- a/src/fish.cpp +++ b/src/fish.cpp @@ -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); } diff --git a/src/fish_key_reader.cpp b/src/fish_key_reader.cpp index 1b49de34c..318e5274b 100644 --- a/src/fish_key_reader.cpp +++ b/src/fish_key_reader.cpp @@ -160,7 +160,7 @@ static void add_char_to_bind_command(wchar_t wc, std::vector &bind_char } static void output_bind_command(std::vector &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); diff --git a/src/input.cpp b/src/input.cpp index 565ecd1a7..91803b660 100644 --- a/src/input.cpp +++ b/src/input.cpp @@ -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) { diff --git a/src/parser.cpp b/src/parser.cpp index e8f3d6a13..0a6955d8f 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -272,7 +272,7 @@ static void print_profile(const std::vector> &it my_time -= prev->parse + prev->exec; } - if (me->cmd.size() == 0) { + if (me->cmd.empty()) { continue; } diff --git a/src/reader.cpp b/src/reader.cpp index 2c83ad2ec..43f5dc4c8 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -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 noninteractive{&parser().libdata().is_interactive, false}; exec_mode_prompt(); diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 49c18c224..450cbc6e9 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -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,