struct _jsonIteratorStruct {
jsonObject* obj; /* the object we're traversing */
osrfHashIterator* hashItr; /* the iterator for this hash */
- char* key; /* if this object is an object, the current key */
+ const char* key; /* if this object is a hash, the current key */
unsigned long index; /* if this object is an array, the index */
};
typedef struct _jsonIteratorStruct jsonIterator;
void jsonIteratorFree(jsonIterator* itr) {
if(!itr) return;
- free(itr->key);
osrfHashIteratorFree(itr->hashItr);
free(itr);
}
jsonObject* jsonIteratorNext(jsonIterator* itr) {
if(!(itr && itr->obj)) return NULL;
if( itr->obj->type == JSON_HASH ) {
- if(!itr->hashItr) return NULL;
+ if(!itr->hashItr)
+ return NULL;
+
jsonObject* item = osrfHashIteratorNext(itr->hashItr);
- if(!item) return NULL;
- free(itr->key);
- itr->key = strdup( osrfHashIteratorKey(itr->hashItr) );
+ if( item )
+ itr->key = osrfHashIteratorKey(itr->hashItr);
+ else
+ itr->key = NULL;
return item;
} else {
return jsonObjectGetIndex( itr->obj, itr->index++ );
if( '0' == *p++ ) {
// If the first digit is zero, it must be the
- // only digit to the lerft of the decimal
+ // only digit to the left of the decimal
if( isdigit( (unsigned char) *p ) )
return 0;
}
else {
- // Skip oer the following digits
+ // Skip over the following digits
while( isdigit( (unsigned char) *p ) ) ++p;
}