[Ipopt-tickets] [Ipopt] #77: allow strings with white spaces as values of string options
Ipopt
coin-trac at coin-or.org
Thu May 29 09:09:28 EDT 2008
#77: allow strings with white spaces as values of string options
------------------------------+---------------------------------------------
Reporter: stefan | Owner: ipopt-team
Type: enhancement | Status: new
Priority: normal | Component: Ipopt
Version: 3.4 (C++ Version) | Severity: normal
Keywords: |
------------------------------+---------------------------------------------
Hi,
for the Ipopt options lists, I would like to use a string option that can
take an arbitrary value as argument that is also allowed to contain
whitespaces.
Currently, {{{OptionsList::readnexttoken}}} does not allow this.
Tokens are here separated by spaces and there seem to be no way to escape
a space.
A way to improve this would be to allow arbitrary strings that are
enclosed by quotes, e.g.,
{{{"my nice string option value"}}}.
A possible way to adapt {{{OptionsList::readnexttoken}}} for this is
{{{
bool OptionsList::readnexttoken(std::istream& is, std::string& token)
{
token.erase();
int c = is.get();
// First get rid of all comments and white spaces
while (!is.eof() && (isspace(c) || c=='#') ) {
if (c=='#') {
is.ignore(10000000, '\n');
}
c=is.get();
}
bool inside_quotes = (c=='"');
if (inside_quotes) {
if (is.eof()) return false; // eof after quotation symbol
c=is.get();
}
// Now read the token
while (!is.eof() && (inside_quotes || !isspace(c))) {
token += c;
c = is.get();
if (inside_quotes && (c=='"')) {
inside_quotes = false;
if (!is.eof())
c = is.get();
}
}
return (!is.eof());
}
}}}
Best,
Stefan
--
Ticket URL: <https://projects.coin-or.org/Ipopt/ticket/77>
Ipopt <http://projects.coin-or.org/Ipopt>
Interior-point optimizer for nonlinear programs.
More information about the Ipopt-tickets
mailing list