@@ -900,7 +900,7 @@ class OurReader {
900
900
bool parse (const char * beginDoc, const char * endDoc, Value& root,
901
901
bool collectComments = true );
902
902
String getFormattedErrorMessages () const ;
903
- std::vector<StructuredError> getStructuredErrors () const ;
903
+ std::vector<OurReader:: StructuredError> getStructuredErrors () const ;
904
904
905
905
private:
906
906
OurReader (OurReader const &); // no impl
@@ -1873,20 +1873,44 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
1873
1873
}
1874
1874
1875
1875
class OurCharReader : public CharReader {
1876
- bool const collectComments_;
1877
- OurReader reader_;
1878
1876
1879
1877
public:
1880
1878
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;
1887
1894
}
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
+ };
1890
1914
};
1891
1915
1892
1916
CharReaderBuilder::CharReaderBuilder () { setDefaults (&settings_); }
@@ -1976,6 +2000,15 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
1976
2000
// ! [CharReaderBuilderDefaults]
1977
2001
}
1978
2002
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
+
1979
2012
// ////////////////////////////////
1980
2013
// global functions
1981
2014
0 commit comments