Skip to content

Commit 29f3d60

Browse files
committed
main: consider BOM in offset and line calculation for making a promise
A multi-table regex parser parses a MIO where all the content of a file are loaded. A MIO may include BOM. However, before starting parsing the file head is moved over the BOM. So the parser never sees the BOM. The infrastructure code for implementing multi-table regex parsers tracks and manages the file offset in the layer(lregex). The offset is used when making a promise to run a guest parser. There is a gap between the offset in the MIO level and the lregex level. In the MIO level, the offset includes the BOM. On the other hand, in the lregex level, the offset doesn't include the BOM; the offset is relative to the end of BOM. ===========V: the MIO level [B][O][M]ABC ==^: the lregex level Because the gap, a multiple table parser may make a promise having wrong offsets if the input file started from a BOM. This change fills the gap by considering the BOM in the functions for converting between offsets and lines. Signed-off-by: Masatake YAMATO <[email protected]>
1 parent 8b459ed commit 29f3d60

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

main/read.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ extern MIOPos getInputFilePositionForLine (unsigned int line)
191191
extern long getInputFileOffsetForLine (unsigned int line)
192192
{
193193
compoundPos *cpos = getInputFileCompoundPosForLine (line);
194-
return cpos->offset;
194+
return cpos->offset - (File.bomFound? 3: 0);
195195
}
196196

197197
extern langType getInputLanguage (void)
@@ -362,6 +362,9 @@ extern unsigned long getInputLineNumberForFileOffset(long offset)
362362
{
363363
compoundPos *p;
364364

365+
if (File.bomFound)
366+
offset += 3;
367+
365368
p = bsearch (&offset, File.lineFposMap.pos, File.lineFposMap.count, sizeof (compoundPos),
366369
compoundPosForOffset);
367370
if (p == NULL)

0 commit comments

Comments
 (0)