read: Move logic for getting a previous character into a read function
This ties related logic together, making it less of a hack and easier to maintain, as well as accessible by all parsers if needed.
This commit is contained in:
parent
a14aa908c5
commit
67f3add7c7
@ -801,10 +801,7 @@ process:
|
||||
* "xxx(raw)xxx";
|
||||
*
|
||||
* which is perfectly valid (yet probably very unlikely). */
|
||||
const unsigned char *base = (unsigned char *) vStringValue (File.line);
|
||||
int prev = '\n';
|
||||
if (File.currentLine - File.ungetchIdx - 2 >= base)
|
||||
prev = (int) *(File.currentLine - File.ungetchIdx - 2);
|
||||
int prev = fileGetNthPrevC (1, 0);
|
||||
|
||||
if (! isident (prev))
|
||||
{
|
||||
|
@ -501,6 +501,18 @@ extern int fileGetc (void)
|
||||
return c;
|
||||
}
|
||||
|
||||
/* returns the nth previous character (0 meaning current), or def if nth cannot
|
||||
* be accessed. Note that this can't access previous line data. */
|
||||
extern int fileGetNthPrevC (unsigned int nth, int def)
|
||||
{
|
||||
const unsigned char *base = (unsigned char *) vStringValue (File.line);
|
||||
|
||||
if (File.currentLine - File.ungetchIdx - 1 - nth >= base)
|
||||
return (int) *(File.currentLine - File.ungetchIdx - 1 - nth);
|
||||
else
|
||||
return def;
|
||||
}
|
||||
|
||||
extern int fileSkipToCharacter (int c)
|
||||
{
|
||||
int d;
|
||||
|
@ -102,6 +102,7 @@ extern boolean fileOpen (const char *const fileName, const langType language);
|
||||
extern boolean fileEOF (void);
|
||||
extern void fileClose (void);
|
||||
extern int fileGetc (void);
|
||||
extern int fileGetNthPrevC (unsigned int nth, int def);
|
||||
extern int fileSkipToCharacter (int c);
|
||||
extern void fileUngetc (int c);
|
||||
extern const unsigned char *fileReadLine (void);
|
||||
|
Loading…
x
Reference in New Issue
Block a user