package info parser: improve parse error column numbers

Assume 4 column tab stops and compute the column numbers accordingly.
This commit is contained in:
Ingo Weinhold
2013-05-25 01:12:38 +02:00
parent a3e070a7ff
commit 38a0419a72
+12 -4
View File
@@ -43,20 +43,28 @@ BPackageInfo::Parser::Parse(const BString& packageInfoString,
if (fListener != NULL) { if (fListener != NULL) {
// map error position to line and column // map error position to line and column
int line = 1; int line = 1;
int column; int inLineOffset;
int32 offset = error.pos - packageInfoString.String(); int32 offset = error.pos - packageInfoString.String();
int32 newlinePos = packageInfoString.FindLast('\n', offset - 1); int32 newlinePos = packageInfoString.FindLast('\n', offset - 1);
if (newlinePos < 0) if (newlinePos < 0)
column = offset; inLineOffset = offset;
else { else {
column = offset - newlinePos; inLineOffset = offset - newlinePos - 1;
do { do {
line++; line++;
newlinePos = packageInfoString.FindLast('\n', newlinePos = packageInfoString.FindLast('\n',
newlinePos - 1); newlinePos - 1);
} while (newlinePos >= 0); } while (newlinePos >= 0);
} }
fListener->OnError(error.message, line, column);
int column = 0;
for (int i = 0; i < inLineOffset; i++) {
column++;
if (error.pos[i - inLineOffset] == '\t')
column = (column + 3) / 4 * 4;
}
fListener->OnError(error.message, line, column + 1);
} }
return B_BAD_DATA; return B_BAD_DATA;
} catch (const std::bad_alloc& e) { } catch (const std::bad_alloc& e) {