33 add( result , filename , limit ) ;
41 if( !f.good() )
throw FileError( filename.
str() ) ;
44 while(
Str::readLine(f,line) && ( limit == 0U || n < limit ) )
46 if( line.find(
'\0') != std::string::npos )
47 throw G::Exception(
"invalid character in configuration file" , filename.
str() ) ;
52 if( key.empty() || key.find(
'#') == 0U ) continue ;
56 if( value.size() >= 2U && value[0] ==
'"' && value[value.size()-1U] ==
'"' )
57 value = value.substr( 1U , value.size() - 2U ) ;
58 out.push_back( std::string(2U,
'-')
59 .append(key.data(),key.size())
60 .append(value.empty()?0U:1U,
'=')
61 .append(value.data(),value.size()) ) ;
64 if( limit && n == limit )
65 throw G::Exception(
"too many lines in configuration file" , filename.
str() ) ;
A general-purpose exception class derived from std::exception and containing an error message.
static void open(std::ofstream &, const Path &)
Calls open() on the given output file stream.
static StringArray read(const G::Path &, std::size_t limit=1000U)
Reads options from file as a list of strings like "--foo=bar".
static std::size_t add(StringArray &out, const G::Path &, std::size_t limit=1000U)
Adds options read from file to an existing list.
A Path object represents a file system path.
std::string str() const
Returns the path string.
static std::istream & readLine(std::istream &stream, std::string &result, string_view eol={}, bool pre_erase_result=true, std::size_t limit=0U)
Reads a line from the stream using the given line terminator, which may be multi-character.
static std::string & trimRight(std::string &s, string_view ws, std::size_t limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
static string_view trimRightView(string_view sv, string_view ws, std::size_t limit=0U) noexcept
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
A zero-copy string token iterator where the token separators are runs of whitespace characters,...
std::size_t pos() const noexcept
Returns the offset of data().
A class like c++17's std::string_view.
std::vector< std::string > StringArray
A std::vector of std::strings.