tr_quark_new() now takes a std::string_view (#1961)
This commit is contained in:
parent
c98b4d33c3
commit
567f1e48c8
|
@ -9,6 +9,8 @@
|
|||
#include <errno.h>
|
||||
#include <stdio.h> /* printf */
|
||||
#include <stdlib.h> /* atoi */
|
||||
#include <string_view>
|
||||
#include <typeinfo>
|
||||
|
||||
#ifdef HAVE_SYSLOG
|
||||
#include <syslog.h>
|
||||
|
@ -33,6 +35,8 @@
|
|||
#include <libtransmission/version.h>
|
||||
#include <libtransmission/watchdir.h>
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
#ifdef USE_SYSTEMD
|
||||
|
||||
#include <systemd/sd-daemon.h>
|
||||
|
@ -883,8 +887,8 @@ EXIT_EARLY:
|
|||
|
||||
int tr_main(int argc, char* argv[])
|
||||
{
|
||||
key_pidfile = tr_quark_new("pidfile", TR_BAD_SIZE);
|
||||
key_watch_dir_force_generic = tr_quark_new("watch-dir-force-generic", TR_BAD_SIZE);
|
||||
key_pidfile = tr_quark_new("pidfile"sv);
|
||||
key_watch_dir_force_generic = tr_quark_new("watch-dir-force-generic"sv);
|
||||
|
||||
struct daemon_data data;
|
||||
bool foreground;
|
||||
|
|
|
@ -61,9 +61,11 @@ static void toggle_pref_cb(GtkToggleAction* action, gpointer user_data)
|
|||
TR_UNUSED(user_data);
|
||||
|
||||
char const* key = gtk_action_get_name(GTK_ACTION(action));
|
||||
gboolean const val = gtk_toggle_action_get_active(action);
|
||||
|
||||
gtr_core_set_pref_bool(myCore, tr_quark_new(key, TR_BAD_SIZE), val);
|
||||
if (key != nullptr)
|
||||
{
|
||||
gboolean const val = gtk_toggle_action_get_active(action);
|
||||
gtr_core_set_pref_bool(myCore, tr_quark_new(key), val);
|
||||
}
|
||||
}
|
||||
|
||||
static GtkToggleActionEntry pref_toggle_entries[] = {
|
||||
|
@ -245,7 +247,7 @@ void gtr_actions_init(GtkUIManager* ui_manager, gpointer callback_user_data)
|
|||
|
||||
for (size_t i = 0; i < G_N_ELEMENTS(pref_toggle_entries); ++i)
|
||||
{
|
||||
pref_toggle_entries[i].is_active = gtr_pref_flag_get(tr_quark_new(pref_toggle_entries[i].name, TR_BAD_SIZE));
|
||||
pref_toggle_entries[i].is_active = gtr_pref_flag_get(tr_quark_new(pref_toggle_entries[i].name));
|
||||
}
|
||||
|
||||
gtk_action_group_add_toggle_actions(
|
||||
|
|
|
@ -37,7 +37,7 @@ static GSList* get_recent_destinations(void)
|
|||
char const* val;
|
||||
g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1);
|
||||
|
||||
if ((val = gtr_pref_string_get(tr_quark_new(key, TR_BAD_SIZE))) != nullptr)
|
||||
if ((val = gtr_pref_string_get(tr_quark_new(key))) != nullptr)
|
||||
{
|
||||
list = g_slist_append(list, (void*)val);
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ static void save_recent_destination(TrCore* core, char const* dir)
|
|||
{
|
||||
char key[64];
|
||||
g_snprintf(key, sizeof(key), "recent-download-dir-%d", i + 1);
|
||||
gtr_pref_string_set(tr_quark_new(key, TR_BAD_SIZE), static_cast<char const*>(l->data));
|
||||
gtr_pref_string_set(tr_quark_new(key), static_cast<char const*>(l->data));
|
||||
}
|
||||
|
||||
gtr_pref_save(gtr_core_session(core));
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include <array>
|
||||
#include <string.h> /* strlen() */
|
||||
#include <string_view>
|
||||
#include <typeinfo>
|
||||
|
||||
#include <event2/buffer.h>
|
||||
|
||||
|
@ -24,6 +25,8 @@
|
|||
#include "utils.h"
|
||||
#include "variant.h"
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
@ -109,8 +112,8 @@ char* tr_metainfo_sanitize_path_component(char const* str, size_t len, bool* is_
|
|||
/* https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file */
|
||||
char const* const reserved_chars = "<>:\"/\\|?*";
|
||||
auto constexpr ReservedNames = std::array<std::string_view, 22>{
|
||||
"CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7",
|
||||
"COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9",
|
||||
"CON"sv, "PRN"sv, "AUX"sv, "NUL"sv, "COM1"sv, "COM2"sv, "COM3"sv, "COM4"sv, "COM5"sv, "COM6"sv, "COM7"sv,
|
||||
"COM8"sv, "COM9"sv, "LPT1"sv, "LPT2"sv, "LPT3"sv, "LPT4"sv, "LPT5"sv, "LPT6"sv, "LPT7"sv, "LPT8"sv, "LPT9"sv,
|
||||
};
|
||||
|
||||
char* const ret = tr_new(char, len + 2);
|
||||
|
|
|
@ -2019,7 +2019,7 @@ static bool myHandshakeDoneCB(
|
|||
if (peer_id != nullptr)
|
||||
{
|
||||
char buf[128];
|
||||
client = tr_quark_new(tr_clientForId(buf, sizeof(buf), peer_id), TR_BAD_SIZE);
|
||||
client = tr_quark_new(tr_clientForId(buf, sizeof(buf), peer_id));
|
||||
}
|
||||
|
||||
/* this steals its refcount too, which is balanced by our unref in peerDelete() */
|
||||
|
|
|
@ -996,7 +996,7 @@ static void sendLtepHandshake(tr_peerMsgsImpl* msgs)
|
|||
|
||||
if (version_quark == 0)
|
||||
{
|
||||
version_quark = tr_quark_new(TR_NAME " " USERAGENT_PREFIX, TR_BAD_SIZE);
|
||||
version_quark = tr_quark_new(TR_NAME " " USERAGENT_PREFIX);
|
||||
}
|
||||
|
||||
dbgmsg(msgs, "sending an ltep handshake");
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <cstring> // strlen()
|
||||
#include <iterator>
|
||||
#include <string_view>
|
||||
#include <typeinfo>
|
||||
#include <vector>
|
||||
|
||||
#include "transmission.h"
|
||||
|
@ -18,399 +19,401 @@
|
|||
#include "tr-assert.h"
|
||||
#include "utils.h" // tr_strndup()
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
auto constexpr my_static = std::array<std::string_view, 391>{ "",
|
||||
"activeTorrentCount",
|
||||
"activity-date",
|
||||
"activityDate",
|
||||
"added",
|
||||
"added-date",
|
||||
"added.f",
|
||||
"added6",
|
||||
"added6.f",
|
||||
"addedDate",
|
||||
"address",
|
||||
"alt-speed-down",
|
||||
"alt-speed-enabled",
|
||||
"alt-speed-time-begin",
|
||||
"alt-speed-time-day",
|
||||
"alt-speed-time-enabled",
|
||||
"alt-speed-time-end",
|
||||
"alt-speed-up",
|
||||
"announce",
|
||||
"announce-list",
|
||||
"announceState",
|
||||
"anti-brute-force-enabled",
|
||||
"anti-brute-force-threshold",
|
||||
"arguments",
|
||||
"bandwidth-priority",
|
||||
"bandwidthPriority",
|
||||
"bind-address-ipv4",
|
||||
"bind-address-ipv6",
|
||||
"bitfield",
|
||||
"blocklist-date",
|
||||
"blocklist-enabled",
|
||||
"blocklist-size",
|
||||
"blocklist-updates-enabled",
|
||||
"blocklist-url",
|
||||
"blocks",
|
||||
"bytesCompleted",
|
||||
"cache-size-mb",
|
||||
"clientIsChoked",
|
||||
"clientIsInterested",
|
||||
"clientName",
|
||||
"comment",
|
||||
"comment_utf_8",
|
||||
"compact-view",
|
||||
"complete",
|
||||
"config-dir",
|
||||
"cookies",
|
||||
"corrupt",
|
||||
"corruptEver",
|
||||
"created by",
|
||||
"created by.utf-8",
|
||||
"creation date",
|
||||
"creator",
|
||||
"cumulative-stats",
|
||||
"current-stats",
|
||||
"date",
|
||||
"dateCreated",
|
||||
"delete-local-data",
|
||||
"desiredAvailable",
|
||||
"destination",
|
||||
"details-window-height",
|
||||
"details-window-width",
|
||||
"dht-enabled",
|
||||
"display-name",
|
||||
"dnd",
|
||||
"done-date",
|
||||
"doneDate",
|
||||
"download-dir",
|
||||
"download-dir-free-space",
|
||||
"download-queue-enabled",
|
||||
"download-queue-size",
|
||||
"downloadCount",
|
||||
"downloadDir",
|
||||
"downloadLimit",
|
||||
"downloadLimited",
|
||||
"downloadSpeed",
|
||||
"downloaded",
|
||||
"downloaded-bytes",
|
||||
"downloadedBytes",
|
||||
"downloadedEver",
|
||||
"downloaders",
|
||||
"downloading-time-seconds",
|
||||
"dropped",
|
||||
"dropped6",
|
||||
"e",
|
||||
"editDate",
|
||||
"encoding",
|
||||
"encryption",
|
||||
"error",
|
||||
"errorString",
|
||||
"eta",
|
||||
"etaIdle",
|
||||
"failure reason",
|
||||
"fields",
|
||||
"file-count",
|
||||
"fileStats",
|
||||
"filename",
|
||||
"files",
|
||||
"files-added",
|
||||
"files-unwanted",
|
||||
"files-wanted",
|
||||
"filesAdded",
|
||||
"filter-mode",
|
||||
"filter-text",
|
||||
"filter-trackers",
|
||||
"flagStr",
|
||||
"flags",
|
||||
"format",
|
||||
"fromCache",
|
||||
"fromDht",
|
||||
"fromIncoming",
|
||||
"fromLpd",
|
||||
"fromLtep",
|
||||
"fromPex",
|
||||
"fromTracker",
|
||||
"hasAnnounced",
|
||||
"hasScraped",
|
||||
"hashString",
|
||||
"have",
|
||||
"haveUnchecked",
|
||||
"haveValid",
|
||||
"honorsSessionLimits",
|
||||
"host",
|
||||
"id",
|
||||
"idle-limit",
|
||||
"idle-mode",
|
||||
"idle-seeding-limit",
|
||||
"idle-seeding-limit-enabled",
|
||||
"ids",
|
||||
"incomplete",
|
||||
"incomplete-dir",
|
||||
"incomplete-dir-enabled",
|
||||
"info",
|
||||
"info_hash",
|
||||
"inhibit-desktop-hibernation",
|
||||
"interval",
|
||||
"ip",
|
||||
"ipv4",
|
||||
"ipv6",
|
||||
"isBackup",
|
||||
"isDownloadingFrom",
|
||||
"isEncrypted",
|
||||
"isFinished",
|
||||
"isIncoming",
|
||||
"isPrivate",
|
||||
"isStalled",
|
||||
"isUTP",
|
||||
"isUploadingTo",
|
||||
"labels",
|
||||
"lastAnnouncePeerCount",
|
||||
"lastAnnounceResult",
|
||||
"lastAnnounceStartTime",
|
||||
"lastAnnounceSucceeded",
|
||||
"lastAnnounceTime",
|
||||
"lastAnnounceTimedOut",
|
||||
"lastScrapeResult",
|
||||
"lastScrapeStartTime",
|
||||
"lastScrapeSucceeded",
|
||||
"lastScrapeTime",
|
||||
"lastScrapeTimedOut",
|
||||
"leecherCount",
|
||||
"leftUntilDone",
|
||||
"length",
|
||||
"location",
|
||||
"lpd-enabled",
|
||||
"m",
|
||||
"magnet-info",
|
||||
"magnetLink",
|
||||
"main-window-height",
|
||||
"main-window-is-maximized",
|
||||
"main-window-layout-order",
|
||||
"main-window-width",
|
||||
"main-window-x",
|
||||
"main-window-y",
|
||||
"manualAnnounceTime",
|
||||
"max-peers",
|
||||
"maxConnectedPeers",
|
||||
"memory-bytes",
|
||||
"memory-units",
|
||||
"message-level",
|
||||
"metadataPercentComplete",
|
||||
"metadata_size",
|
||||
"metainfo",
|
||||
"method",
|
||||
"min interval",
|
||||
"min_request_interval",
|
||||
"move",
|
||||
"msg_type",
|
||||
"mtimes",
|
||||
"name",
|
||||
"name.utf-8",
|
||||
"nextAnnounceTime",
|
||||
"nextScrapeTime",
|
||||
"nodes",
|
||||
"nodes6",
|
||||
"open-dialog-dir",
|
||||
"p",
|
||||
"path",
|
||||
"path.utf-8",
|
||||
"paused",
|
||||
"pausedTorrentCount",
|
||||
"peer-congestion-algorithm",
|
||||
"peer-id-ttl-hours",
|
||||
"peer-limit",
|
||||
"peer-limit-global",
|
||||
"peer-limit-per-torrent",
|
||||
"peer-port",
|
||||
"peer-port-random-high",
|
||||
"peer-port-random-low",
|
||||
"peer-port-random-on-start",
|
||||
"peer-socket-tos",
|
||||
"peerIsChoked",
|
||||
"peerIsInterested",
|
||||
"peers",
|
||||
"peers2",
|
||||
"peers2-6",
|
||||
"peers6",
|
||||
"peersConnected",
|
||||
"peersFrom",
|
||||
"peersGettingFromUs",
|
||||
"peersSendingToUs",
|
||||
"percentDone",
|
||||
"pex-enabled",
|
||||
"piece",
|
||||
"piece length",
|
||||
"pieceCount",
|
||||
"pieceSize",
|
||||
"pieces",
|
||||
"play-download-complete-sound",
|
||||
"port",
|
||||
"port-forwarding-enabled",
|
||||
"port-is-open",
|
||||
"preallocation",
|
||||
"prefetch-enabled",
|
||||
"primary-mime-type",
|
||||
"priorities",
|
||||
"priority",
|
||||
"priority-high",
|
||||
"priority-low",
|
||||
"priority-normal",
|
||||
"private",
|
||||
"progress",
|
||||
"prompt-before-exit",
|
||||
"queue-move-bottom",
|
||||
"queue-move-down",
|
||||
"queue-move-top",
|
||||
"queue-move-up",
|
||||
"queue-stalled-enabled",
|
||||
"queue-stalled-minutes",
|
||||
"queuePosition",
|
||||
"rateDownload",
|
||||
"rateToClient",
|
||||
"rateToPeer",
|
||||
"rateUpload",
|
||||
"ratio-limit",
|
||||
"ratio-limit-enabled",
|
||||
"ratio-mode",
|
||||
"recent-download-dir-1",
|
||||
"recent-download-dir-2",
|
||||
"recent-download-dir-3",
|
||||
"recent-download-dir-4",
|
||||
"recheckProgress",
|
||||
"remote-session-enabled",
|
||||
"remote-session-host",
|
||||
"remote-session-password",
|
||||
"remote-session-port",
|
||||
"remote-session-requres-authentication",
|
||||
"remote-session-username",
|
||||
"removed",
|
||||
"rename-partial-files",
|
||||
"reqq",
|
||||
"result",
|
||||
"rpc-authentication-required",
|
||||
"rpc-bind-address",
|
||||
"rpc-enabled",
|
||||
"rpc-host-whitelist",
|
||||
"rpc-host-whitelist-enabled",
|
||||
"rpc-password",
|
||||
"rpc-port",
|
||||
"rpc-url",
|
||||
"rpc-username",
|
||||
"rpc-version",
|
||||
"rpc-version-minimum",
|
||||
"rpc-version-semver",
|
||||
"rpc-whitelist",
|
||||
"rpc-whitelist-enabled",
|
||||
"scrape",
|
||||
"scrape-paused-torrents-enabled",
|
||||
"scrapeState",
|
||||
"script-torrent-added-enabled",
|
||||
"script-torrent-added-filename",
|
||||
"script-torrent-done-enabled",
|
||||
"script-torrent-done-filename",
|
||||
"seconds-active",
|
||||
"secondsActive",
|
||||
"secondsDownloading",
|
||||
"secondsSeeding",
|
||||
"seed-queue-enabled",
|
||||
"seed-queue-size",
|
||||
"seedIdleLimit",
|
||||
"seedIdleMode",
|
||||
"seedRatioLimit",
|
||||
"seedRatioLimited",
|
||||
"seedRatioMode",
|
||||
"seederCount",
|
||||
"seeding-time-seconds",
|
||||
"session-count",
|
||||
"session-id",
|
||||
"sessionCount",
|
||||
"show-backup-trackers",
|
||||
"show-extra-peer-details",
|
||||
"show-filterbar",
|
||||
"show-notification-area-icon",
|
||||
"show-options-window",
|
||||
"show-statusbar",
|
||||
"show-toolbar",
|
||||
"show-tracker-scrapes",
|
||||
"size-bytes",
|
||||
"size-units",
|
||||
"sizeWhenDone",
|
||||
"sort-mode",
|
||||
"sort-reversed",
|
||||
"speed",
|
||||
"speed-Bps",
|
||||
"speed-bytes",
|
||||
"speed-limit-down",
|
||||
"speed-limit-down-enabled",
|
||||
"speed-limit-up",
|
||||
"speed-limit-up-enabled",
|
||||
"speed-units",
|
||||
"start-added-torrents",
|
||||
"start-minimized",
|
||||
"startDate",
|
||||
"status",
|
||||
"statusbar-stats",
|
||||
"tag",
|
||||
"tier",
|
||||
"time-checked",
|
||||
"torrent-added",
|
||||
"torrent-added-notification-command",
|
||||
"torrent-added-notification-enabled",
|
||||
"torrent-complete-notification-command",
|
||||
"torrent-complete-notification-enabled",
|
||||
"torrent-complete-sound-command",
|
||||
"torrent-complete-sound-enabled",
|
||||
"torrent-duplicate",
|
||||
"torrent-get",
|
||||
"torrent-set",
|
||||
"torrent-set-location",
|
||||
"torrentCount",
|
||||
"torrentFile",
|
||||
"torrents",
|
||||
"totalSize",
|
||||
"total_size",
|
||||
"tracker id",
|
||||
"trackerAdd",
|
||||
"trackerRemove",
|
||||
"trackerReplace",
|
||||
"trackerStats",
|
||||
"trackers",
|
||||
"trash-can-enabled",
|
||||
"trash-original-torrent-files",
|
||||
"umask",
|
||||
"units",
|
||||
"upload-slots-per-torrent",
|
||||
"uploadLimit",
|
||||
"uploadLimited",
|
||||
"uploadRatio",
|
||||
"uploadSpeed",
|
||||
"upload_only",
|
||||
"uploaded",
|
||||
"uploaded-bytes",
|
||||
"uploadedBytes",
|
||||
"uploadedEver",
|
||||
"url-list",
|
||||
"use-global-speed-limit",
|
||||
"use-speed-limit",
|
||||
"user-has-given-informed-consent",
|
||||
"ut_comment",
|
||||
"ut_holepunch",
|
||||
"ut_metadata",
|
||||
"ut_pex",
|
||||
"ut_recommend",
|
||||
"utp-enabled",
|
||||
"v",
|
||||
"version",
|
||||
"wanted",
|
||||
"warning message",
|
||||
"watch-dir",
|
||||
"watch-dir-enabled",
|
||||
"webseeds",
|
||||
auto constexpr my_static = std::array<std::string_view, 391>{ ""sv,
|
||||
"activeTorrentCount"sv,
|
||||
"activity-date"sv,
|
||||
"activityDate"sv,
|
||||
"added"sv,
|
||||
"added-date"sv,
|
||||
"added.f"sv,
|
||||
"added6"sv,
|
||||
"added6.f"sv,
|
||||
"addedDate"sv,
|
||||
"address"sv,
|
||||
"alt-speed-down"sv,
|
||||
"alt-speed-enabled"sv,
|
||||
"alt-speed-time-begin"sv,
|
||||
"alt-speed-time-day"sv,
|
||||
"alt-speed-time-enabled"sv,
|
||||
"alt-speed-time-end"sv,
|
||||
"alt-speed-up"sv,
|
||||
"announce"sv,
|
||||
"announce-list"sv,
|
||||
"announceState"sv,
|
||||
"anti-brute-force-enabled"sv,
|
||||
"anti-brute-force-threshold"sv,
|
||||
"arguments"sv,
|
||||
"bandwidth-priority"sv,
|
||||
"bandwidthPriority"sv,
|
||||
"bind-address-ipv4"sv,
|
||||
"bind-address-ipv6"sv,
|
||||
"bitfield"sv,
|
||||
"blocklist-date"sv,
|
||||
"blocklist-enabled"sv,
|
||||
"blocklist-size"sv,
|
||||
"blocklist-updates-enabled"sv,
|
||||
"blocklist-url"sv,
|
||||
"blocks"sv,
|
||||
"bytesCompleted"sv,
|
||||
"cache-size-mb"sv,
|
||||
"clientIsChoked"sv,
|
||||
"clientIsInterested"sv,
|
||||
"clientName"sv,
|
||||
"comment"sv,
|
||||
"comment_utf_8"sv,
|
||||
"compact-view"sv,
|
||||
"complete"sv,
|
||||
"config-dir"sv,
|
||||
"cookies"sv,
|
||||
"corrupt"sv,
|
||||
"corruptEver"sv,
|
||||
"created by"sv,
|
||||
"created by.utf-8"sv,
|
||||
"creation date"sv,
|
||||
"creator"sv,
|
||||
"cumulative-stats"sv,
|
||||
"current-stats"sv,
|
||||
"date"sv,
|
||||
"dateCreated"sv,
|
||||
"delete-local-data"sv,
|
||||
"desiredAvailable"sv,
|
||||
"destination"sv,
|
||||
"details-window-height"sv,
|
||||
"details-window-width"sv,
|
||||
"dht-enabled"sv,
|
||||
"display-name"sv,
|
||||
"dnd"sv,
|
||||
"done-date"sv,
|
||||
"doneDate"sv,
|
||||
"download-dir"sv,
|
||||
"download-dir-free-space"sv,
|
||||
"download-queue-enabled"sv,
|
||||
"download-queue-size"sv,
|
||||
"downloadCount"sv,
|
||||
"downloadDir"sv,
|
||||
"downloadLimit"sv,
|
||||
"downloadLimited"sv,
|
||||
"downloadSpeed"sv,
|
||||
"downloaded"sv,
|
||||
"downloaded-bytes"sv,
|
||||
"downloadedBytes"sv,
|
||||
"downloadedEver"sv,
|
||||
"downloaders"sv,
|
||||
"downloading-time-seconds"sv,
|
||||
"dropped"sv,
|
||||
"dropped6"sv,
|
||||
"e"sv,
|
||||
"editDate"sv,
|
||||
"encoding"sv,
|
||||
"encryption"sv,
|
||||
"error"sv,
|
||||
"errorString"sv,
|
||||
"eta"sv,
|
||||
"etaIdle"sv,
|
||||
"failure reason"sv,
|
||||
"fields"sv,
|
||||
"file-count"sv,
|
||||
"fileStats"sv,
|
||||
"filename"sv,
|
||||
"files"sv,
|
||||
"files-added"sv,
|
||||
"files-unwanted"sv,
|
||||
"files-wanted"sv,
|
||||
"filesAdded"sv,
|
||||
"filter-mode"sv,
|
||||
"filter-text"sv,
|
||||
"filter-trackers"sv,
|
||||
"flagStr"sv,
|
||||
"flags"sv,
|
||||
"format"sv,
|
||||
"fromCache"sv,
|
||||
"fromDht"sv,
|
||||
"fromIncoming"sv,
|
||||
"fromLpd"sv,
|
||||
"fromLtep"sv,
|
||||
"fromPex"sv,
|
||||
"fromTracker"sv,
|
||||
"hasAnnounced"sv,
|
||||
"hasScraped"sv,
|
||||
"hashString"sv,
|
||||
"have"sv,
|
||||
"haveUnchecked"sv,
|
||||
"haveValid"sv,
|
||||
"honorsSessionLimits"sv,
|
||||
"host"sv,
|
||||
"id"sv,
|
||||
"idle-limit"sv,
|
||||
"idle-mode"sv,
|
||||
"idle-seeding-limit"sv,
|
||||
"idle-seeding-limit-enabled"sv,
|
||||
"ids"sv,
|
||||
"incomplete"sv,
|
||||
"incomplete-dir"sv,
|
||||
"incomplete-dir-enabled"sv,
|
||||
"info"sv,
|
||||
"info_hash"sv,
|
||||
"inhibit-desktop-hibernation"sv,
|
||||
"interval"sv,
|
||||
"ip"sv,
|
||||
"ipv4"sv,
|
||||
"ipv6"sv,
|
||||
"isBackup"sv,
|
||||
"isDownloadingFrom"sv,
|
||||
"isEncrypted"sv,
|
||||
"isFinished"sv,
|
||||
"isIncoming"sv,
|
||||
"isPrivate"sv,
|
||||
"isStalled"sv,
|
||||
"isUTP"sv,
|
||||
"isUploadingTo"sv,
|
||||
"labels"sv,
|
||||
"lastAnnouncePeerCount"sv,
|
||||
"lastAnnounceResult"sv,
|
||||
"lastAnnounceStartTime"sv,
|
||||
"lastAnnounceSucceeded"sv,
|
||||
"lastAnnounceTime"sv,
|
||||
"lastAnnounceTimedOut"sv,
|
||||
"lastScrapeResult"sv,
|
||||
"lastScrapeStartTime"sv,
|
||||
"lastScrapeSucceeded"sv,
|
||||
"lastScrapeTime"sv,
|
||||
"lastScrapeTimedOut"sv,
|
||||
"leecherCount"sv,
|
||||
"leftUntilDone"sv,
|
||||
"length"sv,
|
||||
"location"sv,
|
||||
"lpd-enabled"sv,
|
||||
"m"sv,
|
||||
"magnet-info"sv,
|
||||
"magnetLink"sv,
|
||||
"main-window-height"sv,
|
||||
"main-window-is-maximized"sv,
|
||||
"main-window-layout-order"sv,
|
||||
"main-window-width"sv,
|
||||
"main-window-x"sv,
|
||||
"main-window-y"sv,
|
||||
"manualAnnounceTime"sv,
|
||||
"max-peers"sv,
|
||||
"maxConnectedPeers"sv,
|
||||
"memory-bytes"sv,
|
||||
"memory-units"sv,
|
||||
"message-level"sv,
|
||||
"metadataPercentComplete"sv,
|
||||
"metadata_size"sv,
|
||||
"metainfo"sv,
|
||||
"method"sv,
|
||||
"min interval"sv,
|
||||
"min_request_interval"sv,
|
||||
"move"sv,
|
||||
"msg_type"sv,
|
||||
"mtimes"sv,
|
||||
"name"sv,
|
||||
"name.utf-8"sv,
|
||||
"nextAnnounceTime"sv,
|
||||
"nextScrapeTime"sv,
|
||||
"nodes"sv,
|
||||
"nodes6"sv,
|
||||
"open-dialog-dir"sv,
|
||||
"p"sv,
|
||||
"path"sv,
|
||||
"path.utf-8"sv,
|
||||
"paused"sv,
|
||||
"pausedTorrentCount"sv,
|
||||
"peer-congestion-algorithm"sv,
|
||||
"peer-id-ttl-hours"sv,
|
||||
"peer-limit"sv,
|
||||
"peer-limit-global"sv,
|
||||
"peer-limit-per-torrent"sv,
|
||||
"peer-port"sv,
|
||||
"peer-port-random-high"sv,
|
||||
"peer-port-random-low"sv,
|
||||
"peer-port-random-on-start"sv,
|
||||
"peer-socket-tos"sv,
|
||||
"peerIsChoked"sv,
|
||||
"peerIsInterested"sv,
|
||||
"peers"sv,
|
||||
"peers2"sv,
|
||||
"peers2-6"sv,
|
||||
"peers6"sv,
|
||||
"peersConnected"sv,
|
||||
"peersFrom"sv,
|
||||
"peersGettingFromUs"sv,
|
||||
"peersSendingToUs"sv,
|
||||
"percentDone"sv,
|
||||
"pex-enabled"sv,
|
||||
"piece"sv,
|
||||
"piece length"sv,
|
||||
"pieceCount"sv,
|
||||
"pieceSize"sv,
|
||||
"pieces"sv,
|
||||
"play-download-complete-sound"sv,
|
||||
"port"sv,
|
||||
"port-forwarding-enabled"sv,
|
||||
"port-is-open"sv,
|
||||
"preallocation"sv,
|
||||
"prefetch-enabled"sv,
|
||||
"primary-mime-type"sv,
|
||||
"priorities"sv,
|
||||
"priority"sv,
|
||||
"priority-high"sv,
|
||||
"priority-low"sv,
|
||||
"priority-normal"sv,
|
||||
"private"sv,
|
||||
"progress"sv,
|
||||
"prompt-before-exit"sv,
|
||||
"queue-move-bottom"sv,
|
||||
"queue-move-down"sv,
|
||||
"queue-move-top"sv,
|
||||
"queue-move-up"sv,
|
||||
"queue-stalled-enabled"sv,
|
||||
"queue-stalled-minutes"sv,
|
||||
"queuePosition"sv,
|
||||
"rateDownload"sv,
|
||||
"rateToClient"sv,
|
||||
"rateToPeer"sv,
|
||||
"rateUpload"sv,
|
||||
"ratio-limit"sv,
|
||||
"ratio-limit-enabled"sv,
|
||||
"ratio-mode"sv,
|
||||
"recent-download-dir-1"sv,
|
||||
"recent-download-dir-2"sv,
|
||||
"recent-download-dir-3"sv,
|
||||
"recent-download-dir-4"sv,
|
||||
"recheckProgress"sv,
|
||||
"remote-session-enabled"sv,
|
||||
"remote-session-host"sv,
|
||||
"remote-session-password"sv,
|
||||
"remote-session-port"sv,
|
||||
"remote-session-requres-authentication"sv,
|
||||
"remote-session-username"sv,
|
||||
"removed"sv,
|
||||
"rename-partial-files"sv,
|
||||
"reqq"sv,
|
||||
"result"sv,
|
||||
"rpc-authentication-required"sv,
|
||||
"rpc-bind-address"sv,
|
||||
"rpc-enabled"sv,
|
||||
"rpc-host-whitelist"sv,
|
||||
"rpc-host-whitelist-enabled"sv,
|
||||
"rpc-password"sv,
|
||||
"rpc-port"sv,
|
||||
"rpc-url"sv,
|
||||
"rpc-username"sv,
|
||||
"rpc-version"sv,
|
||||
"rpc-version-minimum"sv,
|
||||
"rpc-version-semver"sv,
|
||||
"rpc-whitelist"sv,
|
||||
"rpc-whitelist-enabled"sv,
|
||||
"scrape"sv,
|
||||
"scrape-paused-torrents-enabled"sv,
|
||||
"scrapeState"sv,
|
||||
"script-torrent-added-enabled"sv,
|
||||
"script-torrent-added-filename"sv,
|
||||
"script-torrent-done-enabled"sv,
|
||||
"script-torrent-done-filename"sv,
|
||||
"seconds-active"sv,
|
||||
"secondsActive"sv,
|
||||
"secondsDownloading"sv,
|
||||
"secondsSeeding"sv,
|
||||
"seed-queue-enabled"sv,
|
||||
"seed-queue-size"sv,
|
||||
"seedIdleLimit"sv,
|
||||
"seedIdleMode"sv,
|
||||
"seedRatioLimit"sv,
|
||||
"seedRatioLimited"sv,
|
||||
"seedRatioMode"sv,
|
||||
"seederCount"sv,
|
||||
"seeding-time-seconds"sv,
|
||||
"session-count"sv,
|
||||
"session-id"sv,
|
||||
"sessionCount"sv,
|
||||
"show-backup-trackers"sv,
|
||||
"show-extra-peer-details"sv,
|
||||
"show-filterbar"sv,
|
||||
"show-notification-area-icon"sv,
|
||||
"show-options-window"sv,
|
||||
"show-statusbar"sv,
|
||||
"show-toolbar"sv,
|
||||
"show-tracker-scrapes"sv,
|
||||
"size-bytes"sv,
|
||||
"size-units"sv,
|
||||
"sizeWhenDone"sv,
|
||||
"sort-mode"sv,
|
||||
"sort-reversed"sv,
|
||||
"speed"sv,
|
||||
"speed-Bps"sv,
|
||||
"speed-bytes"sv,
|
||||
"speed-limit-down"sv,
|
||||
"speed-limit-down-enabled"sv,
|
||||
"speed-limit-up"sv,
|
||||
"speed-limit-up-enabled"sv,
|
||||
"speed-units"sv,
|
||||
"start-added-torrents"sv,
|
||||
"start-minimized"sv,
|
||||
"startDate"sv,
|
||||
"status"sv,
|
||||
"statusbar-stats"sv,
|
||||
"tag"sv,
|
||||
"tier"sv,
|
||||
"time-checked"sv,
|
||||
"torrent-added"sv,
|
||||
"torrent-added-notification-command"sv,
|
||||
"torrent-added-notification-enabled"sv,
|
||||
"torrent-complete-notification-command"sv,
|
||||
"torrent-complete-notification-enabled"sv,
|
||||
"torrent-complete-sound-command"sv,
|
||||
"torrent-complete-sound-enabled"sv,
|
||||
"torrent-duplicate"sv,
|
||||
"torrent-get"sv,
|
||||
"torrent-set"sv,
|
||||
"torrent-set-location"sv,
|
||||
"torrentCount"sv,
|
||||
"torrentFile"sv,
|
||||
"torrents"sv,
|
||||
"totalSize"sv,
|
||||
"total_size"sv,
|
||||
"tracker id"sv,
|
||||
"trackerAdd"sv,
|
||||
"trackerRemove"sv,
|
||||
"trackerReplace"sv,
|
||||
"trackerStats"sv,
|
||||
"trackers"sv,
|
||||
"trash-can-enabled"sv,
|
||||
"trash-original-torrent-files"sv,
|
||||
"umask"sv,
|
||||
"units"sv,
|
||||
"upload-slots-per-torrent"sv,
|
||||
"uploadLimit"sv,
|
||||
"uploadLimited"sv,
|
||||
"uploadRatio"sv,
|
||||
"uploadSpeed"sv,
|
||||
"upload_only"sv,
|
||||
"uploaded"sv,
|
||||
"uploaded-bytes"sv,
|
||||
"uploadedBytes"sv,
|
||||
"uploadedEver"sv,
|
||||
"url-list"sv,
|
||||
"use-global-speed-limit"sv,
|
||||
"use-speed-limit"sv,
|
||||
"user-has-given-informed-consent"sv,
|
||||
"ut_comment"sv,
|
||||
"ut_holepunch"sv,
|
||||
"ut_metadata"sv,
|
||||
"ut_pex"sv,
|
||||
"ut_recommend"sv,
|
||||
"utp-enabled"sv,
|
||||
"v"sv,
|
||||
"version"sv,
|
||||
"wanted"sv,
|
||||
"warning message"sv,
|
||||
"watch-dir"sv,
|
||||
"watch-dir-enabled"sv,
|
||||
"webseeds"sv,
|
||||
"webseedsSendingToUs" };
|
||||
|
||||
size_t constexpr quarks_are_sorted = ( //
|
||||
|
@ -460,22 +463,14 @@ bool tr_quark_lookup(void const* str, size_t len, tr_quark* setme)
|
|||
return false;
|
||||
}
|
||||
|
||||
tr_quark tr_quark_new(void const* str, size_t len)
|
||||
tr_quark tr_quark_new(std::string_view str)
|
||||
{
|
||||
tr_quark ret = TR_KEY_NONE;
|
||||
|
||||
if (str != nullptr)
|
||||
if (!tr_quark_lookup(std::data(str), std::size(str), &ret))
|
||||
{
|
||||
if (len == TR_BAD_SIZE)
|
||||
{
|
||||
len = strlen(static_cast<char const*>(str));
|
||||
}
|
||||
|
||||
if (!tr_quark_lookup(str, len, &ret))
|
||||
{
|
||||
ret = TR_N_KEYS + std::size(my_runtime);
|
||||
my_runtime.emplace_back(tr_strndup(str, len), len);
|
||||
}
|
||||
ret = TR_N_KEYS + std::size(my_runtime);
|
||||
my_runtime.emplace_back(tr_strndup(std::data(str), std::size(str)), std::size(str));
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef> // size_t
|
||||
#include <string_view>
|
||||
|
||||
#include "tr-macros.h"
|
||||
|
||||
/* Quarks — a 2-way association between a string and a unique integer identifier */
|
||||
|
@ -433,4 +436,4 @@ char const* tr_quark_get_string(tr_quark quark, size_t* len);
|
|||
* exists for that string, it is returned so that no duplicates are
|
||||
* created.
|
||||
*/
|
||||
tr_quark tr_quark_new(void const* str, size_t len);
|
||||
tr_quark tr_quark_new(std::string_view);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <cerrno>
|
||||
#include <cstdlib> /* strtol */
|
||||
#include <cstring> /* strcmp */
|
||||
#include <string_view>
|
||||
|
||||
#ifndef ZLIB_CONST
|
||||
#define ZLIB_CONST
|
||||
|
@ -998,7 +999,7 @@ static char const* torrentGet(
|
|||
size_t len;
|
||||
if (tr_variantGetStr(tr_variantListChild(fields, i), &strVal, &len))
|
||||
{
|
||||
keys[keyCount++] = tr_quark_new(strVal, len);
|
||||
keys[keyCount++] = tr_quark_new(std::string_view{ strVal, len });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2890,15 +2891,14 @@ void tr_rpc_request_exec_uri(
|
|||
|
||||
if (delim != nullptr)
|
||||
{
|
||||
char* key = tr_strndup(pch, (size_t)(delim - pch));
|
||||
bool isArg = strcmp(key, "method") != 0 && strcmp(key, "tag") != 0;
|
||||
auto const key = std::string_view{ pch, size_t(delim - pch) };
|
||||
bool isArg = key != "method" && key != "tag";
|
||||
tr_variant* parent = isArg ? args : ⊤
|
||||
|
||||
tr_rpc_parse_list_str(
|
||||
tr_variantDictAdd(parent, tr_quark_new(key, (size_t)(delim - pch))),
|
||||
tr_variantDictAdd(parent, tr_quark_new(key)),
|
||||
delim + 1,
|
||||
next != nullptr ? (size_t)(next - (delim + 1)) : strlen(delim + 1));
|
||||
tr_free(key);
|
||||
}
|
||||
|
||||
pch = next != nullptr ? next + 1 : nullptr;
|
||||
|
|
|
@ -2665,7 +2665,7 @@ static void metainfoLookupInit(tr_session* session)
|
|||
if (tr_torrentParse(ctor, &inf) == TR_PARSE_OK)
|
||||
{
|
||||
++n;
|
||||
tr_variantDictAddStr(lookup, tr_quark_new(inf.hashString, TR_BAD_SIZE), path);
|
||||
tr_variantDictAddStr(lookup, tr_quark_new(inf.hashString), path);
|
||||
}
|
||||
|
||||
tr_free(path);
|
||||
|
@ -2688,7 +2688,7 @@ char const* tr_sessionFindTorrentFile(tr_session const* session, char const* has
|
|||
}
|
||||
|
||||
char const* filename = nullptr;
|
||||
(void)tr_variantDictFindStr(session->metainfoLookup, tr_quark_new(hashString, TR_BAD_SIZE), &filename, nullptr);
|
||||
(void)tr_variantDictFindStr(session->metainfoLookup, tr_quark_new(hashString), &filename, nullptr);
|
||||
return filename;
|
||||
}
|
||||
|
||||
|
@ -2700,7 +2700,7 @@ void tr_sessionSetTorrentFile(tr_session* session, char const* hashString, char
|
|||
* lookup table hasn't been built yet */
|
||||
if (session->metainfoLookup != nullptr)
|
||||
{
|
||||
tr_variantDictAddStr(session->metainfoLookup, tr_quark_new(hashString, TR_BAD_SIZE), filename);
|
||||
tr_variantDictAddStr(session->metainfoLookup, tr_quark_new(hashString), filename);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@
|
|||
#include <set>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <typeinfo>
|
||||
|
||||
#ifndef _WIN32
|
||||
#include <sys/wait.h> /* wait() */
|
||||
|
@ -61,6 +62,8 @@
|
|||
|
||||
#define tr_deeplog_tor(tor, ...) tr_logAddDeepNamed(tr_torrentName(tor), __VA_ARGS__)
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
@ -2902,9 +2905,9 @@ uint64_t tr_torrentGetBytesLeftToAllocate(tr_torrent const* tor)
|
|||
static constexpr bool isJunkFile(std::string_view base)
|
||||
{
|
||||
auto constexpr Files = std::array<std::string_view, 3>{
|
||||
".DS_Store",
|
||||
"Thumbs.db",
|
||||
"desktop.ini",
|
||||
".DS_Store"sv,
|
||||
"Thumbs.db"sv,
|
||||
"desktop.ini"sv,
|
||||
};
|
||||
|
||||
// TODO(C++20): std::any_of is constexpr in C++20
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <errno.h>
|
||||
#include <stdlib.h> /* strtoul() */
|
||||
#include <string.h> /* strlen(), memchr() */
|
||||
#include <string_view>
|
||||
|
||||
#include <event2/buffer.h>
|
||||
|
||||
|
@ -263,7 +264,7 @@ int tr_variantParseBenc(void const* buf_in, void const* bufend_in, tr_variant* t
|
|||
|
||||
if (key == 0 && !std::empty(stack) && tr_variantIsDict(stack.back()))
|
||||
{
|
||||
key = tr_quark_new(str, str_len);
|
||||
key = tr_quark_new(std::string_view{ reinterpret_cast<char const*>(str), str_len });
|
||||
}
|
||||
else if ((v = get_node(stack, &key, top, &err)) != nullptr)
|
||||
{
|
||||
|
|
|
@ -67,7 +67,7 @@ static tr_variant* get_node(struct jsonsl_st* jsn)
|
|||
}
|
||||
else if (tr_variantIsDict(parent) && data->key != nullptr)
|
||||
{
|
||||
node = tr_variantDictAdd(parent, tr_quark_new(data->key, data->keylen));
|
||||
node = tr_variantDictAdd(parent, tr_quark_new(std::string_view{ data->key, data->keylen }));
|
||||
|
||||
data->key = nullptr;
|
||||
data->keylen = 0;
|
||||
|
|
|
@ -182,7 +182,7 @@ void TorrentModel::updateTorrents(tr_variant* torrents, bool is_complete_list)
|
|||
keys.reserve(tr_variantListSize(first_child));
|
||||
while (tr_variantGetStr(tr_variantListChild(first_child, i++), &str, &len))
|
||||
{
|
||||
keys.push_back(tr_quark_new(str, len));
|
||||
keys.push_back(tr_quark_new(std::string_view(str, len)));
|
||||
}
|
||||
}
|
||||
else if (first_child != nullptr)
|
||||
|
|
|
@ -18,6 +18,10 @@
|
|||
#include <clocale> // setlocale()
|
||||
#include <cstring> // strlen()
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <typeinfo> // sv for string_views
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
class JSONTest : public ::testing::TestWithParam<char const*>
|
||||
{
|
||||
|
@ -50,29 +54,29 @@ TEST_P(JSONTest, testElements)
|
|||
EXPECT_TRUE(tr_variantIsDict(&top));
|
||||
|
||||
char const* str = {};
|
||||
auto key = tr_quark_new("string", 6);
|
||||
auto key = tr_quark_new("string"sv);
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, key, &str, nullptr));
|
||||
EXPECT_STREQ("hello world", str);
|
||||
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, tr_quark_new("escaped", 7), &str, nullptr));
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, tr_quark_new("escaped"sv), &str, nullptr));
|
||||
EXPECT_STREQ("bell \b formfeed \f linefeed \n carriage return \r tab \t", str);
|
||||
|
||||
auto i = int64_t{};
|
||||
EXPECT_TRUE(tr_variantDictFindInt(&top, tr_quark_new("int", 3), &i));
|
||||
EXPECT_TRUE(tr_variantDictFindInt(&top, tr_quark_new("int"sv), &i));
|
||||
EXPECT_EQ(5, i);
|
||||
|
||||
auto d = double{};
|
||||
EXPECT_TRUE(tr_variantDictFindReal(&top, tr_quark_new("float", 5), &d));
|
||||
EXPECT_TRUE(tr_variantDictFindReal(&top, tr_quark_new("float"sv), &d));
|
||||
EXPECT_EQ(65, int(d * 10));
|
||||
|
||||
auto f = bool{};
|
||||
EXPECT_TRUE(tr_variantDictFindBool(&top, tr_quark_new("true", 4), &f));
|
||||
EXPECT_TRUE(tr_variantDictFindBool(&top, tr_quark_new("true"sv), &f));
|
||||
EXPECT_TRUE(f);
|
||||
|
||||
EXPECT_TRUE(tr_variantDictFindBool(&top, tr_quark_new("false", 5), &f));
|
||||
EXPECT_TRUE(tr_variantDictFindBool(&top, tr_quark_new("false"sv), &f));
|
||||
EXPECT_FALSE(f);
|
||||
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, tr_quark_new("null", 4), &str, nullptr));
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, tr_quark_new("null"sv), &str, nullptr));
|
||||
EXPECT_STREQ("", str);
|
||||
|
||||
if (err == 0)
|
||||
|
@ -88,7 +92,7 @@ TEST_P(JSONTest, testUtf8)
|
|||
char const* str;
|
||||
char* json;
|
||||
int err;
|
||||
tr_quark const key = tr_quark_new("key", 3);
|
||||
tr_quark const key = tr_quark_new("key"sv);
|
||||
|
||||
err = tr_variantFromJson(&top, in.data(), in.size());
|
||||
EXPECT_EQ(0, err);
|
||||
|
@ -175,18 +179,18 @@ TEST_P(JSONTest, test1)
|
|||
int64_t i;
|
||||
EXPECT_EQ(0, err);
|
||||
EXPECT_TRUE(tr_variantIsDict(&top));
|
||||
auto* headers = tr_variantDictFind(&top, tr_quark_new("headers", 7));
|
||||
auto* headers = tr_variantDictFind(&top, tr_quark_new("headers"sv));
|
||||
EXPECT_NE(nullptr, headers);
|
||||
EXPECT_TRUE(tr_variantIsDict(headers));
|
||||
EXPECT_TRUE(tr_variantDictFindStr(headers, tr_quark_new("type", 4), &str, nullptr));
|
||||
EXPECT_TRUE(tr_variantDictFindStr(headers, tr_quark_new("type"sv), &str, nullptr));
|
||||
EXPECT_STREQ("request", str);
|
||||
EXPECT_TRUE(tr_variantDictFindInt(headers, TR_KEY_tag, &i));
|
||||
EXPECT_EQ(666, i);
|
||||
auto* body = tr_variantDictFind(&top, tr_quark_new("body", 4));
|
||||
auto* body = tr_variantDictFind(&top, tr_quark_new("body"sv));
|
||||
EXPECT_NE(nullptr, body);
|
||||
EXPECT_TRUE(tr_variantDictFindStr(body, TR_KEY_name, &str, nullptr));
|
||||
EXPECT_STREQ("torrent-info", str);
|
||||
auto* args = tr_variantDictFind(body, tr_quark_new("arguments", 9));
|
||||
auto* args = tr_variantDictFind(body, tr_quark_new("arguments"sv));
|
||||
EXPECT_NE(nullptr, args);
|
||||
EXPECT_TRUE(tr_variantIsDict(args));
|
||||
auto* ids = tr_variantDictFind(args, TR_KEY_ids);
|
||||
|
@ -242,7 +246,7 @@ TEST_P(JSONTest, unescape)
|
|||
EXPECT_EQ(0, err);
|
||||
|
||||
char const* str;
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, tr_quark_new("string-1", 8), &str, nullptr));
|
||||
EXPECT_TRUE(tr_variantDictFindStr(&top, tr_quark_new("string-1"sv), &str, nullptr));
|
||||
EXPECT_STREQ("/usr/lib", str);
|
||||
|
||||
tr_variantFree(&top);
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
class QuarkTest : public ::testing::Test
|
||||
{
|
||||
|
@ -39,9 +40,11 @@ TEST_F(QuarkTest, allPredefinedKeysCanBeLookedUp)
|
|||
}
|
||||
}
|
||||
|
||||
TEST_F(QuarkTest, newEmptyQuarkReturnsNone)
|
||||
TEST_F(QuarkTest, newQuarkByStringView)
|
||||
{
|
||||
auto const q = tr_quark_new(nullptr, TR_BAD_SIZE);
|
||||
EXPECT_EQ(TR_KEY_NONE, q);
|
||||
EXPECT_EQ(std::string{ "" }, quarkGetString(q));
|
||||
auto constexpr UniqueString = std::string_view{ "this string is not a predefined quark" };
|
||||
auto const q = tr_quark_new(UniqueString);
|
||||
auto len = size_t{};
|
||||
EXPECT_EQ(UniqueString, tr_quark_get_string(q, &len));
|
||||
EXPECT_EQ(std::size(UniqueString), len);
|
||||
}
|
||||
|
|
|
@ -18,9 +18,13 @@
|
|||
#include <cmath> // lrint()
|
||||
#include <cctype> // isspace()
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <typeinfo>
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
using namespace std::literals;
|
||||
|
||||
class VariantTest : public ::testing::Test
|
||||
{
|
||||
protected:
|
||||
|
@ -371,14 +375,14 @@ TEST_F(VariantTest, bencToJson)
|
|||
|
||||
TEST_F(VariantTest, merge)
|
||||
{
|
||||
auto const i1 = tr_quark_new("i1", 2);
|
||||
auto const i2 = tr_quark_new("i2", 2);
|
||||
auto const i3 = tr_quark_new("i3", 2);
|
||||
auto const i4 = tr_quark_new("i4", 2);
|
||||
auto const s5 = tr_quark_new("s5", 2);
|
||||
auto const s6 = tr_quark_new("s6", 2);
|
||||
auto const s7 = tr_quark_new("s7", 2);
|
||||
auto const s8 = tr_quark_new("s8", 2);
|
||||
auto const i1 = tr_quark_new("i1"sv);
|
||||
auto const i2 = tr_quark_new("i2"sv);
|
||||
auto const i3 = tr_quark_new("i3"sv);
|
||||
auto const i4 = tr_quark_new("i4"sv);
|
||||
auto const s5 = tr_quark_new("s5"sv);
|
||||
auto const s6 = tr_quark_new("s6"sv);
|
||||
auto const s7 = tr_quark_new("s7"sv);
|
||||
auto const s8 = tr_quark_new("s8"sv);
|
||||
|
||||
/* initial dictionary (default values) */
|
||||
tr_variant dest;
|
||||
|
@ -455,10 +459,10 @@ TEST_F(VariantTest, stackSmash)
|
|||
|
||||
TEST_F(VariantTest, boolAndIntRecast)
|
||||
{
|
||||
auto const key1 = tr_quark_new("key1", 4);
|
||||
auto const key2 = tr_quark_new("key2", 4);
|
||||
auto const key3 = tr_quark_new("key3", 4);
|
||||
auto const key4 = tr_quark_new("key4", 4);
|
||||
auto const key1 = tr_quark_new("key1"sv);
|
||||
auto const key2 = tr_quark_new("key2"sv);
|
||||
auto const key3 = tr_quark_new("key3"sv);
|
||||
auto const key4 = tr_quark_new("key4"sv);
|
||||
|
||||
tr_variant top;
|
||||
tr_variantInitDict(&top, 10);
|
||||
|
@ -499,10 +503,10 @@ TEST_F(VariantTest, dictFindType)
|
|||
auto const expected_int = int{ 1234 };
|
||||
auto const expected_real = double{ 0.3 };
|
||||
|
||||
auto const key_bool = tr_quark_new("this-is-a-bool", TR_BAD_SIZE);
|
||||
auto const key_real = tr_quark_new("this-is-a-real", TR_BAD_SIZE);
|
||||
auto const key_int = tr_quark_new("this-is-an-int", TR_BAD_SIZE);
|
||||
auto const key_str = tr_quark_new("this-is-a-string", TR_BAD_SIZE);
|
||||
auto const key_bool = tr_quark_new("this-is-a-bool"sv);
|
||||
auto const key_real = tr_quark_new("this-is-a-real"sv);
|
||||
auto const key_int = tr_quark_new("this-is-an-int"sv);
|
||||
auto const key_str = tr_quark_new("this-is-a-string"sv);
|
||||
|
||||
// populate a dict
|
||||
tr_variant top;
|
||||
|
|
Loading…
Reference in New Issue