formats/json/m_json_jsonpath.c
/*! Turn a string into an index. This will adjust negative numbers to count from the end of the array.
 * On success out will never be < 0. Out can be >= array_len.
 */
Turn a string into an index. This will adjust negative numbers to count from the end of the array.
On success out will never be < 0. Out can be >= array_len.
Turn a string into an index . This will adjust negative numbers to count from the end of the array . On success out will never be < 0 . Out can be > = array_len .
static M_bool M_json_jsonpath_search_array_offset_val(const char *val, size_t val_len, size_t array_len, M_uint32 *out)
{
	M_int32 offset;
	*out = 0;
	if (M_str_to_int32_ex(val, val_len, 10, &offset, NULL) != M_STR_INT_SUCCESS) {
		return M_FALSE;
	}
	if (offset < 0) {
		if ((M_int32)array_len + offset < 0) {
			return M_FALSE;
		}
		*out = (M_uint32)((M_int32)array_len + offset);
	} else {
		*out = (M_uint32)offset;
	}
	return M_TRUE;
}
static M_bool M_json_jsonpath_search_array_offset_val ( const char * val , size_t val_len , size_t array_len , M_uint32 * out ) { M_int32 offset ; * out = 0 ; if ( M_str_to_int32_ex ( val , val_len , 10 , & offset , NULL ) != M_STR_INT_SUCCESS ) { return M_FALSE ; } if ( offset < 0 ) { if ( ( M_int32 ) array_len + offset < 0 ) { return M_FALSE ; } * out = ( M_uint32 ) ( ( M_int32 ) array_len + offset ) ; } else { * out = ( M_uint32 ) offset ; } return M_TRUE ; }
Turn a string into an index.
Turn a string into an index .