diff options
author | Rodeo <[email protected]> | 2012-03-31 12:33:45 +0000 |
---|---|---|
committer | Rodeo <[email protected]> | 2012-03-31 12:33:45 +0000 |
commit | f8f1631a89c587600d6bfd82a01583afdde9f744 (patch) | |
tree | f3515f3632bf1c347bd73a836110badee65af77b /libhb | |
parent | 53ac2667e27811f96e3d82da706c3371405125e9 (diff) |
Add hb_dict_unset and hb_dict_to_encopts.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@4562 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'libhb')
-rw-r--r-- | libhb/hb_dict.c | 46 | ||||
-rw-r--r-- | libhb/hb_dict.h | 4 |
2 files changed, 49 insertions, 1 deletions
diff --git a/libhb/hb_dict.c b/libhb/hb_dict.c index 6946b563f..31b5492ad 100644 --- a/libhb/hb_dict.c +++ b/libhb/hb_dict.c @@ -109,6 +109,24 @@ void hb_dict_set( hb_dict_t ** dict_ptr, const char * key, const char * value ) } } +void hb_dict_unset( hb_dict_t ** dict_ptr, const char * key ) +{ + hb_dict_t * dict = *dict_ptr; + if( !dict || !dict->objects || !key || !strlen( key ) ) + return; + int i; + for( i = 0; i < dict->count; i++ ) + if( !strcmp( key, dict->objects[i].key ) ) + { + free( dict->objects[i].key ); + if( dict->objects[i].value ) + free( dict->objects[i].value ); + if( i != --dict->count ) + memmove( &dict->objects[i], &dict->objects[i+1], + sizeof( hb_dict_entry_t ) * ( dict->count - i ) ); + } +} + hb_dict_entry_t * hb_dict_get( hb_dict_t * dict, const char * key ) { if( !dict || !dict->objects || !key || !strlen( key ) ) @@ -169,3 +187,31 @@ hb_dict_t * hb_encopts_to_dict( const char * encopts, int encoder ) } return dict; } + +char * hb_dict_to_encopts( hb_dict_t * dict ) +{ + int first_opt = 1; + char *tmp, *encopts_tmp, *encopts = NULL; + hb_dict_entry_t * entry = NULL; + while( ( entry = hb_dict_next( dict, entry ) ) ) + { + tmp = hb_strdup_printf( "%s%s%s%s", + first_opt ? "" : ":", + entry->key, + entry->value ? "=" : "", + entry->value ? entry->value : "" ); + if( tmp ) + { + encopts_tmp = hb_strncat_dup( encopts, tmp, strlen( tmp ) ); + if( encopts_tmp ) + { + if( encopts ) + free( encopts ); + encopts = encopts_tmp; + } + first_opt = 0; + free( tmp ); + } + } + return encopts; +} diff --git a/libhb/hb_dict.h b/libhb/hb_dict.h index 8642d007b..3dd5a0a28 100644 --- a/libhb/hb_dict.h +++ b/libhb/hb_dict.h @@ -22,12 +22,14 @@ typedef struct hb_dict_s hb_dict_t; hb_dict_t * hb_dict_init( int alloc ); void hb_dict_free( hb_dict_t ** dict_ptr ); -void hb_dict_set( hb_dict_t ** dict_ptr, const char * key, const char * value ); +void hb_dict_set( hb_dict_t ** dict_ptr, const char * key, const char * value ); +void hb_dict_unset( hb_dict_t ** dict_ptr, const char * key ); hb_dict_entry_t * hb_dict_get( hb_dict_t * dict, const char * key ); hb_dict_entry_t * hb_dict_next( hb_dict_t * dict, hb_dict_entry_t * previous ); hb_dict_t * hb_encopts_to_dict( const char * encopts, int encoder ); +char * hb_dict_to_encopts( hb_dict_t * dict ); struct hb_dict_entry_s { |