Beispiel #1
0
pair<string_view, string_view> splitPair(string_view s, char delim) noexcept
{
  const auto pos = s.find_first_of(delim);
  string_view key, val;
  if (pos == string_view::npos) {
    key = s;
  } else {
    key = s.substr(0, pos);
    val = s.substr(pos + 1);
  }
  return {key, val};
}
Beispiel #2
0
static void
parse_elements (string_view name, TypeDesc type, const char *type_code,
                string_view value, ImageIOParameter &param)
{
    int num_items = type.numelements() * type.aggregate;
    T *data = (T*) param.data();
    // Erase any leading whitespace
    value.remove_prefix (value.find_first_not_of (" \t"));
    for (int i = 0;  i < num_items;  ++i) {
        // Make a temporary copy so we for sure have a 0-terminated string.
        std::string temp = value;
        // Grab the first value from it
        sscanf (temp.c_str(), type_code, &data[i]);
        // Skip the value (eat until we find a delimiter -- space, comma, tab)
        value.remove_prefix (value.find_first_of (" ,\t"));
        // Skip the delimiter
        value.remove_prefix (value.find_first_not_of (" ,\t"));
        if (value.empty())
            break;   // done if nothing left to parse
    }
}