示例#1
0
bool TRI_ReplaceArrayJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name, TRI_json_t* replacement) {
  size_t n;
  size_t i;

  TRI_ASSERT(object->_type == TRI_JSON_ARRAY);
  TRI_ASSERT(name);

  n = object->_value._objects._length;

  for (i = 0;  i < n;  i += 2) {
    TRI_json_t* key;

    key = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i);

    if (! IsString(key)) {
      continue;
    }

    if (TRI_EqualString(key->_value._string.data, name)) {
      TRI_json_t copy;

      // retrieve the old element
      TRI_json_t* old = (TRI_json_t*) TRI_AtVector(&object->_value._objects, i + 1);
      if (old != NULL) {
        TRI_DestroyJson(zone, old);
      }

      TRI_CopyToJson(zone, &copy, replacement);
      TRI_SetVector(&object->_value._objects, i + 1, &copy);
      return true;
    }
  }

  // object not found in array, now simply add it
  TRI_Insert2ArrayJson(zone, object, name, replacement);

  return false;
}
示例#2
0
void TRI_Insert3ArrayJson (TRI_memory_zone_t* zone, TRI_json_t* object, char const* name, TRI_json_t* subobject) {
  TRI_Insert2ArrayJson(zone, object, name, subobject);
  TRI_Free(zone, subobject);
}