version 1.12 | version 1.13 |
---|
| |
| |
| |
// space & tab | // space & tab |
std::string const colvarparse::white_space = " \t"; | char const * const colvarparse::white_space = " \t"; |
| |
std::string colvarparse::dummy_string = ""; | |
size_t colvarparse::dummy_pos = 0; | |
| |
| |
// definition of single-value keyword parsers | // definition of single-value keyword parsers |
| |
| |
do { | do { |
std::string data_this = ""; | std::string data_this = ""; |
b_found = key_lookup(conf, key, data_this, save_pos); | b_found = key_lookup(conf, key, &data_this, &save_pos); |
if (b_found) { | if (b_found) { |
if (!b_found_any) | if (!b_found_any) |
b_found_any = true; | b_found_any = true; |
| |
| |
do { | do { |
std::string data_this = ""; | std::string data_this = ""; |
b_found = key_lookup(conf, key, data_this, save_pos); | b_found = key_lookup(conf, key, &data_this, &save_pos); |
if (b_found) { | if (b_found) { |
if (!b_found_any) | if (!b_found_any) |
b_found_any = true; | b_found_any = true; |
| |
| |
do { | do { |
std::string data_this = ""; | std::string data_this = ""; |
b_found = key_lookup(conf, key, data_this, save_pos); | b_found = key_lookup(conf, key, &data_this, &save_pos); |
if (b_found) { | if (b_found) { |
if (!b_found_any) | if (!b_found_any) |
b_found_any = true; | b_found_any = true; |
| |
| |
do { | do { |
std::string data_this = ""; | std::string data_this = ""; |
b_found = key_lookup(conf, key, data_this, save_pos); | b_found = key_lookup(conf, key, &data_this, &save_pos); |
if (b_found) { | if (b_found) { |
if (!b_found_any) | if (!b_found_any) |
b_found_any = true; | b_found_any = true; |
| |
| |
bool colvarparse::key_lookup(std::string const &conf, | bool colvarparse::key_lookup(std::string const &conf, |
char const *key_in, | char const *key_in, |
std::string &data, | std::string *data, |
size_t &save_pos) | size_t *save_pos) |
{ | { |
if (cvm::debug()) { | if (cvm::debug()) { |
cvm::log("Looking for the keyword \""+std::string(key_in)+"\" and its value.\n"); | cvm::log("Looking for the keyword \""+std::string(key_in)+"\" and its value.\n"); |
| |
std::string const conf_lower(to_lower_cppstr(conf)); | std::string const conf_lower(to_lower_cppstr(conf)); |
| |
// by default, there is no value, unless we found one | // by default, there is no value, unless we found one |
data = ""; | if (data != NULL) { |
| data->clear(); |
// when the function is invoked without save_pos, ensure that we | } |
// start from zero | |
colvarparse::dummy_pos = 0; | |
| |
// start from the first occurrence of key | // start from the first occurrence of key |
size_t pos = conf_lower.find(key, save_pos); | size_t pos = conf_lower.find(key, (save_pos != NULL) ? *save_pos : 0); |
| |
// iterate over all instances of the substring until it finds it as isolated keyword | // iterate over all instances of the substring until it finds it as isolated keyword |
while (true) { | while (true) { |
| |
bool b_isolated_left = true, b_isolated_right = true; | bool b_isolated_left = true, b_isolated_right = true; |
| |
if (pos > 0) { | if (pos > 0) { |
if ( std::string("\n"+white_space+ | if ( std::string("\n"+std::string(white_space)+ |
"}").find(conf[pos-1]) == | "}").find(conf[pos-1]) == |
std::string::npos ) { | std::string::npos ) { |
// none of the valid delimiting characters is on the left of key | // none of the valid delimiting characters is on the left of key |
| |
} | } |
| |
if (pos < conf.size()-key.size()-1) { | if (pos < conf.size()-key.size()-1) { |
if ( std::string("\n"+white_space+ | if ( std::string("\n"+std::string(white_space)+ |
"{").find(conf[pos+key.size()]) == | "{").find(conf[pos+key.size()]) == |
std::string::npos ) { | std::string::npos ) { |
// none of the valid delimiting characters is on the right of key | // none of the valid delimiting characters is on the right of key |
| |
} | } |
} | } |
| |
| if (save_pos != NULL) { |
// save the pointer for a future call (when iterating over multiple | // save the pointer for a future call (when iterating over multiple |
// valid instances of the same keyword) | // valid instances of the same keyword) |
save_pos = pos + key.size(); | *save_pos = pos + key.size(); |
| } |
| |
// get the remainder of the line | // get the remainder of the line |
size_t pl = conf.rfind("\n", pos); | size_t pl = conf.rfind("\n", pos); |
| |
data_end) + 1; | data_end) + 1; |
} | } |
| |
data.append(line, data_begin, (data_end-data_begin)); | if (data != NULL) { |
| data->append(line, data_begin, (data_end-data_begin)); |
| |
if (cvm::debug()) { | if (cvm::debug()) { |
cvm::log("Keyword value = \""+data+"\".\n"); | cvm::log("Keyword value = \""+*data+"\".\n"); |
} | } |
| |
if (data.size() && save_delimiters) { | if (data->size()) { |
data_begin_pos.push_back(conf.find(data, pos+key.size())); | data_begin_pos.push_back(conf.find(*data, pos+key.size())); |
data_end_pos.push_back(data_begin_pos.back()+data.size()); | data_end_pos.push_back(data_begin_pos.back()+data->size()); |
| } |
} | } |
} | } |
| |
save_pos = line_end; | if (save_pos != NULL) *save_pos = line_end; |
| |
return true; | return true; |
} | } |