apt.dat parser: various little improvements
- don't duplicate the line buffer (array of char as well as std::string), it is not useful here; - don't corrupt (truncate) input lines longer than 2048 bytes: there is no such limitation in the apt.dat v1000 format spec; - fix comments handling: the apt.dat v1000 format spec states they must start with *two* '#' characters.
This commit is contained in:
parent
b0b81bcd3e
commit
d85fc7b7e7
1 changed files with 12 additions and 8 deletions
|
@ -98,9 +98,7 @@ public:
|
|||
}
|
||||
|
||||
string line;
|
||||
char tmp[2049];
|
||||
tmp[2048] = 0;
|
||||
|
||||
|
||||
unsigned int line_id = 0;
|
||||
unsigned int line_num = 0;
|
||||
|
||||
|
@ -130,13 +128,11 @@ public:
|
|||
|
||||
throwExceptionIfStreamError(in, "apt.dat", apt_dat);
|
||||
|
||||
while ( in.getline(tmp, 2048) ) {
|
||||
line = tmp; // string copy, ack
|
||||
while ( std::getline(in, line) ) {
|
||||
line_num++;
|
||||
|
||||
if ( line.empty() || isspace(tmp[0]) || tmp[0] == '#' ) {
|
||||
if ( isBlankOrCommentLine(line) )
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((line_num % 100) == 0) {
|
||||
// every 100 lines
|
||||
|
@ -144,7 +140,8 @@ public:
|
|||
cache->setRebuildPhaseProgress(NavDataCache::REBUILD_AIRPORTS, percent);
|
||||
}
|
||||
|
||||
line_id = atoi(tmp);
|
||||
// Extract the first field into 'line_id'
|
||||
line_id = atoi(line.c_str());
|
||||
|
||||
if ( line_id == 1 /* Airport */ ||
|
||||
line_id == 16 /* Seaplane base */ ||
|
||||
|
@ -228,6 +225,13 @@ private:
|
|||
NavDataCache* cache;
|
||||
PositionedID currentAirportID;
|
||||
|
||||
// Tell whether an apt.dat line is blank or a comment line
|
||||
bool isBlankOrCommentLine(const std::string& line)
|
||||
{
|
||||
size_t pos = line.find_first_not_of(" \t");
|
||||
return ( pos == std::string::npos || line.find("##", pos) == pos );
|
||||
}
|
||||
|
||||
void throwExceptionIfStreamError(const sg_gzifstream& input_stream,
|
||||
const std::string& short_name,
|
||||
const std::string& full_path)
|
||||
|
|
Loading…
Add table
Reference in a new issue