찾다

 >  Q&A  >  본문

ios - 关于afnetworking源码中AFPercentEscapedStringFromString方法的疑问

这两天在看afnetworking的源码,发现AFURLRequestSerialization.m文件里有这么一个方法,
用来把url查询字符串中的一些特殊字符转换的。
不理解的是batchSize = 50 的作用是什么,为什么是50而不是其他的值?
而且,要实现相同的功能还有其他方法吗?

static 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];

    static NSUInteger const batchSize = 50;

    NSInteger index = 0;
    NSMutableString *escaped = @"".mutableCopy;

    while (index < string.length) {
        NSUInteger length = MIN(string.length - index, batchSize);
        NSRange range = NSMakeRange(index, length);

        // To avoid breaking up character sequences such as 
ringa_leeringa_lee2772일 전914

모든 응답(0)나는 대답할 것이다

답장 없음
  • 취소회신하다