Skip to content

Commit ceb8bd8

Browse files
committed
Create NSString extensions
1 parent a5cb344 commit ceb8bd8

File tree

11 files changed

+60
-105
lines changed

11 files changed

+60
-105
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
@@ -23,7 +23,6 @@
2323
#import "PosterLabel.h"
2424
#import "PosterHeaderView.h"
2525
#import "RecentlyAddedCell.h"
26-
#import "NSString+MD5.h"
2726
#import "UIScrollView+SVPullToRefresh.h"
2827
#import "BroadcastProgressView.h"
2928
#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 & 38 deletions
This file was deleted.

XBMC Remote/NowPlaying.m

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

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
@@ -872,7 +872,7 @@ - (void)createInfo {
872872

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

875-
subLabel5.text = [Utilities stripBBandHTML:subLabel5.text];
875+
subLabel5.text = [subLabel5.text stripBBandHTML];
876876

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

XBMC Remote/Utilities.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
8787
+ (NSString*)formatTVShowStringForSeasonLeading:(id)season episode:(id)episode title:(NSString*)title;
8888
+ (NSString*)formatTVShowStringForSeason:(id)season episode:(id)episode;
8989
+ (NSString*)formatClipboardMessage:(NSString*)method parameters:(NSDictionary*)parameters error:(NSError*)error methodError:(DSJSONRPCError*)methodError;
90-
+ (NSString*)stripBBandHTML:(NSString*)text;
9190
+ (BOOL)isValidMacAddress:(NSString*)macAddress;
9291
+ (void)wakeUp:(NSString*)macAddress;
9392
+ (NSString*)getUrlStyleAddress:(NSString*)address;
@@ -160,3 +159,10 @@ typedef NS_ENUM(NSInteger, LogoBackgroundType) {
160159
- (UIImage*)resizedImageSize:(CGSize)newSize aspectMode:(UIViewContentMode)contentMode;
161160

162161
@end
162+
163+
@interface NSString (Extensions)
164+
165+
- (NSString*)SHA256String;
166+
- (NSString*)stripBBandHTML;
167+
168+
@end

XBMC Remote/Utilities.m

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

17+
@import CommonCrypto;
18+
1819
#define GET_ROUNDED_EDGES_RADIUS(size) MAX(MIN(size.width, size.height) * 0.03, 6.0)
1920
#define RGBA(r, g, b, a) [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:(a)]
2021
#define GAMMA_DEC(x) pow(x, 2.2)
@@ -1043,31 +1044,6 @@ + (NSString*)formatClipboardMessage:(NSString*)method parameters:(NSDictionary*)
10431044
return message;
10441045
}
10451046

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

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

0 commit comments

Comments
 (0)