Use sv literal suffixes for most string_view literals

They're not in scope by default when using MSVC so using them in header files is problematic.
This commit is contained in:
Oliver Hamlet
2025-04-04 18:45:42 +01:00
parent 58dbff885c
commit 22a2c60c17
4 changed files with 21 additions and 15 deletions
+8 -7
View File
@@ -50,6 +50,7 @@
using std::filesystem::u8path;
namespace {
using std::string_view_literals::operator""sv;
using loot::GameType;
// The Microsoft Store installs Fallout 4 DLCs to directories outside of the
@@ -57,19 +58,19 @@ using loot::GameType;
// game install path (renaming them causes the game launch to fail, or not
// find the DLC files).
constexpr std::string_view MS_FO4_AUTOMATRON_DATA_PATH =
"../../Fallout 4- Automatron (PC)/Content/Data";
"../../Fallout 4- Automatron (PC)/Content/Data"sv;
constexpr std::string_view MS_FO4_CONTRAPTIONS_DATA_PATH =
"../../Fallout 4- Contraptions Workshop (PC)/Content/Data";
"../../Fallout 4- Contraptions Workshop (PC)/Content/Data"sv;
constexpr std::string_view MS_FO4_FAR_HARBOR_DATA_PATH =
"../../Fallout 4- Far Harbor (PC)/Content/Data";
"../../Fallout 4- Far Harbor (PC)/Content/Data"sv;
constexpr std::string_view MS_FO4_TEXTURE_PACK_DATA_PATH =
"../../Fallout 4- High Resolution Texture Pack/Content/Data";
"../../Fallout 4- High Resolution Texture Pack/Content/Data"sv;
constexpr std::string_view MS_FO4_NUKA_WORLD_DATA_PATH =
"../../Fallout 4- Nuka-World (PC)/Content/Data";
"../../Fallout 4- Nuka-World (PC)/Content/Data"sv;
constexpr std::string_view MS_FO4_VAULT_TEC_DATA_PATH =
"../../Fallout 4- Vault-Tec Workshop (PC)/Content/Data";
"../../Fallout 4- Vault-Tec Workshop (PC)/Content/Data"sv;
constexpr std::string_view MS_FO4_WASTELAND_DATA_PATH =
"../../Fallout 4- Wasteland Workshop (PC)/Content/Data";
"../../Fallout 4- Wasteland Workshop (PC)/Content/Data"sv;
bool IsMicrosoftStoreInstall(const GameType gameType,
const std::filesystem::path& gamePath) {
+2 -1
View File
@@ -29,9 +29,10 @@
#include <spdlog/sinks/base_sink.h>
namespace {
using std::string_view_literals::operator""sv;
using loot::LogLevel;
constexpr std::string_view LOGGER_NAME = "loot_api_logger";
constexpr std::string_view LOGGER_NAME = "loot_api_logger"sv;
LogLevel mapFromSpdlog(spdlog::level::level_enum severity) {
using spdlog::level::level_enum;
+7 -5
View File
@@ -34,31 +34,33 @@
#endif
namespace loot {
using std::string_view_literals::operator""sv;
/* The string below matches timestamps that use forwardslashes for date
separators. However, Pseudosem v1.0.1 will only compare the first
two digits as it does not recognise forwardslashes as separators. */
constexpr std::string_view dateRegex =
R"((\d{1,2}/\d{1,2}/\d{1,4} \d{1,2}:\d{1,2}:\d{1,2}))";
R"((\d{1,2}/\d{1,2}/\d{1,4} \d{1,2}:\d{1,2}:\d{1,2}))"sv;
/* The string below matches the range of version strings supported by
Pseudosem v1.0.1, excluding space separators, as they make version
extraction from inside sentences very tricky and have not been
seen "in the wild". */
constexpr std::string_view pseudosemVersionRegex =
R"((\d+(?:\.\d+)+(?:[-._:]?[A-Za-z0-9]+)*))"
R"((\d+(?:\.\d+)+(?:[-._:]?[A-Za-z0-9]+)*))"sv
// The string below prevents version numbers followed by a comma from
// matching.
R"((?!,))";
R"((?!,))"sv;
/* The string below matches a number containing one or more
digits found at the start of the search string or preceded by
'v' or 'version:. */
constexpr std::string_view digitsVersionRegex = R"((?:^|v|version:\s*)(\d+))";
constexpr std::string_view digitsVersionRegex = R"((?:^|v|version:\s*)(\d+))"sv;
std::vector<Tag> ExtractBashTags(std::string_view description) {
std::vector<Tag> tags;
static constexpr std::string_view BASH_TAGS_OPENER = "{{BASH:";
static constexpr std::string_view BASH_TAGS_OPENER = "{{BASH:"sv;
size_t startPos = description.find("{{BASH:");
if (startPos == std::string::npos ||
+4 -2
View File
@@ -38,8 +38,10 @@
#include "loot/exception/file_access_error.h"
namespace loot {
constexpr std::string_view PRELUDE_ON_FIRST_LINE = "prelude:";
constexpr std::string_view PRELUDE_ON_NEW_LINE = "\nprelude:";
using std::string_view_literals::operator""sv;
constexpr std::string_view PRELUDE_ON_FIRST_LINE = "prelude:"sv;
constexpr std::string_view PRELUDE_ON_NEW_LINE = "\nprelude:"sv;
std::string read_to_string(const std::filesystem::path& filePath) {
std::ifstream in(filePath);