Skip to content
Snippets Groups Projects

JobOptionSvc: use stringstream to read job options file

Merged Frank Winklmeier requested to merge fwinkl/Gaudi:joparser_ubsan into master
All threads resolved!
@@ -29,30 +29,24 @@ namespace gpu = Gaudi::Parsers::Utils;
namespace qi = boost::spirit::qi;
// ============================================================================
namespace {
// ============================================================================
void GetLastLineAndColumn( std::ifstream& ifs, int& line, int& column ) {
int n = 0;
std::string str;
while ( !ifs.eof() ) {
getline( ifs, str );
++n;
// Return last line and column number of text in `s` with newline delimiter `delim`
std::pair<size_t, size_t> GetLastLineAndColumn( std::string_view s, const char delim = '\n' ) {
size_t line = 1;
for ( size_t p = s.find( delim ); p != s.npos; p = s.find( delim ) ) {
s.remove_prefix( p + 1 );
++line;
}
line = n;
column = str.length() + 1;
ifs.clear();
ifs.seekg( 0, ifs.beg );
return { line, s.size() + 1 };
}
template <typename Grammar>
bool ParseStream( std::ifstream& stream, const std::string& stream_name, gp::Messages* messages, gp::Node* root ) {
int last_line, last_column;
GetLastLineAndColumn( stream, last_line, last_column );
std::stringstream ss;
std::ostringstream ss;
ss << stream.rdbuf();
const std::string& input = ss.str();
const std::string input = ss.str();
auto [last_line, last_column] = GetLastLineAndColumn( input );
BaseIterator in_begin( input.begin() );
// convert input iterator to forward iterator, usable by spirit parser
@@ -60,7 +54,6 @@ namespace {
ForwardIterator fwd_end;
// wrap forward iterator with position iterator, to record the position
Iterator position_begin( fwd_begin, fwd_end, stream_name );
Iterator position_end;
Loading