@@ -900,7 +900,7 @@ class OurReader {
900900 bool parse (const char * beginDoc, const char * endDoc, Value& root,
901901 bool collectComments = true );
902902 String getFormattedErrorMessages () const ;
903- std::vector<StructuredError> getStructuredErrors () const ;
903+ std::vector<OurReader:: StructuredError> getStructuredErrors () const ;
904904
905905private:
906906 OurReader (OurReader const &); // no impl
@@ -1873,20 +1873,44 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
18731873}
18741874
18751875class OurCharReader : public CharReader {
1876- bool const collectComments_;
1877- OurReader reader_;
18781876
18791877public:
18801878 OurCharReader (bool collectComments, OurFeatures const & features)
1881- : collectComments_(collectComments), reader_(features) {}
1882- bool parse (char const * beginDoc, char const * endDoc, Value* root,
1883- String* errs) override {
1884- bool ok = reader_.parse (beginDoc, endDoc, *root, collectComments_);
1885- if (errs) {
1886- *errs = reader_.getFormattedErrorMessages ();
1879+ : CharReader(new OurImpl(collectComments, features)) {}
1880+
1881+ protected:
1882+ class OurImpl : public Impl {
1883+ public:
1884+ OurImpl (bool collectComments, OurFeatures const & features)
1885+ : collectComments_(collectComments), reader_(features) {}
1886+
1887+ bool parse (char const * beginDoc, char const * endDoc, Value* root,
1888+ String* errs) override {
1889+ bool ok = reader_.parse (beginDoc, endDoc, *root, collectComments_);
1890+ if (errs) {
1891+ *errs = reader_.getFormattedErrorMessages ();
1892+ }
1893+ return ok;
18871894 }
1888- return ok;
1889- }
1895+
1896+ std::vector<CharReader::StructuredError> getStructuredErrors () const override {
1897+ std::vector<OurReader::StructuredError> errors = reader_.getStructuredErrors ();
1898+ std::vector<CharReader::StructuredError> out_errors;
1899+ std::transform (errors.begin (), errors.end (), std::back_inserter (out_errors),
1900+ [](OurReader::StructuredError x) {
1901+ CharReader::StructuredError y;
1902+ y.offset_start = x.offset_start ;
1903+ y.offset_limit = x.offset_limit ;
1904+ y.message = x.message ;
1905+ return y;
1906+ });
1907+ return out_errors;
1908+ }
1909+
1910+ private:
1911+ bool const collectComments_;
1912+ OurReader reader_;
1913+ };
18901914};
18911915
18921916CharReaderBuilder::CharReaderBuilder () { setDefaults (&settings_); }
@@ -1976,6 +2000,15 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
19762000 // ! [CharReaderBuilderDefaults]
19772001}
19782002
2003+ std::vector<CharReader::StructuredError> CharReader::getStructuredErrors () const {
2004+ return _impl->getStructuredErrors ();
2005+ }
2006+
2007+ bool CharReader::parse (char const * beginDoc, char const * endDoc, Value* root,
2008+ String* errs) {
2009+ return _impl->parse (beginDoc, endDoc, root, errs);
2010+ }
2011+
19792012// ////////////////////////////////
19802013// global functions
19812014
0 commit comments