39 #ifndef OPENIMAGEIO_OPTPARSER_H
40 #define OPENIMAGEIO_OPTPARSER_H
52 optparse1 (C &system,
const std::string &opt)
54 std::string::size_type eq_pos = opt.find_first_of (
"=");
55 if (eq_pos == std::string::npos) {
59 std::string name (opt, 0, eq_pos);
61 while (name.size() && name[0] ==
' ')
63 while (name.size() && name[name.size()-1] ==
' ')
64 name.erase (name.size()-1);
65 std::string value (opt, eq_pos+1, std::string::npos);
68 char v = value.size() ? value[0] :
' ';
69 if ((v >=
'0' && v <=
'9') || v ==
'+' || v ==
'-') {
70 if (strchr (value.c_str(),
'.'))
71 return system.attribute (name.c_str(), (float)atof(value.c_str()));
73 return system.attribute (name.c_str(), (int)atoi(value.c_str()));
78 if (value.size() >= 2 &&
79 value[0] ==
'\"' && value[value.size()-1] ==
'\"')
80 value = std::string (value, 1, value.size()-2);
82 return system.attribute (name.c_str(), value.c_str());
95 optparser (C &system,
const std::string &optstring)
98 size_t len = optstring.length();
102 bool inquote =
false;
104 unsigned char c = optstring[pos];
110 }
else if (c ==
',' && !inquote) {
121 ok &= optparse1 (system, opt);
130 #endif // OPENIMAGEIO_OPTPARSER_H