|
10 | 10 | #import <mach/mach.h> |
11 | 11 | #import "Utilities.h" |
12 | 12 | #import "AppDelegate.h" |
13 | | -#import "NSString+MD5.h" |
14 | 13 | #import "SDWebImageManager.h" |
15 | 14 | #import "LocalNetworkAccess.h" |
16 | 15 |
|
17 | 16 | @import StoreKit; |
| 17 | +@import CommonCrypto; |
18 | 18 |
|
19 | 19 | #define GET_ROUNDED_EDGES_RADIUS(size) MAX(MIN(size.width, size.height) * 0.03, 6.0) |
20 | 20 | #define RGBA(r, g, b, a) [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:(a)] |
@@ -1059,31 +1059,6 @@ + (NSString*)formatClipboardMessage:(NSString*)method parameters:(NSDictionary*) |
1059 | 1059 | return message; |
1060 | 1060 | } |
1061 | 1061 |
|
1062 | | -+ (NSString*)stripRegEx:(NSString*)regExp text:(NSString*)textIn { |
1063 | | - // Returns unchanged string, if regExp is nil. Returns nil, if string is nil. |
1064 | | - if (!textIn || !regExp) { |
1065 | | - return textIn; |
1066 | | - } |
1067 | | - NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regExp options:NSRegularExpressionCaseInsensitive error:NULL]; |
1068 | | - NSString *textOut = [regex stringByReplacingMatchesInString:textIn options:0 range:NSMakeRange(0, [textIn length]) withTemplate:@""]; |
1069 | | - return textOut; |
1070 | | -} |
1071 | | - |
1072 | | -+ (NSString*)stripBBandHTML:(NSString*)text { |
1073 | | - NSString *textOut = text; |
1074 | | - |
1075 | | - // Strip html, <x>, whereas x is not "" |
1076 | | - textOut = [Utilities stripRegEx:@"<[^>]+>" text:textOut]; |
1077 | | - |
1078 | | - // Strip BB code, [x] [/x], whereas x = b,u,i,s,center,left,right,url,img and spaces |
1079 | | - textOut = [Utilities stripRegEx:@"\\[/?(b|u|i|s|center|left|right|url|img)\\]" text:textOut]; |
1080 | | - |
1081 | | - // Strip BB code, [x=anything] [/x], whereas x = font,size,color,url and spaces |
1082 | | - textOut = [Utilities stripRegEx:@"\\[/?(font|size|color|url)(=[^]]+)?\\]" text:textOut]; |
1083 | | - |
1084 | | - return textOut; |
1085 | | -} |
1086 | | - |
1087 | 1062 | + (BOOL)isValidMacAddress:(NSString*)macAddress { |
1088 | 1063 | return macAddress && macAddress.length && ![macAddress isEqualToString:@":::::"]; |
1089 | 1064 | } |
@@ -1604,3 +1579,46 @@ - (UIImage*)resizedImageSize:(CGSize)newSize aspectMode:(UIViewContentMode)conte |
1604 | 1579 | } |
1605 | 1580 |
|
1606 | 1581 | @end |
| 1582 | + |
| 1583 | +#pragma mark - NSString extensions |
| 1584 | + |
| 1585 | +@implementation NSString (Extensions) |
| 1586 | + |
| 1587 | +- (NSString*)SHA256String { |
| 1588 | + const char *utf8chars = [self UTF8String]; |
| 1589 | + unsigned char result[CC_SHA256_DIGEST_LENGTH]; |
| 1590 | + CC_SHA256(utf8chars, (CC_LONG)strlen(utf8chars), result); |
| 1591 | + |
| 1592 | + NSMutableString *ret = [NSMutableString stringWithCapacity:CC_SHA256_DIGEST_LENGTH * 2]; |
| 1593 | + for (int i = 0; i < CC_SHA256_DIGEST_LENGTH; i++) { |
| 1594 | + [ret appendFormat:@"%02x", result[i]]; |
| 1595 | + } |
| 1596 | + return ret; |
| 1597 | +} |
| 1598 | + |
| 1599 | +- (NSString*)stripRegEx:(NSString*)regExp { |
| 1600 | + // Returns unchanged string, if regExp is nil. |
| 1601 | + if (!regExp) { |
| 1602 | + return self; |
| 1603 | + } |
| 1604 | + NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regExp options:NSRegularExpressionCaseInsensitive error:NULL]; |
| 1605 | + NSString *textOut = [regex stringByReplacingMatchesInString:self options:0 range:NSMakeRange(0, self.length) withTemplate:@""]; |
| 1606 | + return textOut; |
| 1607 | +} |
| 1608 | + |
| 1609 | +- (NSString*)stripBBandHTML { |
| 1610 | + NSString *textOut = self; |
| 1611 | + |
| 1612 | + // Strip html, <x>, whereas x is not "" |
| 1613 | + textOut = [textOut stripRegEx:@"<[^>]+>"]; |
| 1614 | + |
| 1615 | + // Strip BB code, [x] [/x], whereas x = b,u,i,s,center,left,right,url,img and spaces |
| 1616 | + textOut = [textOut stripRegEx:@"\\[/?(b|u|i|s|center|left|right|url|img)\\]"]; |
| 1617 | + |
| 1618 | + // Strip BB code, [x=anything] [/x], whereas x = font,size,color,url and spaces |
| 1619 | + textOut = [textOut stripRegEx:@"\\[/?(font|size|color|url)(=[^]]+)?\\]"]; |
| 1620 | + |
| 1621 | + return textOut; |
| 1622 | +} |
| 1623 | + |
| 1624 | +@end |
0 commit comments