iOS-AFNetworking源码解析(五)
程序员文章站
2022-06-15 23:30:17
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
下一篇: 总结几种MySQL中常见的排名问题
推荐阅读
-
Vue源码解析之Template转化为AST的实现方法
-
jQuery 源码解析(二十二) DOM操作模块 复制元素 详解
-
解析xHTML源码的DLL组件AngleSharp介绍
-
Mybaits 源码解析 (十一)----- 设计模式精妙使用:静态代理和动态代理结合使用:@MapperScan将Mapper接口生成代理注入到Spring
-
Mybaits 源码解析 (十二)----- Mybatis的事务如何被Spring管理?Mybatis和Spring事务中用的Connection是同一个吗?
-
Ribbon源码解析
-
Mybaits 源码解析 (五)----- 面试源码系列:Mapper接口底层原理(为什么Mapper不用写实现类就能访问到数据库?)
-
Eureka获取服务列表源码解析
-
Tomcat源码分析三:Tomcat启动加载过程(一)的源码解析
-
spring5 源码深度解析-----ApplicationContext容器refresh过程