Ejemplo n.º 1
0
static int json_pointer_get_single_path(struct json_object *obj, char *path, struct json_object **value)
{
	if (json_object_is_type(obj, json_type_array)) {
		int32_t idx;
		if (!is_valid_index(obj, path, &idx))
			return -1;
		obj = json_object_array_get_idx(obj, idx);
		if (obj) {
			if (value)
				*value = obj;
			return 0;
		}
		/* Entry not found */
		errno = ENOENT;
		return -1;
	}

	/* RFC states that we first must eval all ~1 then all ~0 */
	string_replace_all_occurrences_with_char(path, "~1", '/');
	string_replace_all_occurrences_with_char(path, "~0", '~');

	if (!json_object_object_get_ex(obj, path, value)) {
		errno = ENOENT;
		return -1;
	}

	return 0;
}
Ejemplo n.º 2
0
static int json_pointer_set_single_path(
	struct json_object *parent,
	const char *path,
	struct json_object *value)
{
	if (json_object_is_type(parent, json_type_array)) {
		int32_t idx;
		/* RFC (Chapter 4) states that '-' may be used to add new elements to an array */
		if (path[0] == '-' && path[1] == '\0')
			return json_object_array_add(parent, value);
		if (!is_valid_index(parent, path, &idx))
			return -1;
		return json_object_array_put_idx(parent, idx, value);
	}

	/* path replacements should have been done in json_pointer_get_single_path(),
	   and we should still be good here */
	if (json_object_is_type(parent, json_type_object))
		return json_object_object_add(parent, path, value);

	/* Getting here means that we tried to "dereference" a primitive JSON type (like string, int, bool).
	   i.e. add a sub-object to it */
	errno = ENOENT;
	return -1;
}
Ejemplo n.º 3
0
char
index2mark(const int index)
{
	if(is_valid_index(index))
	{
		return valid_marks[index];
	}
	return '\0';
}
Ejemplo n.º 4
0
char
index2mark(const int bmark_index)
{
	if(is_valid_index(bmark_index))
	{
		return valid_bookmarks[bmark_index];
	}
	return '\0';
}
Ejemplo n.º 5
0
int list_remove(StringList *list, int index){
    int i;
    if(is_valid_index(*list, index)){
        // for each one until the end, copy the string
        for(i = index; i < list->size - 1; i++)
            list->string[i] = copy_string(list->string[i+1]);
        // and removes the last
        dispose_string(&list->string[list->size-1]);
        list->string = (String*) realloc(list->string, sizeof(String)*(--list->size));
        return 1;
    }else
        return 0;
}
Ejemplo n.º 6
0
/* Gets mark by its index.  Returns pointer to a statically allocated mark_t
 * structure or NULL for wrong index. */
static mark_t *
find_mark(const int index)
{
	int spec_mark_index;

	if(!is_valid_index(index))
	{
		return NULL;
	}

	if(index < NUM_REGULAR_MARKS)
	{
		return &regular_marks[index];
	}

	spec_mark_index = index - NUM_REGULAR_MARKS;
	return (curr_view == &lwin)
	     ? &lspecial_marks[spec_mark_index]
	     : &rspecial_marks[spec_mark_index];
}
Ejemplo n.º 7
0
/* Gets bookmark by its index.  Returns pointer to a statically allocated
 * bookmark_t structure or NULL for wrong index. */
static bookmark_t *
get_bmark(const int bmark_index)
{
	int spec_bmark_index;

	if(!is_valid_index(bmark_index))
	{
		return NULL;
	}

	if(bmark_index < NUM_REGULAR_BOOKMARKS)
	{
		return &regular_bookmarks[bmark_index];
	}

	spec_bmark_index = bmark_index - NUM_REGULAR_BOOKMARKS;
	return (curr_view == &lwin)
	     ? &lspecial_bookmarks[spec_bmark_index]
	     : &rspecial_bookmarks[spec_bmark_index];
}
Ejemplo n.º 8
0
field row::operator[](const std::size_t &column_index) const {
    assert(is_valid_index(column_index) && "invalid column index requested");
    if (! is_valid_index(column_index))
        throw error("no column at index " + std::to_string(column_index));
    return {stmt, column_index};
}
Ejemplo n.º 9
0
/**
Returns a reference to the element at index __i__ in the array.

\param __i__ index
*/
const double& dvector::operator()(int i) const
{
  assert((index_min <= i && i <= index_max) || is_valid_index(i));

  return *(v + i);
}