Browse Source

Util: Change Job m_input string -> string_view

master
Riyyi 2 years ago
parent
commit
4e6c5ca341
  1. 4
      src/util/json/job.cpp
  2. 8
      src/util/json/job.h
  3. 2
      src/util/json/value.cpp
  4. 2
      src/util/json/value.h

4
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) {

8
src/util/json/job.h

@ -8,7 +8,7 @@
#define JSON_JOB_H
#include <cstddef> // size_t
#include <string>
#include <string_view>
#include <vector>
#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<Token>* 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<Token> m_tokens;

2
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();
}

2
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;

Loading…
Cancel
Save