Skip to content

Commit

Permalink
Merge pull request #663 from cldellow/geojson-lines
Browse files Browse the repository at this point in the history
GeoJSON lines: skip leading whitespace in a chunk
  • Loading branch information
systemed authored Feb 1, 2024
2 parents 1c8ad9d + 49d838d commit 6e335ef
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/geojson_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,16 @@ void GeoJSONProcessor::readFeatureLines(class LayerDef &layer, uint layerNum) {
char readBuffer[65536];
rapidjson::FileReadStream is(fp, readBuffer, sizeof(readBuffer));

// Skip leading whitespace.
while(is.Tell() < chunk.length && isspace(is.Peek())) is.Take();

while(is.Tell() < chunk.length) {
auto doc = rapidjson::Document();
doc.ParseStream<rapidjson::kParseStopWhenDoneFlag>(is);
if (doc.HasParseError()) { throw std::runtime_error("Invalid JSON file."); }
processFeature(std::move(doc.GetObject()), layer, layerNum);

// Skip whitespace.
// Skip trailing whitespace.
while(is.Tell() < chunk.length && isspace(is.Peek())) is.Take();
}
fclose(fp);
Expand Down

0 comments on commit 6e335ef

Please sign in to comment.