mirror of
https://github.com/transmission/transmission
synced 2025-01-03 13:35:36 +00:00
refactor: remove tr_str_is_empty() (#6432)
* refactor: do not u se tr_str_is_empty() in tr_torrentSetLocation() * refactor: do not use tr_str_is_empty() in remote.cc * refactor: do not use tr_str_is_empty() in subprocess-win32 * refactor: remove tr_str_is_empty()
This commit is contained in:
parent
42b09b22df
commit
0ef34878de
4 changed files with 22 additions and 19 deletions
|
@ -144,12 +144,14 @@ auto get_current_env()
|
|||
|
||||
void append_argument(std::string& arguments, char const* argument)
|
||||
{
|
||||
TR_ASSERT(argument != nullptr);
|
||||
|
||||
if (!std::empty(arguments))
|
||||
{
|
||||
arguments += ' ';
|
||||
}
|
||||
|
||||
if (!tr_str_is_empty(argument) && strpbrk(argument, " \t\n\v\"") == nullptr)
|
||||
if (*argument != '\0' && strpbrk(argument, " \t\n\v\"") == nullptr)
|
||||
{
|
||||
arguments += argument;
|
||||
return;
|
||||
|
|
|
@ -1182,7 +1182,8 @@ void tr_torrent::set_location(std::string_view location, bool move_from_old_path
|
|||
void tr_torrentSetLocation(tr_torrent* tor, char const* location, bool move_from_old_path, int volatile* setme_state)
|
||||
{
|
||||
TR_ASSERT(tr_isTorrent(tor));
|
||||
TR_ASSERT(!tr_str_is_empty(location));
|
||||
TR_ASSERT(location != nullptr);
|
||||
TR_ASSERT(*location != '\0');
|
||||
|
||||
tor->set_location(location, move_from_old_path, setme_state);
|
||||
}
|
||||
|
|
|
@ -100,11 +100,6 @@ int tr_main_win32(int argc, char** argv, int (*real_main)(int, char**));
|
|||
|
||||
// ---
|
||||
|
||||
[[nodiscard]] constexpr bool tr_str_is_empty(char const* value)
|
||||
{
|
||||
return value == nullptr || *value == '\0';
|
||||
}
|
||||
|
||||
/** @brief Portability wrapper for `strlcpy()` that uses the system implementation if available */
|
||||
size_t tr_strlcpy(void* dst, void const* src, size_t siz);
|
||||
|
||||
|
|
|
@ -679,23 +679,28 @@ static void setGroup(tr_variant* args, std::string_view group)
|
|||
tr_variantDictAddStrView(args, TR_KEY_group, group);
|
||||
}
|
||||
|
||||
static void addFiles(tr_variant* args, tr_quark const key, char const* arg)
|
||||
[[nodiscard]] auto make_files_list(char const* const str_in)
|
||||
{
|
||||
tr_variant* files = tr_variantDictAddList(args, key, 100);
|
||||
auto str = std::string_view{ str_in != nullptr ? str_in : "" };
|
||||
|
||||
if (tr_str_is_empty(arg))
|
||||
if (std::empty(str))
|
||||
{
|
||||
fmt::print(stderr, "No files specified!\n");
|
||||
arg = "-1"; /* no file will have this index, so should be a no-op */
|
||||
str = "-1"sv; // no file will have this index, so should be a no-op
|
||||
}
|
||||
|
||||
if (strcmp(arg, "all") != 0)
|
||||
auto files = tr_variant::Vector{};
|
||||
|
||||
if (str != "all"sv)
|
||||
{
|
||||
for (auto const& idx : tr_num_parse_range(arg))
|
||||
files.reserve(100U);
|
||||
for (auto const& idx : tr_num_parse_range(str))
|
||||
{
|
||||
tr_variantListAddInt(files, idx);
|
||||
files.emplace_back(idx);
|
||||
}
|
||||
}
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
|
@ -2935,11 +2940,11 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv, Re
|
|||
switch (c)
|
||||
{
|
||||
case 'g':
|
||||
addFiles(args, TR_KEY_files_wanted, optarg);
|
||||
*tr_variantDictAdd(args, TR_KEY_files_wanted) = make_files_list(optarg);
|
||||
break;
|
||||
|
||||
case 'G':
|
||||
addFiles(args, TR_KEY_files_unwanted, optarg);
|
||||
*tr_variantDictAdd(args, TR_KEY_files_unwanted) = make_files_list(optarg);
|
||||
break;
|
||||
|
||||
case 'L':
|
||||
|
@ -2955,15 +2960,15 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv, Re
|
|||
break;
|
||||
|
||||
case 900:
|
||||
addFiles(args, TR_KEY_priority_high, optarg);
|
||||
*tr_variantDictAdd(args, TR_KEY_priority_high) = make_files_list(optarg);
|
||||
break;
|
||||
|
||||
case 901:
|
||||
addFiles(args, TR_KEY_priority_normal, optarg);
|
||||
*tr_variantDictAdd(args, TR_KEY_priority_normal) = make_files_list(optarg);
|
||||
break;
|
||||
|
||||
case 902:
|
||||
addFiles(args, TR_KEY_priority_low, optarg);
|
||||
*tr_variantDictAdd(args, TR_KEY_priority_low) = make_files_list(optarg);
|
||||
break;
|
||||
|
||||
case 700:
|
||||
|
|
Loading…
Reference in a new issue