This repository has been archived by the owner on Jan 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
NSStringAdditions.h
140 lines (125 loc) · 4.45 KB
/
NSStringAdditions.h
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
//
// Copyright 2009-2011 Facebook
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#import <Foundation/Foundation.h>
#import "Three20Core/TTCorePreprocessorMacros.h" // For __TTDEPRECATED_METHOD
/**
* Doxygen does not handle categories very well, so please refer to the .m file in general
* for the documentation that is reflected on api.three20.info.
*/
@interface NSString (TTAdditions)
/**
* Determines if the string contains only whitespace and newlines.
*/
- (BOOL)isWhitespaceAndNewlines;
/**
* Determines if the string is empty or contains only whitespace.
* @deprecated Use TTIsStringWithAnyText() instead. Updating your use of
* this method is non-trivial. See the note below.
*
* Notes for updating your use of isEmptyOrWhitespace:
*
* if (!textField.text.isEmptyOrWhitespace) {
*
* becomes
*
* if (TTIsStringWithAnyText(textField.text) && !textField.text.isWhitespaceAndNewlines) {
*
* and
*
* if (textField.text.isEmptyOrWhitespace) {
*
* becomes
*
* if (0 == textField.text.length || textField.text.isWhitespaceAndNewlines) {
*/
- (BOOL)isEmptyOrWhitespace __TTDEPRECATED_METHOD;
/**
* Parses a URL query string into a dictionary.
*
* @deprecated Use queryContentsUsingEncoding: instead.
*/
- (NSDictionary*)queryDictionaryUsingEncoding:(NSStringEncoding)encoding __TTDEPRECATED_METHOD;
/**
* Parses a URL query string into a dictionary where the values are arrays.
*/
- (NSDictionary*)queryContentsUsingEncoding:(NSStringEncoding)encoding;
/**
* Parses a URL, adds query parameters to its query, and re-encodes it as a new URL.
*/
- (NSString*)stringByAddingQueryDictionary:(NSDictionary*)query;
/**
* Parses a URL, adds urlEncoded query parameters to its query, and re-encodes it as a new URL.
*
* This method encodes keys and values of query using [NSString urlEncoded] and calls
* stringByAddingQueryDictionary with the resulting dictionary.
*
* @throw NSInvalidArgumentException If any value or key does not respond to urlEncoded.
*/
- (NSString*)stringByAddingURLEncodedQueryDictionary:(NSDictionary*)query;
/**
* Returns a URL Encoded String
*/
- (NSString*)urlEncoded;
/**
* Returns a string with all HTML tags removed.
*/
- (NSString*)stringByRemovingHTMLTags;
/**
* Compares two strings expressing software versions.
*
* The comparison is (except for the development version provisions noted below) lexicographic
* string comparison. So as long as the strings being compared use consistent version formats,
* a variety of schemes are supported. For example "3.02" < "3.03" and "3.0.2" < "3.0.3". If you
* mix such schemes, like trying to compare "3.02" and "3.0.3", the result may not be what you
* expect.
*
* Development versions are also supported by adding an "a" character and more version info after
* it. For example "3.0a1" or "3.01a4". The way these are handled is as follows: if the parts
* before the "a" are different, the parts after the "a" are ignored. If the parts before the "a"
* are identical, the result of the comparison is the result of NUMERICALLY comparing the parts
* after the "a". If the part after the "a" is empty, it is treated as if it were "0". If one
* string has an "a" and the other does not (e.g. "3.0" and "3.0a1") the one without the "a"
* is newer.
*
* Examples (?? means undefined):
* "3.0" = "3.0"
* "3.0a2" = "3.0a2"
* "3.0" > "2.5"
* "3.1" > "3.0"
* "3.0a1" < "3.0"
* "3.0a1" < "3.0a4"
* "3.0a2" < "3.0a19" <-- numeric, not lexicographic
* "3.0a" < "3.0a1"
* "3.02" < "3.03"
* "3.0.2" < "3.0.3"
* "3.00" ?? "3.0"
* "3.02" ?? "3.0.3"
* "3.02" ?? "3.0.2"
*/
- (NSComparisonResult)versionStringCompare:(NSString *)other;
/**
* Calculate the md5 hash of this string using CC_MD5.
*
* @return md5 hash of this string
*/
@property (nonatomic, readonly) NSString* md5Hash;
/**
* Calculate the SHA1 hash of this string using CommonCrypto CC_SHA1.
*
* @return NSString with SHA1 hash of this string
*/
@property (nonatomic, readonly) NSString* sha1Hash;
@end