forked from wuyuedefeng/NSDictionary-Model-Interconversion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NSString+WSCategory.m
82 lines (76 loc) · 2.3 KB
/
NSString+WSCategory.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// NSString+WSCategory.m
// Category_Nsobject
//
// Created by wangsen on 13-12-31.
// Copyright (c) 2013年 ws. All rights reserved.
//
#import <CommonCrypto/CommonDigest.h>
#import "NSString+WSCategory.h"
#import <objc/runtime.h>
@implementation NSNull (Category)
-(BOOL) ws_isNotNilString
{
return NO;
}
@end
/***
* ///////////////添加ContainsString分类 该方法在ios8才被系统提供 该方法为了向下兼容
*/
#if __IPHONE_OS_VERSION_MIN_REQUIRED < 80000
@implementation NSString (ContainsString)
+ (void)load {
@autoreleasepool {
[self pspdf_modernizeSelector:NSSelectorFromString(@"containsString:") withSelector:@selector(containsString:)];
}
}
+ (void)pspdf_modernizeSelector:(SEL)originalSelector withSelector:(SEL)newSelector {
if (![NSString instancesRespondToSelector:originalSelector]) {
Method newMethod = class_getInstanceMethod(self, newSelector);
class_addMethod(self, originalSelector, method_getImplementation(newMethod), method_getTypeEncoding(newMethod));
}
}
// containsString: has been added in iOS 8. We dynamically add this if we run on iOS 7.
- (BOOL)containsString:(NSString *)aString {
return [self rangeOfString:aString].location != NSNotFound;
}
@end
#endif
/**
* /////////////////////
*/
@implementation NSString (Category)
#pragma mark - MD5加密
/**
* MD5加密
*
* @return 加密后的字符串
*/
- (NSString *) ws_md5_encrypt
{
if(self == nil || [self length] == 0)
return nil;
const char *value = [self UTF8String];
unsigned char outputBuffer[CC_MD5_DIGEST_LENGTH];
CC_MD5(value, (unsigned int)strlen(value), outputBuffer);
NSMutableString *outputString = [[NSMutableString alloc] initWithCapacity:CC_MD5_DIGEST_LENGTH * 2];
for(NSInteger count = 0; count < CC_MD5_DIGEST_LENGTH; count++){
[outputString appendFormat:@"%02x",outputBuffer[count]];
}
return [outputString copy];
}
#pragma mark - 判断字符串是否不为空(' ',nil,null)
/**
* 判断字符串是否不为空 包括(' ',nil,null)
*
* @return 如果不是(' ',nil,null)返回YES
*/
-(BOOL) ws_isNotNilString
{
if(self != nil && ![self isEqual:[NSNull null]] && self.length != 0 && ![[self lowercaseString] isEqualToString:@"(null)"])
{
return YES;
}
return NO;
}
@end