@@ -878,17 +878,12 @@ class OurReader {
878
878
public:
879
879
using Char = char ;
880
880
using Location = const Char*;
881
- struct StructuredError {
882
- ptrdiff_t offset_start;
883
- ptrdiff_t offset_limit;
884
- String message;
885
- };
886
881
887
882
explicit OurReader (OurFeatures const & features);
888
883
bool parse (const char * beginDoc, const char * endDoc, Value& root,
889
884
bool collectComments = true );
890
885
String getFormattedErrorMessages () const ;
891
- std::vector<StructuredError> getStructuredErrors () const ;
886
+ std::vector<CharReader:: StructuredError> getStructuredErrors () const ;
892
887
893
888
private:
894
889
OurReader (OurReader const &); // no impl
@@ -1836,10 +1831,11 @@ String OurReader::getFormattedErrorMessages() const {
1836
1831
return formattedMessage;
1837
1832
}
1838
1833
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;
1841
1837
for (const auto & error : errors_) {
1842
- OurReader ::StructuredError structured;
1838
+ CharReader ::StructuredError structured;
1843
1839
structured.offset_start = error.token_ .start_ - begin_;
1844
1840
structured.offset_limit = error.token_ .end_ - begin_;
1845
1841
structured.message = error.message_ ;
@@ -1849,20 +1845,36 @@ std::vector<OurReader::StructuredError> OurReader::getStructuredErrors() const {
1849
1845
}
1850
1846
1851
1847
class OurCharReader : public CharReader {
1852
- bool const collectComments_;
1853
- OurReader reader_;
1854
1848
1855
1849
public:
1856
1850
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;
1863
1867
}
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
+ };
1866
1878
};
1867
1879
1868
1880
CharReaderBuilder::CharReaderBuilder () { setDefaults (&settings_); }
@@ -1952,6 +1964,16 @@ void CharReaderBuilder::setDefaults(Json::Value* settings) {
1952
1964
// ! [CharReaderBuilderDefaults]
1953
1965
}
1954
1966
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
+
1955
1977
// ////////////////////////////////
1956
1978
// global functions
1957
1979
0 commit comments