iOS-AFNetworking源码解析(五)
程序员文章站
2022-03-12 19:28:47
AFURLRequestSerializationAFURLRequestSerialization是用来对发出的请求进行一些处理AFPercentEscapedStringFromString方法将string里面的:#[]@!$&’()*+,;=字符替换成%NSString * AFPercentEscapedStringFromString(NSString *string) { static NSString * const kAFCharactersGeneralDel...
AFURLRequestSerialization
AFURLRequestSerialization是用来对发出的请求进行一些处理
AFPercentEscapedStringFromString方法将string里面的:#[]@!$&’()*+,;=字符替换成%
NSString * AFPercentEscapedStringFromString(NSString *string) {
static NSString * const kAFCharactersGeneralDelimitersToEncode = @":#[]@"; // does not include "?" or "/" due to RFC 3986 - Section 3.4
static NSString * const kAFCharactersSubDelimitersToEncode = @"!$&'()*+,;=";
// 从可用字符替换删除掉:#[]@!$&'()*+,;=这些字符
NSMutableCharacterSet * allowedCharacterSet = [[NSCharacterSet URLQueryAllowedCharacterSet] mutableCopy];
[allowedCharacterSet removeCharactersInString:[kAFCharactersGeneralDelimitersToEncode stringByAppendingString:kAFCharactersSubDelimitersToEncode]];
// FIXME: https://github.com/AFNetworking/AFNetworking/pull/3028
// return [string stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];
// 声明批量处理的大小为50
static NSUInteger const batchSize = 50;
NSUInteger index = 0;
NSMutableString *escaped = @"".mutableCopy;
// 循环将string里面:#[]@!$&'()*+,;=的字符替换成%
while (index < string.length) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu"
NSUInteger length = MIN(string.length - index, batchSize);
#pragma GCC diagnostic pop
NSRange range = NSMakeRange(index, length);
// To avoid breaking up character sequences such as
推荐阅读
-
java源码解析(java新手代码大全)
-
ArrayList构造方法的源码解析
-
Spring MVC源码(三) ----- @RequestBody和@ResponseBody原理解析
-
基于Spring注解的上下文初始化过程源码解析(一)
-
axios 源码解析(下) 拦截器的详解
-
Unity3D实现简易五子棋源码
-
Spring源码解析之ConfigurableApplicationContext
-
angularjs 源码解析之injector
-
angularjs 源码解析之scope
-
netty源码解析(4.0)-28 ByteBuf内存池:PooledByteBufAllocator-把一切组装起来