vlc | branch: master | Marvin Scholz <[email protected]> | Tue Oct 9 10:40:29 2018 +0200| [ac853e52eb9f10e880c34a7d37c73c33d9afcbd0] | committer: Marvin Scholz
macosx: Add NSString category with string helpers > http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=ac853e52eb9f10e880c34a7d37c73c33d9afcbd0 --- .../package/macosx/VLC.xcodeproj/project.pbxproj | 6 ++ modules/gui/macosx/Makefile.am | 1 + modules/gui/macosx/NSString+Helpers.h | 87 ++++++++++++++++++++++ modules/gui/macosx/NSString+Helpers.m | 74 ++++++++++++++++++ .../gui/macosx/VLCAudioEffectsWindowController.m | 1 + modules/gui/macosx/VLCStringUtility.h | 6 -- modules/gui/macosx/VLCStringUtility.m | 28 ------- .../gui/macosx/VLCVideoEffectsWindowController.m | 1 + 8 files changed, 170 insertions(+), 34 deletions(-) diff --git a/extras/package/macosx/VLC.xcodeproj/project.pbxproj b/extras/package/macosx/VLC.xcodeproj/project.pbxproj index d08dca5e32..e12ff37933 100644 --- a/extras/package/macosx/VLC.xcodeproj/project.pbxproj +++ b/extras/package/macosx/VLC.xcodeproj/project.pbxproj @@ -93,6 +93,7 @@ 6B0AB0F11F1AC8B3003A1B4E /* VLCSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B0AB0EF1F1AC8B3003A1B4E /* VLCSliderCell.m */; }; 6B2EFC601F2819F700F3C0EA /* VLCVolumeSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2EFC5F1F2819F700F3C0EA /* VLCVolumeSlider.m */; }; 6B2EFC631F281A0900F3C0EA /* VLCVolumeSliderCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B2EFC621F281A0900F3C0EA /* VLCVolumeSliderCell.m */; }; + 6B397C4F216C8EB200403ED0 /* NSString+Helpers.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B397C4E216C8EB200403ED0 /* NSString+Helpers.m */; }; 6B3BE42C1E6217CB008D098A /* VLCImageButton.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B3BE42B1E6217CB008D098A /* VLCImageButton.m */; }; 6B4D50901E79781F004479B5 /* VLCHotkeyChangeWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D508F1E79781F004479B5 /* VLCHotkeyChangeWindow.m */; }; 6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */ = {isa = PBXBuildFile; fileRef = 6B4D50921E7979CB004479B5 /* VLCSimplePrefsWindow.m */; }; @@ -190,6 +191,8 @@ 6B2EFC5F1F2819F700F3C0EA /* VLCVolumeSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCVolumeSlider.m; sourceTree = "<group>"; }; 6B2EFC611F281A0900F3C0EA /* VLCVolumeSliderCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCVolumeSliderCell.h; sourceTree = "<group>"; }; 6B2EFC621F281A0900F3C0EA /* VLCVolumeSliderCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCVolumeSliderCell.m; sourceTree = "<group>"; }; + 6B397C4D216C8EB200403ED0 /* NSString+Helpers.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "NSString+Helpers.h"; sourceTree = "<group>"; }; + 6B397C4E216C8EB200403ED0 /* NSString+Helpers.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "NSString+Helpers.m"; sourceTree = "<group>"; }; 6B3BE42A1E6217CB008D098A /* VLCImageButton.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCImageButton.h; sourceTree = "<group>"; }; 6B3BE42B1E6217CB008D098A /* VLCImageButton.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = VLCImageButton.m; sourceTree = "<group>"; }; 6B4D508E1E79781F004479B5 /* VLCHotkeyChangeWindow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = VLCHotkeyChangeWindow.h; sourceTree = "<group>"; }; @@ -988,6 +991,8 @@ 8ED6C28003E2EB1C0059A3A7 /* misc.m */, CC269A4615E7947F00F2FDC9 /* VLCStringUtility.h */, CC269A4715E7947F00F2FDC9 /* VLCStringUtility.m */, + 6B397C4D216C8EB200403ED0 /* NSString+Helpers.h */, + 6B397C4E216C8EB200403ED0 /* NSString+Helpers.m */, 6B7F1FDD1F07DA920002BDD8 /* VLCHexNumberFormatter.h */, 6B7F1FDE1F07DA920002BDD8 /* VLCHexNumberFormatter.m */, ); @@ -1607,6 +1612,7 @@ 1C3113F11E508C7600D4DD76 /* VLCRendererItem.m in Sources */, 1C3113F31E508C7600D4DD76 /* VLCRendererMenuController.m in Sources */, 6B4D50931E7979CB004479B5 /* VLCSimplePrefsWindow.m in Sources */, + 6B397C4F216C8EB200403ED0 /* NSString+Helpers.m in Sources */, 1C31138E1E508C6900D4DD76 /* VLCAboutWindowController.m in Sources */, 1C3113901E508C6900D4DD76 /* VLCHelpWindowController.m in Sources */, 1C3113921E508C6900D4DD76 /* VLCAddonListItem.m in Sources */, diff --git a/modules/gui/macosx/Makefile.am b/modules/gui/macosx/Makefile.am index 3be6795db7..fde34dcdc2 100644 --- a/modules/gui/macosx/Makefile.am +++ b/modules/gui/macosx/Makefile.am @@ -26,6 +26,7 @@ endif libmacosx_plugin_la_SOURCES = \ gui/macosx/helpers.h \ + gui/macosx/NSString+Helpers.h gui/macosx/NSString+Helpers.m \ gui/macosx/VLCAboutWindowController.h gui/macosx/VLCAboutWindowController.m \ gui/macosx/VLCAddonListItem.h gui/macosx/VLCAddonListItem.m \ gui/macosx/VLCAddonsWindowController.h gui/macosx/VLCAddonsWindowController.m \ diff --git a/modules/gui/macosx/NSString+Helpers.h b/modules/gui/macosx/NSString+Helpers.h new file mode 100644 index 0000000000..35c18a7d5e --- /dev/null +++ b/modules/gui/macosx/NSString+Helpers.h @@ -0,0 +1,87 @@ +/***************************************************************************** + * NSString+Helpers.h: Category with helper functions for NSStrings + ***************************************************************************** + * Copyright (C) 2002-2018 VLC authors and VideoLAN + * $Id$ + * + * Authors: Jon Lech Johansen <[email protected]> + * Christophe Massiot <[email protected]> + * Derk-Jan Hartman <hartman at videolan dot org> + * Felix Paul Kühne <fkuehne at videolan dot org> + * Marvin Scholz <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#import <Foundation/Foundation.h> + +@interface NSString (Helpers) + +/** + Creates an NSString from the given null-terminated C string + buffer encoded as base64 + + This method allocates and initializes an NSString with the + provided C string encoded as base64. + */ ++ (instancetype)base64StringWithCString:(const char *)cstring; + +/** + Base64 encoded copy of the string + + Encode the string as Base64 string and return the result or + nil on failure. + */ +- (NSString *)base64EncodedString; + +/** + Base64 decoded copy of the string + + Decode the string as Base64 string and return the result or + nil on failure. + */ +- (NSString *)base64DecodedString; + +@end + +/** + Base64 decode the given NSString + + Decodes the given Base64 encoded NSString or returns and empty + NSString in case of failure. + + \warning Compatibility function, do not use in new code! + */ +static inline NSString *B64DecNSStr(NSString *s) { + NSString *res = [s base64DecodedString]; + + return (res == nil) ? @"" : res; +} + +/** + Base64 encode the given C String and free it + + Base64 encodes the given C string and frees it, returns and empty + NSString in case of failure. + The given string is freed regardless if an error occured or not. + + \warning Compatibility function, do not use in new code! + */ +static inline NSString *B64EncAndFree(char *cs) { + NSString *res = [NSString base64StringWithCString:cs]; + free(cs); + + return (res == nil) ? @"" : res; +} diff --git a/modules/gui/macosx/NSString+Helpers.m b/modules/gui/macosx/NSString+Helpers.m new file mode 100644 index 0000000000..e8257d898a --- /dev/null +++ b/modules/gui/macosx/NSString+Helpers.m @@ -0,0 +1,74 @@ +/***************************************************************************** + * NSString+Helpers.m: Category with helper functions for NSStrings + ***************************************************************************** + * Copyright (C) 2002-2018 VLC authors and VideoLAN + * $Id$ + * + * Authors: Jon Lech Johansen <[email protected]> + * Christophe Massiot <[email protected]> + * Derk-Jan Hartman <hartman at videolan dot org> + * Felix Paul Kühne <fkuehne at videolan dot org> + * Marvin Scholz <[email protected]> + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA. + *****************************************************************************/ + +#import "NSString+Helpers.h" + +#import <vlc_common.h> +#import <vlc_strings.h> + +@implementation NSString (Helpers) + ++ (instancetype)base64StringWithCString:(const char *)cstring +{ + if (cstring == NULL) + return nil; + + char *encoded_cstring = vlc_b64_encode(cstring); + if (encoded_cstring == NULL) + return nil; + + return [[NSString alloc] initWithBytesNoCopy:encoded_cstring + length:strlen(encoded_cstring) + encoding:NSUTF8StringEncoding + freeWhenDone:YES]; +} + +- (NSString *)base64EncodedString +{ + char *encoded_cstring = vlc_b64_encode(self.UTF8String); + if (encoded_cstring == NULL) + return nil; + + return [[NSString alloc] initWithBytesNoCopy:encoded_cstring + length:strlen(encoded_cstring) + encoding:NSUTF8StringEncoding + freeWhenDone:YES]; +} + +- (NSString *)base64DecodedString +{ + char *decoded_cstring = vlc_b64_decode(self.UTF8String); + if (decoded_cstring == NULL) + return nil; + + return [[NSString alloc] initWithBytesNoCopy:decoded_cstring + length:strlen(decoded_cstring) + encoding:NSUTF8StringEncoding + freeWhenDone:YES]; +} + +@end diff --git a/modules/gui/macosx/VLCAudioEffectsWindowController.m b/modules/gui/macosx/VLCAudioEffectsWindowController.m index e0213f27c8..ed7e9c8639 100644 --- a/modules/gui/macosx/VLCAudioEffectsWindowController.m +++ b/modules/gui/macosx/VLCAudioEffectsWindowController.m @@ -32,6 +32,7 @@ #import "CompatibilityFixes.h" #import "VLCPopupPanelController.h" #import "VLCTextfieldPanelController.h" +#import "NSString+Helpers.h" #import <vlc_common.h> diff --git a/modules/gui/macosx/VLCStringUtility.h b/modules/gui/macosx/VLCStringUtility.h index 85f58c45ab..b7402fa6ca 100644 --- a/modules/gui/macosx/VLCStringUtility.h +++ b/modules/gui/macosx/VLCStringUtility.h @@ -37,9 +37,6 @@ * the translated string. the translation should be '1:translatedstring' though */ #define _ANS(s) [((s) ? toNSStr(vlc_gettext(s)) : @"") substringFromIndex:2] -#define B64DecNSStr(s) [[VLCStringUtility sharedInstance] b64Decode: s] -#define B64EncAndFree(s) [[VLCStringUtility sharedInstance] b64EncodeAndFree: s] - extern NSString *const kVLCMediaAudioCD; extern NSString *const kVLCMediaDVD; extern NSString *const kVLCMediaVCD; @@ -69,9 +66,6 @@ NSImage *imageFromRes(NSString *name); - (NSString *)VLCKeyToString:(NSString *)theString; - (unsigned int)VLCModifiersToCocoa:(NSString *)theString; -- (NSString *)b64Decode:(NSString *)string; -- (NSString *)b64EncodeAndFree:(char *)psz_string; - - (NSString *)getVolumeTypeFromMountPath:(NSString *)mountPath; - (NSString *)getBSDNodeFromMountPath:(NSString *)mountPath; diff --git a/modules/gui/macosx/VLCStringUtility.m b/modules/gui/macosx/VLCStringUtility.m index de5c84b0de..2176da9199 100644 --- a/modules/gui/macosx/VLCStringUtility.m +++ b/modules/gui/macosx/VLCStringUtility.m @@ -356,34 +356,6 @@ NSString *toNSStr(const char *str) { return theString; } -#pragma mark - -#pragma mark base64 helpers - -- (NSString *)b64Decode:(NSString *)string -{ - char *psz_decoded_string = vlc_b64_decode([string UTF8String]); - if(!psz_decoded_string) - return @""; - - NSString *returnStr = [NSString stringWithFormat:@"%s", psz_decoded_string]; - free(psz_decoded_string); - - return returnStr; -} - -- (NSString *)b64EncodeAndFree:(char *)psz_string -{ - char *psz_encoded_string = vlc_b64_encode(psz_string); - free(psz_string); - if(!psz_encoded_string) - return @""; - - NSString *returnStr = [NSString stringWithFormat:@"%s", psz_encoded_string]; - free(psz_encoded_string); - - return returnStr; -} - - (NSString *) getBSDNodeFromMountPath:(NSString *)mountPath { struct statfs stf; diff --git a/modules/gui/macosx/VLCVideoEffectsWindowController.m b/modules/gui/macosx/VLCVideoEffectsWindowController.m index 6e69986da4..2f6644255c 100644 --- a/modules/gui/macosx/VLCVideoEffectsWindowController.m +++ b/modules/gui/macosx/VLCVideoEffectsWindowController.m @@ -28,6 +28,7 @@ #import "VLCTextfieldPanelController.h" #import "VLCCoreInteraction.h" #import "VLCHexNumberFormatter.h" +#import "NSString+Helpers.h" #define getWidgetBoolValue(w) ((vlc_value_t){ .b_bool = [w state] }) #define getWidgetIntValue(w) ((vlc_value_t){ .i_int = [w intValue] }) _______________________________________________ vlc-commits mailing list [email protected] https://mailman.videolan.org/listinfo/vlc-commits
