add limits when parsing a json/space format
while here: - add column index error - add parsing methods with pt::TextStream and pt::WTextStream arguments
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021, Tomasz Sowa
|
||||
* Copyright (c) 2021-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -52,6 +52,7 @@ BaseParser::BaseParser()
|
||||
void BaseParser::clear_input_flags()
|
||||
{
|
||||
line = 0;
|
||||
column = 0;
|
||||
reading_from_file = false;
|
||||
pchar_ascii = nullptr;
|
||||
pchar_unicode = nullptr;
|
||||
@@ -69,6 +70,16 @@ void BaseParser::clear_input_flags()
|
||||
}
|
||||
|
||||
|
||||
void BaseParser::check_new_line()
|
||||
{
|
||||
if( lastc == '\n' )
|
||||
{
|
||||
++line;
|
||||
column = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int BaseParser::read_utf8_char()
|
||||
{
|
||||
int c;
|
||||
@@ -86,9 +97,7 @@ bool correct;
|
||||
while( !correct );
|
||||
|
||||
lastc = c;
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -97,9 +106,7 @@ return lastc;
|
||||
int BaseParser::read_ascii_char()
|
||||
{
|
||||
lastc = file.get();
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -112,8 +119,7 @@ int BaseParser::read_char_from_wchar_string()
|
||||
else
|
||||
lastc = *(pchar_unicode++);
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -136,8 +142,7 @@ bool correct;
|
||||
if( correct )
|
||||
lastc = c;
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -150,8 +155,7 @@ int BaseParser::read_char_from_ascii_string()
|
||||
else
|
||||
lastc = *(pchar_ascii++);
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -169,8 +173,7 @@ int BaseParser::read_char_from_wtext_stream()
|
||||
lastc = -1;
|
||||
}
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -192,8 +195,7 @@ int BaseParser::read_char_from_utf8_text_stream()
|
||||
if( correct )
|
||||
lastc = c;
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
@@ -211,8 +213,7 @@ int BaseParser::read_char_from_ascii_text_stream()
|
||||
lastc = -1;
|
||||
}
|
||||
|
||||
if( lastc == '\n' )
|
||||
++line;
|
||||
check_new_line();
|
||||
|
||||
return lastc;
|
||||
}
|
||||
|
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2021, Tomasz Sowa
|
||||
* Copyright (c) 2021-2022, Tomasz Sowa
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
@@ -54,6 +54,7 @@ protected:
|
||||
|
||||
virtual void clear_input_flags();
|
||||
|
||||
virtual void check_new_line();
|
||||
virtual int read_utf8_char();
|
||||
virtual int read_ascii_char();
|
||||
virtual int read_char_from_wchar_string();
|
||||
@@ -72,6 +73,11 @@ protected:
|
||||
*/
|
||||
int line;
|
||||
|
||||
/*
|
||||
a number of a column in which there is a syntax_error
|
||||
*/
|
||||
int column;
|
||||
|
||||
|
||||
/*
|
||||
true if parse() method was called
|
||||
|
Reference in New Issue
Block a user