+ fixed a bug in the stream input
This commit is contained in:
parent
15a9d3cff6
commit
4e44390090
2
.gitignore
vendored
2
.gitignore
vendored
@ -34,3 +34,5 @@ test-driver
|
||||
Makefile.in
|
||||
|
||||
*.plist
|
||||
|
||||
json_parser
|
||||
|
@ -1,4 +1,4 @@
|
||||
noinst_PROGRAMS = json_unit
|
||||
noinst_PROGRAMS = json_unit json_parser
|
||||
|
||||
FLAGS = -Wall -Wextra -pedantic -Weffc++ -Wcast-align -Wcast-qual -Wctor-dtor-privacy -Wdisabled-optimization -Wformat=2 -Winit-self -Wmissing-declarations -Wmissing-include-dirs -Wold-style-cast -Woverloaded-virtual -Wredundant-decls -Wshadow -Wsign-conversion -Wsign-promo -Wstrict-overflow=5 -Wswitch -Wundef -Wno-unused -Wnon-virtual-dtor -Wreorder
|
||||
|
||||
@ -6,6 +6,10 @@ json_unit_SOURCES = src/JSON.cc src/JSON.h test/catch.hpp test/JSON_unit.cc
|
||||
json_unit_CXXFLAGS = $(FLAGS) -std=c++11
|
||||
json_unit_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/test -Dprivate=public
|
||||
|
||||
json_parser_SOURCES = src/JSON.cc src/JSON.h benchmark/parse.cc
|
||||
json_parser_CXXFLAGS = $(FLAGS) -std=c++11
|
||||
json_parser_CPPFLAGS = -I$(top_srcdir)/src -I$(top_srcdir)/benchmark
|
||||
|
||||
cppcheck:
|
||||
cppcheck --enable=all --inconclusive --std=c++11 src/JSON.*
|
||||
|
||||
|
8
benchmark/parse.cc
Normal file
8
benchmark/parse.cc
Normal file
@ -0,0 +1,8 @@
|
||||
#include "JSON.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
JSON j;
|
||||
j << std::cin;
|
||||
return 0;
|
||||
}
|
11
src/JSON.cc
11
src/JSON.cc
@ -1775,14 +1775,13 @@ Initialize the JSON parser given an input stream \p _is.
|
||||
*/
|
||||
JSON::Parser::Parser(std::istream& _is)
|
||||
{
|
||||
// determine length of input stream
|
||||
_is.seekg(0, std::ios::end);
|
||||
_length = static_cast<size_t>(_is.tellg());
|
||||
_is.seekg(0, std::ios::beg);
|
||||
// copy stream to string
|
||||
std::istreambuf_iterator<char> eos;
|
||||
std::string string_input(std::istreambuf_iterator<char>(_is), eos);
|
||||
|
||||
// copy stream to buffer
|
||||
_length = string_input.size();
|
||||
_buffer = new char[_length + 1];
|
||||
_is.read(_buffer, static_cast<std::streamsize>(_length));
|
||||
std::strcpy(_buffer, string_input.c_str());
|
||||
|
||||
// read first character
|
||||
next();
|
||||
|
Loading…
Reference in New Issue
Block a user