@@ -890,17 +890,12 @@ class OurReader {
890890public:
891891 using Char = char ;
892892 using Location = const Char*;
893- struct StructuredError {
894- ptrdiff_t offset_start;
895- ptrdiff_t offset_limit;
896- String message;
897- };
898893
899894 explicit OurReader (OurFeatures const & features);
900895 bool parse (const char * beginDoc, const char * endDoc, Value& root,
901896 bool collectComments = true );
902897 String getFormattedErrorMessages () const ;
903- std::vector<StructuredError> getStructuredErrors () const ;
898+ std::vector<CharReader:: StructuredError> getStructuredErrors () const ;
904899
905900private:
906901 OurReader (OurReader const &); // no impl
@@ -1860,10 +1855,10 @@ String OurReader::getFormattedErrorMessages() const {
18601855 return formattedMessage;
18611856}
18621857
1863- std::vector<OurReader ::StructuredError> OurReader::getStructuredErrors () const {
1864- std::vector<OurReader ::StructuredError> allErrors;
1858+ std::vector<CharReader ::StructuredError> OurReader::getStructuredErrors () const {
1859+ std::vector<CharReader ::StructuredError> allErrors;
18651860 for (const auto & error : errors_) {
1866- OurReader ::StructuredError structured;
1861+ CharReader ::StructuredError structured;
18671862 structured.offset_start = error.token_ .start_ - begin_;
18681863 structured.offset_limit = error.token_ .end_ - begin_;
18691864 structured.message = error.message_ ;
@@ -1873,20 +1868,34 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
18731868}
18741869
18751870class OurCharReader : public CharReader {
1876- bool const collectComments_;
1877- OurReader reader_;
18781871
18791872public:
18801873 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 ();
1874+ : CharReader(std::unique_ptr<OurImpl>(new OurImpl(collectComments, features))) {}
1875+
1876+ protected:
1877+ class OurImpl : public Impl {
1878+ public:
1879+ OurImpl (bool collectComments, OurFeatures const & features)
1880+ : collectComments_(collectComments), reader_(features) {}
1881+
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 ();
1887+ }
1888+ return ok;
18871889 }
1888- return ok;
1889- }
1890+
1891+ std::vector<CharReader::StructuredError> getStructuredErrors () const override {
1892+ return reader_.getStructuredErrors ();
1893+ }
1894+
1895+ private:
1896+ bool const collectComments_;
1897+ OurReader reader_;
1898+ };
18901899};
18911900
18921901CharReaderBuilder::CharReaderBuilder () { setDefaults (&settings_); }
@@ -1976,6 +1985,15 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
19761985 // ! [CharReaderBuilderDefaults]
19771986}
19781987
1988+ std::vector<CharReader::StructuredError> CharReader::getStructuredErrors () const {
1989+ return _impl->getStructuredErrors ();
1990+ }
1991+
1992+ bool CharReader::parse (char const * beginDoc, char const * endDoc, Value* root,
1993+ String* errs) {
1994+ return _impl->parse (beginDoc, endDoc, root, errs);
1995+ }
1996+
19791997// ////////////////////////////////
19801998// global functions
19811999
0 commit comments