Build with C++17, remove nonstd::string_view
parent
8052a5903a
commit
f08f00d334
|
@ -198,9 +198,9 @@ if (WIN32)
|
|||
add_definitions(-DPSAPI_VERSION=1)
|
||||
endif (WIN32)
|
||||
|
||||
macro(set_cxx11_properties)
|
||||
macro(set_cxx_properties)
|
||||
set_target_properties(${ARGN} PROPERTIES
|
||||
CXX_STANDARD 11
|
||||
CXX_STANDARD 17
|
||||
CXX_STANDARD_REQUIRED ON
|
||||
CXX_EXTENSIONS ON
|
||||
)
|
||||
|
@ -208,7 +208,7 @@ endmacro()
|
|||
|
||||
macro(define_pioneer_library library_name _src _header)
|
||||
add_library(${library_name} STATIC ${${_src}} ${${_header}})
|
||||
set_cxx11_properties(${library_name})
|
||||
set_cxx_properties(${library_name})
|
||||
endmacro()
|
||||
|
||||
if (MSVC)
|
||||
|
@ -343,7 +343,7 @@ target_link_libraries(${PROJECT_NAME} LINK_PRIVATE ${pioneerLibs} ${winLibs})
|
|||
target_link_libraries(modelcompiler LINK_PRIVATE ${pioneerLibs} ${winLibs})
|
||||
target_link_libraries(savegamedump LINK_PRIVATE pioneer-core ${SDL2_IMAGE_LIBRARIES} ${winLibs})
|
||||
|
||||
set_cxx11_properties(${PROJECT_NAME} modelcompiler savegamedump)
|
||||
set_cxx_properties(${PROJECT_NAME} modelcompiler savegamedump)
|
||||
|
||||
if(MSVC)
|
||||
add_custom_command(TARGET ${PROJECT_NAME} POST_BUILD
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -302,7 +302,7 @@ InputBindings::Action *Manager::AddActionBinding(std::string id, BindingGroup *g
|
|||
// Load from the config
|
||||
std::string config_str = m_config->String(id.c_str());
|
||||
if (!config_str.empty()) {
|
||||
nonstd::string_view str(config_str);
|
||||
std::string_view str(config_str);
|
||||
str >> binding;
|
||||
}
|
||||
|
||||
|
@ -320,7 +320,7 @@ InputBindings::Axis *Manager::AddAxisBinding(std::string id, BindingGroup *group
|
|||
// Load from the config
|
||||
std::string config_str = m_config->String(id.c_str());
|
||||
if (!config_str.empty()) {
|
||||
nonstd::string_view str(config_str);
|
||||
std::string_view str(config_str);
|
||||
str >> binding;
|
||||
}
|
||||
|
||||
|
|
|
@ -139,11 +139,11 @@ Axis &Axis::operator=(const Axis &rhs)
|
|||
//
|
||||
// ============================================================================
|
||||
|
||||
using smatch = std::match_results<nonstd::string_view::const_iterator>;
|
||||
using smatch = std::match_results<std::string_view::const_iterator>;
|
||||
static std::regex disabled_matcher("^disabled", std::regex::icase);
|
||||
|
||||
// Handle the fiddly bits of matching a regex and advancing the beginning of a string
|
||||
bool consumeMatch(nonstd::string_view &str, smatch &match_results, std::regex ®)
|
||||
bool consumeMatch(std::string_view &str, smatch &match_results, std::regex ®)
|
||||
{
|
||||
if (!std::regex_search(str.cbegin(), str.cend(), match_results, reg))
|
||||
return false;
|
||||
|
@ -156,7 +156,7 @@ bool consumeMatch(nonstd::string_view &str, smatch &match_results, std::regex &r
|
|||
// Less awful than iostreams, but still not elegant. That's C++ for you.
|
||||
// TODO: save joystick id->GUID mapping separately in the config file and
|
||||
// don't write them here to save space
|
||||
nonstd::string_view &InputBindings::operator>>(nonstd::string_view &str, KeyBinding &out)
|
||||
std::string_view &InputBindings::operator>>(std::string_view &str, KeyBinding &out)
|
||||
{
|
||||
static std::regex key_matcher("^Key(\\d+)");
|
||||
static std::regex joystick_matcher("^Joy([^/]{32})");
|
||||
|
@ -222,7 +222,7 @@ std::ostream &InputBindings::operator<<(std::ostream &str, const KeyBinding &in)
|
|||
}
|
||||
|
||||
// Match [-]JoyGUID/A4
|
||||
nonstd::string_view &InputBindings::operator>>(nonstd::string_view &str, JoyAxis &out)
|
||||
std::string_view &InputBindings::operator>>(std::string_view &str, JoyAxis &out)
|
||||
{
|
||||
static std::regex joy_matcher("^Joy([^/]{32})/A(\\d+)");
|
||||
auto begin = str.cbegin();
|
||||
|
@ -260,7 +260,7 @@ std::ostream &InputBindings::operator<<(std::ostream &str, const JoyAxis &in)
|
|||
|
||||
// find a close paren, copy str into ret str, and return retstr
|
||||
// (for one-line failure case returns)
|
||||
nonstd::string_view &findCloseParen(nonstd::string_view &str, nonstd::string_view &retstr, smatch &match_results)
|
||||
std::string_view &findCloseParen(std::string_view &str, std::string_view &retstr, smatch &match_results)
|
||||
{
|
||||
if (std::regex_search(str.cbegin(), str.cend(), match_results, std::regex("\\)")))
|
||||
str.remove_prefix(std::distance(str.cbegin(), match_results[0].second));
|
||||
|
@ -270,7 +270,7 @@ nonstd::string_view &findCloseParen(nonstd::string_view &str, nonstd::string_vie
|
|||
}
|
||||
|
||||
// Parse KeyChord(Key53 + JoyGUID/B3 + Mouse1) | KeyChord(Mouse5)
|
||||
nonstd::string_view &InputBindings::operator>>(nonstd::string_view &str, KeyChord &out)
|
||||
std::string_view &InputBindings::operator>>(std::string_view &str, KeyChord &out)
|
||||
{
|
||||
static std::regex key_chord("^KeyChord\\(\\s*");
|
||||
static std::regex plus_sign("^\\s*\\+\\s*");
|
||||
|
@ -281,7 +281,7 @@ nonstd::string_view &InputBindings::operator>>(nonstd::string_view &str, KeyChor
|
|||
return str;
|
||||
|
||||
// make a copy of the string view so we can nondestructively consume matches.
|
||||
nonstd::string_view iterstr = str;
|
||||
std::string_view iterstr = str;
|
||||
|
||||
// ensure we read the KeyChord( opening
|
||||
if (!consumeMatch(iterstr, match_results, key_chord))
|
||||
|
@ -324,7 +324,7 @@ std::ostream &InputBindings::operator<<(std::ostream &str, const KeyChord &in)
|
|||
return str;
|
||||
}
|
||||
|
||||
nonstd::string_view &InputBindings::operator>>(nonstd::string_view &str, Axis &out)
|
||||
std::string_view &InputBindings::operator>>(std::string_view &str, Axis &out)
|
||||
{
|
||||
static std::regex input_axis("^InputAxis\\(\\s*");
|
||||
static std::regex comma_sep("^\\s*,\\s*");
|
||||
|
@ -354,7 +354,7 @@ std::ostream &InputBindings::operator<<(std::ostream &str, const Axis &in)
|
|||
return str << "InputAxis(" << in.axis << ", " << in.negative << ", " << in.positive << ")";
|
||||
}
|
||||
|
||||
nonstd::string_view &InputBindings::operator>>(nonstd::string_view &str, Action &out)
|
||||
std::string_view &InputBindings::operator>>(std::string_view &str, Action &out)
|
||||
{
|
||||
static std::regex input_action("^InputAction\\(\\s*");
|
||||
static std::regex comma_sep("^\\s*,\\s*");
|
||||
|
|
|
@ -4,12 +4,12 @@
|
|||
#pragma once
|
||||
|
||||
#include "DeleteEmitter.h"
|
||||
#include "nonstd/string_view.hpp"
|
||||
#include <SDL_events.h>
|
||||
#include <SDL_keycode.h>
|
||||
#include <sigc++/sigc++.h>
|
||||
#include <cstdint>
|
||||
#include <iostream>
|
||||
#include <string_view>
|
||||
|
||||
namespace InputBindings {
|
||||
enum class Response {
|
||||
|
@ -80,7 +80,7 @@ namespace InputBindings {
|
|||
bool operator<(const KeyBinding &rhs) const;
|
||||
|
||||
// serialization
|
||||
friend nonstd::string_view &operator>>(nonstd::string_view &, KeyBinding &);
|
||||
friend std::string_view &operator>>(std::string_view &, KeyBinding &);
|
||||
friend std::ostream &operator<<(std::ostream &, const KeyBinding &);
|
||||
};
|
||||
|
||||
|
@ -100,7 +100,7 @@ namespace InputBindings {
|
|||
}
|
||||
|
||||
// serialization
|
||||
friend nonstd::string_view &operator>>(nonstd::string_view &, JoyAxis &);
|
||||
friend std::string_view &operator>>(std::string_view &, JoyAxis &);
|
||||
friend std::ostream &operator<<(std::ostream &, const JoyAxis &);
|
||||
};
|
||||
|
||||
|
@ -135,7 +135,7 @@ namespace InputBindings {
|
|||
uint8_t m_queuedEvents = 0;
|
||||
|
||||
// serialization
|
||||
friend nonstd::string_view &operator>>(nonstd::string_view &, KeyChord &);
|
||||
friend std::string_view &operator>>(std::string_view &, KeyChord &);
|
||||
friend std::ostream &operator<<(std::ostream &, const KeyChord &);
|
||||
};
|
||||
|
||||
|
@ -161,7 +161,7 @@ namespace InputBindings {
|
|||
sigc::signal<void> onReleased;
|
||||
|
||||
// serialization
|
||||
friend nonstd::string_view &operator>>(nonstd::string_view &, Action &);
|
||||
friend std::string_view &operator>>(std::string_view &, Action &);
|
||||
friend std::ostream &operator<<(std::ostream &, const Action &);
|
||||
};
|
||||
|
||||
|
@ -195,22 +195,22 @@ namespace InputBindings {
|
|||
sigc::signal<void, float> onAxisValue;
|
||||
|
||||
// serialization
|
||||
friend nonstd::string_view &operator>>(nonstd::string_view &, Axis &);
|
||||
friend std::string_view &operator>>(std::string_view &, Axis &);
|
||||
friend std::ostream &operator<<(std::ostream &, const Axis &);
|
||||
};
|
||||
|
||||
nonstd::string_view &operator>>(nonstd::string_view &, KeyBinding &);
|
||||
std::string_view &operator>>(std::string_view &, KeyBinding &);
|
||||
std::ostream &operator<<(std::ostream &, const KeyBinding &);
|
||||
|
||||
nonstd::string_view &operator>>(nonstd::string_view &, JoyAxis &);
|
||||
std::string_view &operator>>(std::string_view &, JoyAxis &);
|
||||
std::ostream &operator<<(std::ostream &, const JoyAxis &);
|
||||
|
||||
nonstd::string_view &operator>>(nonstd::string_view &, KeyChord &);
|
||||
std::string_view &operator>>(std::string_view &, KeyChord &);
|
||||
std::ostream &operator<<(std::ostream &, const KeyChord &);
|
||||
|
||||
nonstd::string_view &operator>>(nonstd::string_view &, Action &);
|
||||
std::string_view &operator>>(std::string_view &, Action &);
|
||||
std::ostream &operator<<(std::ostream &, const Action &);
|
||||
|
||||
nonstd::string_view &operator>>(nonstd::string_view &, Axis &);
|
||||
std::string_view &operator>>(std::string_view &, Axis &);
|
||||
std::ostream &operator<<(std::ostream &, const Axis &);
|
||||
}; // namespace InputBindings
|
||||
|
|
|
@ -23,7 +23,7 @@ static void checkError(std::size_t errorCode)
|
|||
}
|
||||
}
|
||||
|
||||
std::string lz4::DecompressLZ4(const string_view data)
|
||||
std::string lz4::DecompressLZ4(const std::string_view data)
|
||||
{
|
||||
PROFILE_SCOPED()
|
||||
LZ4F_dctx *_tmp;
|
||||
|
@ -68,7 +68,7 @@ std::string lz4::DecompressLZ4(const string_view data)
|
|||
return out;
|
||||
}
|
||||
|
||||
std::string lz4::CompressLZ4(const string_view data, const int lz4_preset)
|
||||
std::string lz4::CompressLZ4(const std::string_view data, const int lz4_preset)
|
||||
{
|
||||
PROFILE_SCOPED()
|
||||
LZ4F_preferences_t pref = LZ4F_INIT_PREFERENCES;
|
||||
|
|
|
@ -3,14 +3,12 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include "nonstd/string_view.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
namespace lz4 {
|
||||
using nonstd::string_view;
|
||||
|
||||
struct DecompressionFailedException : public std::runtime_error {
|
||||
using std::runtime_error::runtime_error;
|
||||
|
@ -25,10 +23,10 @@ namespace lz4 {
|
|||
|
||||
// Decompress lz4 format data.
|
||||
// If the input fails format checks or checksum then it will throw an exception.
|
||||
std::string DecompressLZ4(const string_view data);
|
||||
std::string DecompressLZ4(const std::string_view data);
|
||||
|
||||
// Compresses a block of data according to the lz4 framing format.
|
||||
// If compression fails it throws an exception.
|
||||
// lz4_speed is the compression preset; 0 = default compression, 3-12 = HC compression
|
||||
std::string CompressLZ4(const string_view data, const int lz4_preset);
|
||||
std::string CompressLZ4(const std::string_view data, const int lz4_preset);
|
||||
} // namespace lz4
|
||||
|
|
|
@ -5,11 +5,11 @@
|
|||
#include "DateTime.h"
|
||||
#include "FileSystem.h"
|
||||
#include "SDL_messagebox.h"
|
||||
#include "nonstd/string_view.hpp"
|
||||
#include <SDL.h>
|
||||
#include <chrono>
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <string_view>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/format.h>
|
||||
|
@ -52,12 +52,12 @@ bool Log::Logger::SetLogFile(std::string filename)
|
|||
|
||||
void Log::Logger::LogLevel(Severity sv, const char *message)
|
||||
{
|
||||
LogLevel(sv, nonstd::string_view(message, strlen(message)));
|
||||
LogLevel(sv, std::string_view(message, strlen(message)));
|
||||
}
|
||||
|
||||
void Log::Logger::LogLevel(Severity sv, std::string &message)
|
||||
{
|
||||
LogLevel(sv, nonstd::string_view(message));
|
||||
LogLevel(sv, std::string_view(message));
|
||||
}
|
||||
|
||||
inline bool is_space(char c)
|
||||
|
@ -65,7 +65,7 @@ inline bool is_space(char c)
|
|||
return c == ' ' || c == '\n' || c == '\t' || c == '\r';
|
||||
}
|
||||
|
||||
void Log::Logger::LogLevel(Severity sv, nonstd::string_view message)
|
||||
void Log::Logger::LogLevel(Severity sv, std::string_view message)
|
||||
{
|
||||
// Convert std::chrono::system_clock (epoch functionally guaranteed to be 1970/1/1-00:00:00)
|
||||
// to our DateTime class (epoch defined as 2001/1/1-00:00:00)
|
||||
|
@ -81,7 +81,7 @@ void Log::Logger::LogLevel(Severity sv, nonstd::string_view message)
|
|||
WriteLog(time, sv, message);
|
||||
}
|
||||
|
||||
void Log::Logger::WriteLog(Time::DateTime time, Severity sv, nonstd::string_view msg)
|
||||
void Log::Logger::WriteLog(Time::DateTime time, Severity sv, std::string_view msg)
|
||||
{
|
||||
std::string &svName = s_severityNames.at(sv);
|
||||
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
#pragma once
|
||||
|
||||
#include "DateTime.h"
|
||||
#include "nonstd/string_view.hpp"
|
||||
#include <fmt/format.h>
|
||||
#include <sigc++/signal.h>
|
||||
#include <string_view>
|
||||
|
||||
namespace Log {
|
||||
enum class Severity : int8_t {
|
||||
|
@ -24,7 +24,7 @@ namespace Log {
|
|||
// Handle formatting, indentation, etc.
|
||||
// Prefer the Verbose, Info, Warning, etc. functions instead of directly using this one
|
||||
void LogLevel(Severity sv, std::string &message);
|
||||
void LogLevel(Severity sv, nonstd::string_view message);
|
||||
void LogLevel(Severity sv, std::string_view message);
|
||||
void LogLevel(Severity sv, const char *message);
|
||||
|
||||
bool SetLogFile(std::string filename);
|
||||
|
@ -42,10 +42,10 @@ namespace Log {
|
|||
if (current_indent) current_indent -= 1;
|
||||
}
|
||||
|
||||
sigc::signal<void, Time::DateTime, Severity, nonstd::string_view> printCallback;
|
||||
sigc::signal<void, Time::DateTime, Severity, std::string_view> printCallback;
|
||||
|
||||
private:
|
||||
void WriteLog(Time::DateTime t, Severity sv, nonstd::string_view msg);
|
||||
void WriteLog(Time::DateTime t, Severity sv, std::string_view msg);
|
||||
|
||||
FILE *file;
|
||||
Severity m_maxSeverity = Severity::Info;
|
||||
|
|
|
@ -183,10 +183,10 @@ void LuaConsole::RegisterAutoexec()
|
|||
LUA_DEBUG_END(L, 0);
|
||||
}
|
||||
|
||||
void LuaConsole::LogCallback(Time::DateTime time, Log::Severity sev, nonstd::string_view message)
|
||||
void LuaConsole::LogCallback(Time::DateTime time, Log::Severity sev, std::string_view message)
|
||||
{
|
||||
if (sev <= Log::Severity::Debug)
|
||||
m_outputLines.push_back(message.to_string());
|
||||
m_outputLines.push_back(std::string(message));
|
||||
}
|
||||
|
||||
static int callback(ImGuiInputTextCallbackData *data)
|
||||
|
|
|
@ -35,7 +35,7 @@ public:
|
|||
private:
|
||||
bool OnCompletion(bool backward);
|
||||
bool OnHistory(bool upArrow);
|
||||
void LogCallback(Time::DateTime, Log::Severity, nonstd::string_view);
|
||||
void LogCallback(Time::DateTime, Log::Severity, std::string_view);
|
||||
|
||||
bool ExecOrContinue(const std::string &stmt, bool repeatStatement = true);
|
||||
void UpdateCompletion(const std::string &statement);
|
||||
|
|
|
@ -447,11 +447,11 @@ static std::string make_module_name(lua_State *L, int idx)
|
|||
static std::string get_caller_module_name(lua_State *L)
|
||||
{
|
||||
std::string caller = get_caller(L);
|
||||
nonstd::string_view sv(caller);
|
||||
if (sv.ends_with(".lua"))
|
||||
std::string_view sv(caller);
|
||||
if (ends_with(sv, ".lua"))
|
||||
sv.remove_suffix(4);
|
||||
|
||||
return path_to_module(sv.to_string() + "/");
|
||||
return path_to_module(std::string(sv) + "/");
|
||||
}
|
||||
|
||||
static int l_reimport_package(lua_State *L)
|
||||
|
|
69
src/utils.h
69
src/utils.h
|
@ -94,69 +94,42 @@ static inline Sint64 isqrt(fixed v)
|
|||
// find string in bigger string, ignoring case
|
||||
const char *pi_strcasestr(const char *haystack, const char *needle);
|
||||
|
||||
inline bool starts_with(const char *s, const char *t)
|
||||
inline bool starts_with(const std::string_view s, const std::string_view t)
|
||||
{
|
||||
assert(s && t);
|
||||
while ((*s == *t) && *t) {
|
||||
++s;
|
||||
++t;
|
||||
}
|
||||
return (*t == '\0');
|
||||
if (s.size() < t.size())
|
||||
return false;
|
||||
return memcmp(s.begin(), t.begin(), t.size()) == 0;
|
||||
}
|
||||
|
||||
inline bool starts_with(const std::string &s, const char *t)
|
||||
inline bool ends_with(const std::string_view s, const std::string_view t)
|
||||
{
|
||||
assert(t);
|
||||
return starts_with(s.c_str(), t);
|
||||
if (s.size() < t.size())
|
||||
return false;
|
||||
return memcmp(s.end() - t.size(), t.begin(), t.size()) == 0;
|
||||
}
|
||||
|
||||
inline bool starts_with(const std::string &s, const std::string &t)
|
||||
inline bool starts_with_ci(const std::string_view s, const std::string_view t)
|
||||
{
|
||||
return starts_with(s.c_str(), t.c_str());
|
||||
}
|
||||
if (s.size() < t.size())
|
||||
return false;
|
||||
|
||||
inline bool ends_with(const char *s, size_t ns, const char *t, size_t nt)
|
||||
{
|
||||
return (ns >= nt) && (memcmp(s + (ns - nt), t, nt) == 0);
|
||||
}
|
||||
for (size_t i = 0; i < t.size(); i++)
|
||||
if (tolower(s.data()[i]) != tolower(t.data()[i]))
|
||||
return false;
|
||||
|
||||
inline bool ends_with(const char *s, const char *t)
|
||||
{
|
||||
return ends_with(s, strlen(s), t, strlen(t));
|
||||
}
|
||||
|
||||
inline bool ends_with(const std::string &s, const char *t)
|
||||
{
|
||||
return ends_with(s.c_str(), s.size(), t, strlen(t));
|
||||
}
|
||||
|
||||
inline bool ends_with(const std::string &s, const std::string &t)
|
||||
{
|
||||
return ends_with(s.c_str(), s.size(), t.c_str(), t.size());
|
||||
}
|
||||
|
||||
inline bool ends_with_ci(const char *s, size_t ns, const char *t, size_t nt)
|
||||
{
|
||||
if (ns < nt) return false;
|
||||
s += (ns - nt);
|
||||
for (size_t i = 0; i < nt; i++)
|
||||
if (tolower(*s++) != tolower(*t++)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool ends_with_ci(const char *s, const char *t)
|
||||
inline bool ends_with_ci(const std::string_view s, const std::string_view t)
|
||||
{
|
||||
return ends_with_ci(s, strlen(s), t, strlen(t));
|
||||
}
|
||||
if (s.size() < t.size())
|
||||
return false;
|
||||
|
||||
inline bool ends_with_ci(const std::string &s, const char *t)
|
||||
{
|
||||
return ends_with_ci(s.c_str(), s.size(), t, strlen(t));
|
||||
}
|
||||
for (size_t i = t.size(); i > 0; i--)
|
||||
if (tolower(s.end()[-i]) != tolower(t.end()[-i]))
|
||||
return false;
|
||||
|
||||
inline bool ends_with_ci(const std::string &s, const std::string &t)
|
||||
{
|
||||
return ends_with_ci(s.c_str(), s.size(), t.c_str(), t.size());
|
||||
return true;
|
||||
}
|
||||
|
||||
static inline size_t SplitSpec(const std::string &spec, std::vector<int> &output)
|
||||
|
|
Loading…
Reference in New Issue