From 4e6c5ca341773554517f1c2e8a4066d9da5fb477 Mon Sep 17 00:00:00 2001 From: Riyyi Date: Wed, 20 Jul 2022 21:32:17 +0200 Subject: [PATCH] Util: Change Job m_input string -> string_view --- src/util/json/job.cpp | 4 ++-- src/util/json/job.h | 8 ++++---- src/util/json/value.cpp | 2 +- src/util/json/value.h | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/util/json/job.cpp b/src/util/json/job.cpp index efa4aef..f6a6b35 100644 --- a/src/util/json/job.cpp +++ b/src/util/json/job.cpp @@ -15,7 +15,7 @@ namespace Json { -Job::Job(const std::string& input) +Job::Job(std::string_view input) : m_input(input) { // FIXME: Make this work for all newline types: \n, \r, \r\n @@ -68,7 +68,7 @@ void Job::printErrorLine(Token token, const char* message) message); // Get the JSON line that caused the error - std::istringstream input(m_input); + std::istringstream input(m_input.data()); std::string line; for (size_t i = 0; std::getline(input, line); ++i) { if (i == token.line) { diff --git a/src/util/json/job.h b/src/util/json/job.h index 62e92ba..3e36484 100644 --- a/src/util/json/job.h +++ b/src/util/json/job.h @@ -8,7 +8,7 @@ #define JSON_JOB_H #include // size_t -#include +#include #include #include "util/json/lexer.h" @@ -19,7 +19,7 @@ class Value; class Job { public: - Job(const std::string& input); + Job(std::string_view input); virtual ~Job(); enum class Color { @@ -36,13 +36,13 @@ public: void printErrorLine(Token token, const char* message); bool success() const { return m_success; } - const std::string& input() const { return m_input; } + std::string_view input() const { return m_input; } std::vector* tokens() { return &m_tokens; } private: bool m_success { true }; - std::string m_input; + std::string_view m_input; size_t m_lineNumbersWidth { 0 }; std::vector m_tokens; diff --git a/src/util/json/value.cpp b/src/util/json/value.cpp index 33e91c7..d831329 100644 --- a/src/util/json/value.cpp +++ b/src/util/json/value.cpp @@ -153,7 +153,7 @@ void Value::clear() } } -Value Value::parse(const std::string& input) +Value Value::parse(std::string_view input) { return Job(input).fire(); } diff --git a/src/util/json/value.h b/src/util/json/value.h index bc97f7e..784ef54 100644 --- a/src/util/json/value.h +++ b/src/util/json/value.h @@ -65,7 +65,7 @@ public: // -------------------------------------- - static Value parse(const std::string& input); + static Value parse(std::string_view input); static Value parse(std::ifstream& file); std::string dump(const uint32_t indent = 0, const char indentCharacter = ' ') const;