@@ -878,17 +878,12 @@ class OurReader {
878878public:
879879 using Char = char ;
880880 using Location = const Char*;
881- struct StructuredError {
882- ptrdiff_t offset_start;
883- ptrdiff_t offset_limit;
884- String message;
885- };
886881
887882 explicit OurReader (OurFeatures const & features);
888883 bool parse (const char * beginDoc, const char * endDoc, Value& root,
889884 bool collectComments = true );
890885 String getFormattedErrorMessages () const ;
891- std::vector<StructuredError> getStructuredErrors () const ;
886+ std::vector<CharReader:: StructuredError> getStructuredErrors () const ;
892887
893888private:
894889 OurReader (OurReader const &); // no impl
@@ -1836,10 +1831,11 @@ String OurReader::getFormattedErrorMessages() const {
18361831 return formattedMessage;
18371832}
18381833
1839- std::vector<OurReader::StructuredError> OurReader::getStructuredErrors () const {
1840- std::vector<OurReader::StructuredError> allErrors;
1834+ std::vector<CharReader::StructuredError>
1835+ OurReader::getStructuredErrors () const {
1836+ std::vector<CharReader::StructuredError> allErrors;
18411837 for (const auto & error : errors_) {
1842- OurReader ::StructuredError structured;
1838+ CharReader ::StructuredError structured;
18431839 structured.offset_start = error.token_ .start_ - begin_;
18441840 structured.offset_limit = error.token_ .end_ - begin_;
18451841 structured.message = error.message_ ;
@@ -1849,20 +1845,36 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
18491845}
18501846
18511847class OurCharReader : public CharReader {
1852- bool const collectComments_;
1853- OurReader reader_;
18541848
18551849public:
18561850 OurCharReader (bool collectComments, OurFeatures const & features)
1857- : collectComments_(collectComments), reader_(features) {}
1858- bool parse (char const * beginDoc, char const * endDoc, Value* root,
1859- String* errs) override {
1860- bool ok = reader_.parse (beginDoc, endDoc, *root, collectComments_);
1861- if (errs) {
1862- *errs = reader_.getFormattedErrorMessages ();
1851+ : CharReader(
1852+ std::unique_ptr<OurImpl>(new OurImpl(collectComments, features))) {}
1853+
1854+ protected:
1855+ class OurImpl : public Impl {
1856+ public:
1857+ OurImpl (bool collectComments, OurFeatures const & features)
1858+ : collectComments_(collectComments), reader_(features) {}
1859+
1860+ bool parse (char const * beginDoc, char const * endDoc, Value* root,
1861+ String* errs) override {
1862+ bool ok = reader_.parse (beginDoc, endDoc, *root, collectComments_);
1863+ if (errs) {
1864+ *errs = reader_.getFormattedErrorMessages ();
1865+ }
1866+ return ok;
18631867 }
1864- return ok;
1865- }
1868+
1869+ std::vector<CharReader::StructuredError>
1870+ getStructuredErrors () const override {
1871+ return reader_.getStructuredErrors ();
1872+ }
1873+
1874+ private:
1875+ bool const collectComments_;
1876+ OurReader reader_;
1877+ };
18661878};
18671879
18681880CharReaderBuilder::CharReaderBuilder () { setDefaults (&settings_); }
@@ -1952,6 +1964,16 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
19521964 // ! [CharReaderBuilderDefaults]
19531965}
19541966
1967+ std::vector<CharReader::StructuredError>
1968+ CharReader::getStructuredErrors () const {
1969+ return _impl->getStructuredErrors ();
1970+ }
1971+
1972+ bool CharReader::parse (char const * beginDoc, char const * endDoc, Value* root,
1973+ String* errs) {
1974+ return _impl->parse (beginDoc, endDoc, root, errs);
1975+ }
1976+
19551977// ////////////////////////////////
19561978// global functions
19571979
0 commit comments