@@ -116,12 +116,12 @@ + (NSString *)queryStringWithParams:(NSDictionary *)params URLEscapeValues:(BOOL
116
116
if (params.allKeys .count == 0 ) return @" " ;
117
117
118
118
NSMutableString *q = [NSMutableString string ];
119
- [params enumerateKeysAndObjectsUsingBlock: ^(NSString *key, id value, BOOL *stop) {
119
+ [params enumerateKeysAndObjectsUsingBlock: ^(NSString *key, NSString * value, BOOL *stop) {
120
120
if ([value isKindOfClass: [NSString class ]]) {
121
121
if (escapeValues) {
122
- value = [( NSString *) value urlencode ];
122
+ value = [value URLEncodedString ];
123
123
} else {
124
- value = [( NSString *) value stringByReplacingOccurrencesOfString: @" " withString: @" +" ];
124
+ value = [value stringByReplacingOccurrencesOfString: @" " withString: @" +" ];
125
125
}
126
126
}
127
127
[q appendFormat: @" %@ =%@ &" , key, value];
@@ -132,24 +132,26 @@ + (NSString *)queryStringWithParams:(NSDictionary *)params URLEscapeValues:(BOOL
132
132
return q;
133
133
}
134
134
135
- - (NSString *)urlencode {
136
- NSMutableString *output = [NSMutableString string ];
137
- const unsigned char *source = (const unsigned char *)[self UTF8String ];
138
- int sourceLen = (int )strlen ((const char *)source);
139
- for (int i = 0 ; i < sourceLen; ++i) {
140
- const unsigned char thisChar = source[i];
141
- if (thisChar == ' ' ){
142
- [output appendString: @" +" ];
143
- } else if (thisChar == ' .' || thisChar == ' -' || thisChar == ' _' || thisChar == ' ~' ||
144
- (thisChar >= ' a' && thisChar <= ' z' ) ||
145
- (thisChar >= ' A' && thisChar <= ' Z' ) ||
146
- (thisChar >= ' 0' && thisChar <= ' 9' )) {
147
- [output appendFormat: @" %c " , thisChar];
135
+ - (NSString *)URLEncodedString {
136
+ NSMutableString *encoded = [NSMutableString string ];
137
+ const unsigned char *source = (const unsigned char *)self.UTF8String ;
138
+ NSInteger sourceLen = (NSInteger )strlen ((const char *)source);
139
+
140
+ for (NSInteger i = 0 ; i < sourceLen; i++) {
141
+ const unsigned char c = source[i];
142
+ if (c == ' ' ){
143
+ [encoded appendString: @" +" ];
144
+ } else if (c == ' .' || c == ' -' || c == ' _' || c == ' ~' ||
145
+ (c >= ' a' && c <= ' z' ) ||
146
+ (c >= ' A' && c <= ' Z' ) ||
147
+ (c >= ' 0' && c <= ' 9' )) {
148
+ [encoded appendFormat: @" %c " , c];
148
149
} else {
149
- [output appendFormat: @" %%%02X " , thisChar ];
150
+ [encoded appendFormat: @" %%%02X " , c ];
150
151
}
151
152
}
152
- return output;
153
+
154
+ return encoded;
153
155
}
154
156
155
157
@end
0 commit comments