from an osrfList without destroying it, and returns a pointer to
the item thus removed.
2. Create a new jsonObjectExtractIndex, which removes a
specified entry in a JSON_ARRAY, and returns a pointer
to it, without destroying it.
3. In osrf_json.h: Corrected an inaccurate comment about
jsonObjectRemoveIndex(). Contrary to the original comment, this
function does not shift other objects down to fill the gap.
git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@1689
9efc2488-bf62-4759-914b-
345cdb29e865
*/
unsigned long jsonObjectSetIndex(jsonObject* dest, unsigned long index, jsonObject* newObj);
-/* removes the object at the given index and, if more items exist,
- * re-indexes (shifts down by 1) the rest of the objects in the array
+/* removes and deallocates the object at the given index, replacing
+ it with a NULL pointer
*/
unsigned long jsonObjectRemoveIndex(jsonObject* dest, unsigned long index);
+/* removes (but does not deallocate) the object at the given index,
+ * replacing it with a NULL pointer; returns a pointer to the object removed
+ */
+jsonObject* jsonObjectExtractIndex(jsonObject* dest, unsigned long index);
+
/* removes (and deallocates) the object with key 'key' if it exists */
unsigned long jsonObjectRemoveKey( jsonObject* dest, const char* key);
void* osrfListRemove( osrfList* list, unsigned int position );
/**
+ Removes the list item at the given index, without freeing it
+ @param list The list
+ @param position The position of the item to remove
+ @return A pointer to the item extracted, or NULL
+ if there is nothing to extract
+ */
+void* osrfListExtract( osrfList* list, unsigned int position );
+
+/**
Finds the list item whose void* is the same as the one passed in
@param list The list
@param addr The pointer connected to the list item we're to find
while( (item = osrfHashIteratorNext(itr)) ) {
if(i++ > 0) OSRF_BUFFER_ADD_CHAR(buf, ',');
OSRF_BUFFER_ADD_CHAR(buf, '"');
- buffer_append_utf8(buf, osrfHashIteratorKey(itr));
+ buffer_append_utf8(buf, osrfHashIteratorKey(itr));
OSRF_BUFFER_ADD(buf, "\":");
add_json_to_buffer( item, buf, do_classname, second_pass );
}
}
+jsonObject* jsonObjectExtractIndex(jsonObject* dest, unsigned long index) {
+ if( dest && dest->type == JSON_ARRAY ) {
+ return osrfListExtract(dest->value.l, index);
+ } else
+ return NULL;
+}
+
+
unsigned long jsonObjectRemoveKey( jsonObject* dest, const char* key) {
if( dest && key && dest->type == JSON_HASH ) {
osrfHashRemove(dest->value.h, key);
return olditem;
}
+void* osrfListExtract( osrfList* list, unsigned int position ) {
+ if(!list || position >= list->size || position < 0) return NULL;
+
+ void* olditem = list->arrlist[position];
+ list->arrlist[position] = NULL;
+
+ if( position == list->size - 1 ) list->size--;
+ return olditem;
+}
+
int osrfListFind( const osrfList* list, void* addr ) {
if(!(list && addr)) return -1;