advgetopt/validator.cpp
/** \brief Set the validator for this option.
 *
 * This function parses the specified name and optional parameters and
 * create a corresponding validator for this option.
 *
 * The \p name_and_params string can be defined as:
 *
 * \code
 *     <validator-name>(<param1>, <param2>, ...)
 * \endcode
 *
 * The list of parameters is optional. There may be an empty, just one,
 * or any number of parameters. How the parameters are parsed is left
 * to the validator to decide.
 *
 * If the input string is empty, the current validator, if one is
 * installed, gets removed.
 *
 * \param[in] name_and_params  The validator name and parameters.
 */
\brief Set the validator for this option.
This function parses the specified name and optional parameters and
create a corresponding validator for this option.

The \p name_and_params string can be defined as.



The list of parameters is optional. There may be an empty, just one,
or any number of parameters. How the parameters are parsed is left
to the validator to decide.

If the input string is empty, the current validator, if one is
installed, gets removed.

\param[in] name_and_params  The validator name and parameters.
\ brief Set the validator for this option . This function parses the specified name and optional parameters and create a corresponding validator for this option . The \ p name_and_params string can be defined as . The list of parameters is optional . There may be an empty just one or any number of parameters . How the parameters are parsed is left to the validator to decide . If the input string is empty the current validator if one is installed gets removed . \ param [ in ] name_and_params The validator name and parameters .
validator::pointer_t validator::create(std::string const & name_and_params)
{
    if(name_and_params.empty())
    {
        return validator::pointer_t();
    }
    if(name_and_params.length() >= 2
    && name_and_params[0] == '/')
    {
        string_list_t data{name_and_params};
        return create("regex", data);
    }
    else
    {
        std::string::size_type const params(name_and_params.find('('));
        std::string name(name_and_params);
        string_list_t data;
        if(params != std::string::npos)
        {
            if(name_and_params.back() != ')')
            {
                throw getopt_logic_error(
                      "invalid validator parameter definition: \""
                    + name_and_params
                    + "\", the ')' is missing.");
            }
            name = name_and_params.substr(0, params);
            split_string(name_and_params.substr(params + 1, name_and_params.length() - params - 2)
                       , data
                       , {","});
        }
        return create(name, data);
    }
}
validator :: pointer_t validator :: create ( std :: string const & name_and_params ) { if ( name_and_params . empty ( ) ) { return validator :: pointer_t ( ) ; } if ( name_and_params . length ( ) >= 2 && name_and_params [ 0 ] == ' ' ) { string_list_t data { name_and_params } ; return create ( " " , data ) ; } else { std :: string :: size_type const params ( name_and_params . find ( ' ' ) ) ; std :: string name ( name_and_params ) ; string_list_t data ; if ( params != std :: string :: npos ) { if ( name_and_params . back ( ) != ' ' ) { throw getopt_logic_error ( " \" " + name_and_params + " \" " ) ; } name = name_and_params . substr ( 0 , params ) ; split_string ( name_and_params . substr ( params + 1 , name_and_params . length ( ) - params - 2 ) , data , { " " } ) ; } return create ( name , data ) ; } }
\brief Set the validator for this option.
\ brief Set the validator for this option .
// for the regex we have a special case //