Util: Change Job m_input string -> string_view

This commit is contained in:
Riyyi
2022-07-20 21:32:17 +02:00
parent b4100113fe
commit 4e6c5ca341
4 changed files with 8 additions and 8 deletions
+2 -2
View File
@@ -15,7 +15,7 @@
namespace Json { namespace Json {
Job::Job(const std::string& input) Job::Job(std::string_view input)
: m_input(input) : m_input(input)
{ {
// FIXME: Make this work for all newline types: \n, \r, \r\n // 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); message);
// Get the JSON line that caused the error // Get the JSON line that caused the error
std::istringstream input(m_input); std::istringstream input(m_input.data());
std::string line; std::string line;
for (size_t i = 0; std::getline(input, line); ++i) { for (size_t i = 0; std::getline(input, line); ++i) {
if (i == token.line) { if (i == token.line) {
+4 -4
View File
@@ -8,7 +8,7 @@
#define JSON_JOB_H #define JSON_JOB_H
#include <cstddef> // size_t #include <cstddef> // size_t
#include <string> #include <string_view>
#include <vector> #include <vector>
#include "util/json/lexer.h" #include "util/json/lexer.h"
@@ -19,7 +19,7 @@ class Value;
class Job { class Job {
public: public:
Job(const std::string& input); Job(std::string_view input);
virtual ~Job(); virtual ~Job();
enum class Color { enum class Color {
@@ -36,13 +36,13 @@ public:
void printErrorLine(Token token, const char* message); void printErrorLine(Token token, const char* message);
bool success() const { return m_success; } bool success() const { return m_success; }
const std::string& input() const { return m_input; } std::string_view input() const { return m_input; }
std::vector<Token>* tokens() { return &m_tokens; } std::vector<Token>* tokens() { return &m_tokens; }
private: private:
bool m_success { true }; bool m_success { true };
std::string m_input; std::string_view m_input;
size_t m_lineNumbersWidth { 0 }; size_t m_lineNumbersWidth { 0 };
std::vector<Token> m_tokens; std::vector<Token> m_tokens;
+1 -1
View File
@@ -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(); return Job(input).fire();
} }
+1 -1
View File
@@ -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); static Value parse(std::ifstream& file);
std::string dump(const uint32_t indent = 0, const char indentCharacter = ' ') const; std::string dump(const uint32_t indent = 0, const char indentCharacter = ' ') const;