diff options
author | ritsuka <[email protected]> | 2015-05-30 07:45:00 +0000 |
---|---|---|
committer | ritsuka <[email protected]> | 2015-05-30 07:45:00 +0000 |
commit | 39eff9d080effd0138c91f397632d24b38f7a441 (patch) | |
tree | 04e529f8b72ad44a628c6717a3b80afcc3950bb2 /macosx/NSJSONSerialization+HBAdditions.m | |
parent | 2837048a59ac5beab0b3428ca89c86857765de0a (diff) |
MacGui: fix the leaks after using hb_presets_import_json and hb_presets_clean_json, add an extension to NSJSONSerialization to convert a char * directly.
git-svn-id: svn://svn.handbrake.fr/HandBrake/trunk@7245 b64f7644-9d1e-0410-96f1-a4d463321fa5
Diffstat (limited to 'macosx/NSJSONSerialization+HBAdditions.m')
-rw-r--r-- | macosx/NSJSONSerialization+HBAdditions.m | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/macosx/NSJSONSerialization+HBAdditions.m b/macosx/NSJSONSerialization+HBAdditions.m new file mode 100644 index 000000000..0f18eb17c --- /dev/null +++ b/macosx/NSJSONSerialization+HBAdditions.m @@ -0,0 +1,29 @@ +/* NSJSONSerialization+HBAdditions.m $ + + This file is part of the HandBrake source code. + Homepage: <http://handbrake.fr/>. + It may be used under the terms of the GNU General Public License. */ + +#import "NSJSONSerialization+HBAdditions.h" + +@implementation NSJSONSerialization (HBAdditions) + ++ (id)HB_JSONObjectWithUTF8String:(const char *)nullTerminatedCString options:(NSJSONReadingOptions)opt error:(NSError **)error; +{ + NSData *data = [NSData dataWithBytes:nullTerminatedCString length:strlen(nullTerminatedCString)]; + id result = [NSJSONSerialization JSONObjectWithData:data options:opt error:error]; + return result; +} + ++ (NSString *)HB_StringWithJSONObject:(id)obj options:(NSJSONWritingOptions)opt error:(NSError **)error +{ + NSData *data = [NSJSONSerialization dataWithJSONObject:obj options:opt error:error]; + if (data) + { + return [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; + } + + return nil; +} + +@end |