Changeset 5ebff60 for lib/json_util.c
- Timestamp:
- 2015-02-20T22:50:54Z (10 years ago)
- Branches:
- master
- Children:
- 0b9daac, 3d45471, 7733b8c
- Parents:
- af359b4
- git-author:
- Indent <please@…> (19-02-15 05:47:20)
- git-committer:
- dequis <dx@…> (20-02-15 22:50:54)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/json_util.c
raf359b4 r5ebff60 28 28 #include "json_util.h" 29 29 30 json_value *json_o_get( const json_value *obj, const json_char *name)31 { 30 json_value *json_o_get(const json_value *obj, const json_char *name) 31 { 32 32 int i; 33 34 if ( !obj || obj->type != json_object )33 34 if (!obj || obj->type != json_object) { 35 35 return NULL; 36 } 36 37 37 for ( i = 0; i < obj->u.object.length; ++ i)38 if ( strcmp( obj->u.object.values[i].name, name ) == 0 )38 for (i = 0; i < obj->u.object.length; ++i) { 39 if (strcmp(obj->u.object.values[i].name, name) == 0) { 39 40 return obj->u.object.values[i].value; 41 } 42 } 40 43 41 44 return NULL; 42 45 } 43 46 44 const char *json_o_str( const json_value *obj, const json_char *name)45 { 46 json_value *ret = json_o_get( obj, name);47 48 if ( ret && ret->type == json_string )47 const char *json_o_str(const json_value *obj, const json_char *name) 48 { 49 json_value *ret = json_o_get(obj, name); 50 51 if (ret && ret->type == json_string) { 49 52 return ret->u.string.ptr; 50 else53 } else { 51 54 return NULL; 55 } 52 56 } 53 57 54 char *json_o_strdup( const json_value *obj, const json_char *name)58 char *json_o_strdup(const json_value *obj, const json_char *name) 55 59 { 56 json_value *ret = json_o_get( obj, name);57 58 if ( ret && ret->type == json_string && ret->u.string.ptr )59 return g_memdup( ret->u.string.ptr, ret->u.string.length + 1);60 else60 json_value *ret = json_o_get(obj, name); 61 62 if (ret && ret->type == json_string && ret->u.string.ptr) { 63 return g_memdup(ret->u.string.ptr, ret->u.string.length + 1); 64 } else { 61 65 return NULL; 66 } 62 67 }
Note: See TracChangeset
for help on using the changeset viewer.