@@ -890,17 +890,12 @@ class OurReader {
890
890
public:
891
891
using Char = char ;
892
892
using Location = const Char*;
893
- struct StructuredError {
894
- ptrdiff_t offset_start;
895
- ptrdiff_t offset_limit;
896
- String message;
897
- };
898
893
899
894
explicit OurReader (OurFeatures const & features);
900
895
bool parse (const char * beginDoc, const char * endDoc, Value& root,
901
896
bool collectComments = true );
902
897
String getFormattedErrorMessages () const ;
903
- std::vector<StructuredError> getStructuredErrors () const ;
898
+ std::vector<CharReader:: StructuredError> getStructuredErrors () const ;
904
899
905
900
private:
906
901
OurReader (OurReader const &); // no impl
@@ -1860,10 +1855,10 @@ String OurReader::getFormattedErrorMessages() const {
1860
1855
return formattedMessage;
1861
1856
}
1862
1857
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;
1865
1860
for (const auto & error : errors_) {
1866
- OurReader ::StructuredError structured;
1861
+ CharReader ::StructuredError structured;
1867
1862
structured.offset_start = error.token_ .start_ - begin_;
1868
1863
structured.offset_limit = error.token_ .end_ - begin_;
1869
1864
structured.message = error.message_ ;
@@ -1873,20 +1868,34 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
1873
1868
}
1874
1869
1875
1870
class OurCharReader : public CharReader {
1876
- bool const collectComments_;
1877
- OurReader reader_;
1878
1871
1879
1872
public:
1880
1873
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;
1887
1889
}
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
+ };
1890
1899
};
1891
1900
1892
1901
CharReaderBuilder::CharReaderBuilder () { setDefaults (&settings_); }
@@ -1976,6 +1985,15 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
1976
1985
// ! [CharReaderBuilderDefaults]
1977
1986
}
1978
1987
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
+
1979
1997
// ////////////////////////////////
1980
1998
// global functions
1981
1999
0 commit comments