|
11 | 11 | #import <mach/mach.h> |
12 | 12 | #import "Utilities.h" |
13 | 13 | #import "AppDelegate.h" |
14 | | -#import "NSString+MD5.h" |
15 | 14 | #import "SDWebImageManager.h" |
16 | 15 | #import "LocalNetworkAccess.h" |
17 | 16 |
|
| 17 | +@import CommonCrypto; |
| 18 | + |
18 | 19 | #define GET_ROUNDED_EDGES_RADIUS(size) MAX(MIN(size.width, size.height) * 0.03, 6.0) |
19 | 20 | #define RGBA(r, g, b, a) [UIColor colorWithRed:(r) / 255.0 green:(g) / 255.0 blue:(b) / 255.0 alpha:(a)] |
20 | 21 | #define GAMMA_DEC(x) pow(x, 2.2) |
@@ -1043,31 +1044,6 @@ + (NSString*)formatClipboardMessage:(NSString*)method parameters:(NSDictionary*) |
1043 | 1044 | return message; |
1044 | 1045 | } |
1045 | 1046 |
|
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 | | - |
1071 | 1047 | + (BOOL)isValidMacAddress:(NSString*)macAddress { |
1072 | 1048 | return macAddress && macAddress.length && ![macAddress isEqualToString:@":::::"]; |
1073 | 1049 | } |
@@ -1588,3 +1564,46 @@ - (UIImage*)resizedImageSize:(CGSize)newSize aspectMode:(UIViewContentMode)conte |
1588 | 1564 | } |
1589 | 1565 |
|
1590 | 1566 | @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