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() ) ;
50 std::string_view sv( line ) ;
52 std::string_view key = t() ;
53 if( key.empty() || key.find(
'#') == 0U )
56 std::string_view value = (++t)() ;
59 if( value.size() >= 2U && value[0] ==
'"' && value[value.size()-1U] ==
'"' )
60 value = value.substr( 1U , value.size() - 2U ) ;
62 out.push_back( std::string(2U,
'-')
63 .append(key.data(),key.size())
64 .append(value.empty()?0U:1U,
'=')
65 .append(value.data(),value.size()) ) ;
69 if( limit && n == limit )
70 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::string & trimRight(std::string &s, std::string_view ws, std::size_t limit=0U)
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
static std::string_view trimRightView(std::string_view sv, std::string_view ws, std::size_t limit=0U) noexcept
Trims the rhs of s, taking off up to 'limit' of the 'ws' characters.
static std::istream & readLine(std::istream &stream, std::string &result, std::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.
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().
std::vector< std::string > StringArray
A std::vector of std::strings.