Skip to content

Commit f91d617

Browse files
committed
Create NSString extensions
1 parent e4c313d commit f91d617

File tree

11 files changed

+59
-106
lines changed

11 files changed

+59
-106
lines changed

Kodi Remote.xcodeproj/project.pbxproj

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
/* Begin PBXBuildFile section */
1010
0F00207816EE247A003822B5 /* OBSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F00207616EE247A003822B5 /* OBSlider.m */; };
11-
0F05FB69170D79D400BBA833 /* NSString+MD5.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F05FB68170D79D400BBA833 /* NSString+MD5.m */; };
1211
0F089AA518EC4E3300F32430 /* SettingsValuesViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F089AA418EC4E3300F32430 /* SettingsValuesViewController.m */; };
1312
0F175F24154D5C3600C1C61F /* ViewControllerIPad.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F175F22154D5C3600C1C61F /* ViewControllerIPad.m */; };
1413
0F175F28154D696B00C1C61F /* StackScrollViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 0F175F27154D696B00C1C61F /* StackScrollViewController.m */; };
@@ -110,8 +109,6 @@
110109
0F00207616EE247A003822B5 /* OBSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = OBSlider.m; sourceTree = "<group>"; };
111110
0F0320841C59531700C7E25D /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/InfoPlist.strings; sourceTree = "<group>"; };
112111
0F0320851C59531700C7E25D /* es */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = es; path = es.lproj/Localizable.strings; sourceTree = "<group>"; };
113-
0F05FB67170D79D400BBA833 /* NSString+MD5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSString+MD5.h"; sourceTree = "<group>"; };
114-
0F05FB68170D79D400BBA833 /* NSString+MD5.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSString+MD5.m"; sourceTree = "<group>"; };
115112
0F089AA318EC4E3300F32430 /* SettingsValuesViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SettingsValuesViewController.h; sourceTree = "<group>"; };
116113
0F089AA418EC4E3300F32430 /* SettingsValuesViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SettingsValuesViewController.m; sourceTree = "<group>"; };
117114
0F175F21154D5C3600C1C61F /* ViewControllerIPad.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ViewControllerIPad.h; sourceTree = "<group>"; };
@@ -365,15 +362,6 @@
365362
path = OBSlider;
366363
sourceTree = "<group>";
367364
};
368-
0F05FB66170D79B000BBA833 /* NSString+MD5 */ = {
369-
isa = PBXGroup;
370-
children = (
371-
0F05FB67170D79D400BBA833 /* NSString+MD5.h */,
372-
0F05FB68170D79D400BBA833 /* NSString+MD5.m */,
373-
);
374-
path = "NSString+MD5";
375-
sourceTree = "<group>";
376-
};
377365
0F175F13154D45B300C1C61F /* iPhone */ = {
378366
isa = PBXGroup;
379367
children = (
@@ -615,7 +603,6 @@
615603
0F4156421646D810009E6DD4 /* KenBurns */,
616604
0F7F3DA0164A6D730080A14A /* ECSlidingViewController */,
617605
0F7F0DC71703490A0098FF75 /* BDKCollectionIndexView */,
618-
0F05FB66170D79B000BBA833 /* NSString+MD5 */,
619606
0FDC8917170DCAEA00419F58 /* SVPullToRefresh */,
620607
C78C30F728F899DF0055CD95 /* SharingActivityItemSource */,
621608
C72CDAF52DD27ACC00AFB2FA /* LocalNetwork */,
@@ -914,7 +901,6 @@
914901
0F7F0DCC1703490A0098FF75 /* BDKCollectionIndexView.m in Sources */,
915902
0FEE08161704819A00EC9BC7 /* FloatingHeaderFlowLayout.m in Sources */,
916903
0F4205D217099AE500EA533C /* RecentlyAddedCell.m in Sources */,
917-
0F05FB69170D79D400BBA833 /* NSString+MD5.m in Sources */,
918904
0F4019B018F3ECEB0064E4DC /* customButton.m in Sources */,
919905
0FDC891A170DCAEA00419F58 /* UIScrollView+SVPullToRefresh.m in Sources */,
920906
C76451DA29C51221000AE949 /* SDWebImageDownloaderOperation.m in Sources */,

XBMC Remote/DetailViewController.m

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
#import "PosterLabel.h"
2222
#import "PosterHeaderView.h"
2323
#import "RecentlyAddedCell.h"
24-
#import "NSString+MD5.h"
2524
#import "UIScrollView+SVPullToRefresh.h"
2625
#import "BroadcastProgressView.h"
2726
#import "SettingsValuesViewController.h"
@@ -493,7 +492,7 @@ - (void)addExtraProperties:(NSMutableArray*)mutableProperties newParams:(NSMutab
493492
}
494493

495494
- (void)setFilternameLabel:(NSString*)labelText {
496-
labelText = [Utilities stripBBandHTML:labelText];
495+
labelText = [labelText stripBBandHTML];
497496
self.navigationItem.title = labelText;
498497
if (IS_IPHONE || stackscrollFullscreen) {
499498
return;
@@ -1726,12 +1725,12 @@ - (UICollectionViewCell*)collectionView:(UICollectionView*)cView cellForItemAtIn
17261725
cell.posterLabelFullscreen.font = [UIFont boldSystemFontOfSize:posterFontSize];
17271726
cell.posterThumbnail.contentMode = UIViewContentModeScaleAspectFill;
17281727
if (stackscrollFullscreen) {
1729-
cell.posterLabelFullscreen.text = [Utilities stripBBandHTML:item[@"label"]];
1728+
cell.posterLabelFullscreen.text = [item[@"label"] stripBBandHTML];
17301729
cell.labelImageView.hidden = YES;
17311730
cell.posterLabelFullscreen.hidden = NO;
17321731
}
17331732
else {
1734-
cell.posterLabel.text = [Utilities stripBBandHTML:item[@"label"]];
1733+
cell.posterLabel.text = [item[@"label"] stripBBandHTML];
17351734
cell.posterLabelFullscreen.hidden = YES;
17361735
}
17371736

@@ -2451,7 +2450,7 @@ - (UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSI
24512450
title.text = [Utilities formatTVShowStringForSeasonLeading:item[@"season"] episode:item[@"episode"] title:item[@"label"]];
24522451
}
24532452
else {
2454-
title.text = [Utilities stripBBandHTML:item[@"label"]];
2453+
title.text = [item[@"label"] stripBBandHTML];
24552454
}
24562455

24572456
// In case no thumbs are shown and there is a child view or we are showing a setting, display disclosure indicator and adapt width.

XBMC Remote/NSString+MD5/NSString+MD5.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

XBMC Remote/NSString+MD5/NSString+MD5.m

Lines changed: 0 additions & 39 deletions
This file was deleted.

XBMC Remote/NowPlaying.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ - (void)updateNowPlayingLabels:(NSDictionary*)item {
451451
NSString *description = [Utilities getStringFromItem:item[@"description"]];
452452
NSString *plot = [Utilities getStringFromItem:item[@"plot"]];
453453
itemDescription.text = description.length ? description : (plot.length ? plot : @"");
454-
itemDescription.text = [Utilities stripBBandHTML:itemDescription.text];
454+
itemDescription.text = [itemDescription.text stripBBandHTML];
455455
[itemDescription scrollRangeToVisible:NSMakeRange(0, 0)];
456456
}
457457

XBMC Remote/SDWebImage/SDImageCache.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#import "SDImageCache.h"
1010
#import "SDWebImageDecoder.h"
1111
#import "UIImage+MultiFormat.h"
12-
#import "NSString+MD5.h"
12+
#import "Utilities.h"
1313
#import <CommonCrypto/CommonDigest.h>
1414

1515
// See https://github.com/rs/SDWebImage/pull/1141 for discussion

XBMC Remote/SettingsValuesViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ - (void)configureCell:(UITableViewCell*)cell forRowAtIndexPath:(NSIndexPath*)ind
467467

468468
NSString *descriptionString = [NSString stringWithFormat:@"%@", self.detailItem[@"genre"]];
469469
descriptionString = [descriptionString stringByReplacingOccurrencesOfString:@"[CR]" withString:@"\n"];
470-
descriptionString = [Utilities stripBBandHTML:descriptionString];
470+
descriptionString = [descriptionString stripBBandHTML];
471471
switch (xbmcSetting) {
472472
case SettingTypeSwitch:
473473
cell.selectionStyle = UITableViewCellSelectionStyleNone;

XBMC Remote/ShowInfoViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -873,7 +873,7 @@ - (void)createInfo {
873873

874874
parentalRatingSubLabel.text = [Utilities getStringFromItem:item[@"mpaa"]];
875875

876-
subLabel5.text = [Utilities stripBBandHTML:subLabel5.text];
876+
subLabel5.text = [subLabel5.text stripBBandHTML];
877877

878878
if ([item[@"trailer"] isKindOfClass:[NSString class]]) {
879879
[self processTrailerFromString:item[@"trailer"]];

XBMC Remote/Utilities.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,6 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
8989
+ (NSString*)formatTVShowStringForSeasonLeading:(id)season episode:(id)episode title:(NSString*)title;
9090
+ (NSString*)formatTVShowStringForSeason:(id)season episode:(id)episode;
9191
+ (NSString*)formatClipboardMessage:(NSString*)method parameters:(NSDictionary*)parameters error:(NSError*)error methodError:(DSJSONRPCError*)methodError;
92-
+ (NSString*)stripBBandHTML:(NSString*)text;
9392
+ (BOOL)isValidMacAddress:(NSString*)macAddress;
9493
+ (void)wakeUp:(NSString*)macAddress;
9594
+ (NSString*)getUrlStyleAddress:(NSString*)address;
@@ -162,3 +161,10 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
162161
- (UIImage*)resizedImageSize:(CGSize)newSize aspectMode:(UIViewContentMode)contentMode;
163162

164163
@end
164+
165+
@interface NSString (Extensions)
166+
167+
- (NSString*)SHA256String;
168+
- (NSString*)stripBBandHTML;
169+
170+
@end

XBMC Remote/Utilities.m

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010
#import <mach/mach.h>
1111
#import "Utilities.h"
1212
#import "AppDelegate.h"
13-
#import "NSString+MD5.h"
1413
#import "SDWebImageManager.h"
1514
#import "LocalNetworkAccess.h"
1615

1716
@import StoreKit;
17+
@import CommonCrypto;
1818

1919
#define GET_ROUNDED_EDGES_RADIUS(size) MAX(MIN(size.width, size.height) * 0.03, 6.0)
2020
#define RGBA(r, g, b, a) [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:(a)]
@@ -1046,31 +1046,6 @@ + (NSString*)formatClipboardMessage:(NSString*)method parameters:(NSDictionary*)
10461046
return message;
10471047
}
10481048

1049-
+ (NSString*)stripRegEx:(NSString*)regExp text:(NSString*)textIn {
1050-
// Returns unchanged string, if regExp is nil. Returns nil, if string is nil.
1051-
if (!textIn || !regExp) {
1052-
return textIn;
1053-
}
1054-
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regExp options:NSRegularExpressionCaseInsensitive error:NULL];
1055-
NSString *textOut = [regex stringByReplacingMatchesInString:textIn options:0 range:NSMakeRange(0, [textIn length]) withTemplate:@""];
1056-
return textOut;
1057-
}
1058-
1059-
+ (NSString*)stripBBandHTML:(NSString*)text {
1060-
NSString *textOut = text;
1061-
1062-
// Strip html, <x>, whereas x is not ""
1063-
textOut = [Utilities stripRegEx:@"<[^>]+>" text:textOut];
1064-
1065-
// Strip BB code, [x] [/x], whereas x = b,u,i,s,center,left,right,url,img and spaces
1066-
textOut = [Utilities stripRegEx:@"\\[/?(b|u|i|s|center|left|right|url|img)\\]" text:textOut];
1067-
1068-
// Strip BB code, [x=anything] [/x], whereas x = font,size,color,url and spaces
1069-
textOut = [Utilities stripRegEx:@"\\[/?(font|size|color|url)(=[^]]+)?\\]" text:textOut];
1070-
1071-
return textOut;
1072-
}
1073-
10741049
+ (BOOL)isValidMacAddress:(NSString*)macAddress {
10751050
return macAddress && macAddress.length && ![macAddress isEqualToString:@":::::"];
10761051
}
@@ -1591,3 +1566,46 @@ - (UIImage*)resizedImageSize:(CGSize)newSize aspectMode:(UIViewContentMode)conte
15911566
}
15921567

15931568
@end
1569+
1570+
#pragma mark - NSString extensions
1571+
1572+
@implementation NSString (Extensions)
1573+
1574+
- (NSString*)SHA256String {
1575+
const char *utf8chars = [self UTF8String];
1576+
unsigned char result[CC_SHA256_DIGEST_LENGTH];
1577+
CC_SHA256(utf8chars, (CC_LONG)strlen(utf8chars), result);
1578+
1579+
NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2];
1580+
for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) {
1581+
[ret appendFormat:@"%02x", result[i]];
1582+
}
1583+
return ret;
1584+
}
1585+
1586+
- (NSString*)stripRegEx:(NSString*)regExp {
1587+
// Returns unchanged string, if regExp is nil.
1588+
if (!regExp) {
1589+
return self;
1590+
}
1591+
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regExp options:NSRegularExpressionCaseInsensitive error:NULL];
1592+
NSString *textOut = [regex stringByReplacingMatchesInString:self options:0 range:NSMakeRange(0, self.length) withTemplate:@""];
1593+
return textOut;
1594+
}
1595+
1596+
- (NSString*)stripBBandHTML {
1597+
NSString *textOut = self;
1598+
1599+
// Strip html, <x>, whereas x is not ""
1600+
textOut = [textOut stripRegEx:@"<[^>]+>"];
1601+
1602+
// Strip BB code, [x] [/x], whereas x = b,u,i,s,center,left,right,url,img and spaces
1603+
textOut = [textOut stripRegEx:@"\\[/?(b|u|i|s|center|left|right|url|img)\\]"];
1604+
1605+
// Strip BB code, [x=anything] [/x], whereas x = font,size,color,url and spaces
1606+
textOut = [textOut stripRegEx:@"\\[/?(font|size|color|url)(=[^]]+)?\\]"];
1607+
1608+
return textOut;
1609+
}
1610+
1611+
@end

0 commit comments

Comments
 (0)