advgetopt/conf_file.cpp
/** \brief Get one line.
 *
 * This function reads one line. The function takes the line continuation
 * setup in account. So for example a line that ends with a backslash
 * continues on the next line when the line continuation is setup to Unix.
 *
 * Note that by default comments are also continued. So a backslash in
 * Unix mode continues a comment on the next line.
 *
 * There is a special case with the semicolon continuation setup. When
 * the line starts as a comment, it will end on the first standalone
 * newline (i.e. a comment does not need to end with a semi-colon.)
 *
 * \param[in,out] in  The input stream.
 * \param[out] line  Where the line gets saved.
 *
 * \return true if a line was read, false on EOF.
 */
\brief Get one line.
This function reads one line. The function takes the line continuation
setup in account. So for example a line that ends with a backslash
continues on the next line when the line continuation is setup to Unix.

Note that by default comments are also continued. So a backslash in
Unix mode continues a comment on the next line.

There is a special case with the semicolon continuation setup. When
the line starts as a comment, it will end on the first standalone
newline

\param[in,out] in  The input stream.
\param[out] line  Where the line gets saved.

\return true if a line was read, false on EOF.
\ brief Get one line . This function reads one line . The function takes the line continuation setup in account . So for example a line that ends with a backslash continues on the next line when the line continuation is setup to Unix . Note that by default comments are also continued . So a backslash in Unix mode continues a comment on the next line . There is a special case with the semicolon continuation setup . When the line starts as a comment it will end on the first standalone newline \ param [ in out ] in The input stream . \ param [ out ] line Where the line gets saved . \ return true if a line was read false on EOF .
bool conf_file::get_line(std::ifstream & in, std::string & line)
{
    line.clear();
    for(;;)
    {
        int c(getc(in));
        if(c == EOF)
        {
            return false;
        }
        if(c == ';'
        && f_setup.get_line_continuation() == line_continuation_t::line_continuation_semicolon)
        {
            return true;
        }
        while(c == '\n' || c == '\r')
        {
            if(c == '\r')
            {
                c = getc(in);
                if(c != '\n')
                {
                    ungetc(c);
                }
                c = '\n';
            }
            ++f_line;
            switch(f_setup.get_line_continuation())
            {
            case line_continuation_t::line_continuation_single_line:
                 continuation support
                return true;
            case line_continuation_t::line_continuation_rfc_822:
                c = getc(in);
                if(!iswspace(c))
                {
                    ungetc(c);
                    return true;
                }
                do
                {
                    c = getc(in);
                }
                while(iswspace(c));
                break;
            case line_continuation_t::line_continuation_msdos:
                if(line.empty()
                || line.back() != '&')
                {
                    return true;
                }
                line.pop_back();
                c = getc(in);
                break;
            case line_continuation_t::line_continuation_unix:
                if(line.empty()
                || line.back() != '\\')
                {
                    return true;
                }
                line.pop_back();
                c = getc(in);
                break;
            case line_continuation_t::line_continuation_fortran:
                c = getc(in);
                if(c != '&')
                {
                    ungetc(c);
                    return true;
                }
                c = getc(in);
                break;
            case line_continuation_t::line_continuation_semicolon:
                 if we have a comment, we want to return immediately;
                 at this time, the comments are not multi-line so
                 the call can return true only if we were reading the
                 very first line
                if(is_comment(line.c_str()))
                {
                    return true;
                }
                 the semicolon is checked earlier, just keep the newline
                 in this case (but not at the start)
                if(!line.empty() || c != '\n')
                {
                    line += c;
                }
                c = getc(in);
                break;
            }
        }
         we just read the last line
        if(c == EOF)
        {
            return true;
        }
        line += c;
    }
}
bool conf_file :: get_line ( std :: ifstream & in , std :: string & line ) { line . clear ( ) ; for ( ; ; ) { int c ( getc ( in ) ) ; if ( c == EOF ) { return false ; } if ( c == ' ' && f_setup . get_line_continuation ( ) == line_continuation_t :: line_continuation_semicolon ) { return true ; } while ( c == ' \n ' || c == ' \r ' ) { if ( c == ' \r ' ) { c = getc ( in ) ; if ( c != ' \n ' ) { ungetc ( c ) ; } c = ' \n ' ; } ++ f_line ; switch ( f_setup . get_line_continuation ( ) ) { case line_continuation_t :: line_continuation_single_line : return true ; case line_continuation_t :: line_continuation_rfc_822 : c = getc ( in ) ; if ( ! iswspace ( c ) ) { ungetc ( c ) ; return true ; } do { c = getc ( in ) ; } while ( iswspace ( c ) ) ; break ; case line_continuation_t :: line_continuation_msdos : if ( line . empty ( ) || line . back ( ) != ' ' ) { return true ; } line . pop_back ( ) ; c = getc ( in ) ; break ; case line_continuation_t :: line_continuation_unix : if ( line . empty ( ) || line . back ( ) != ' \\ ' ) { return true ; } line . pop_back ( ) ; c = getc ( in ) ; break ; case line_continuation_t :: line_continuation_fortran : c = getc ( in ) ; if ( c != ' ' ) { ungetc ( c ) ; return true ; } c = getc ( in ) ; break ; case line_continuation_t :: line_continuation_semicolon : if ( is_comment ( line . c_str ( ) ) ) { return true ; } if ( ! line . empty ( ) || c != ' \n ' ) { line += c ; } c = getc ( in ) ; break ; } } if ( c == EOF ) { return true ; } line += c ; } }
\brief Get one line.
\ brief Get one line .
// count the "\r\n" sequence as one line // // continuation support // if we have a comment, we want to return immediately; // at this time, the comments are not multi-line so // the call can return true only if we were reading the // very first line // // the semicolon is checked earlier, just keep the newline // in this case (but not at the start) // // we just read the last line