午夜视频在线网站,日韩视频精品在线,中文字幕精品一区二区三区在线,在线播放精品,1024你懂我懂的旧版人,欧美日韩一级黄色片,一区二区三区在线观看视频

分享

iOS字符串處理筆記(正則表達(dá)式、NSScanner掃描、CoreParse解析器)

 宇智波瞬潤 2016-09-06
- (NSDictionary *)parse:(NSString *)string error:(NSError **)error
{
     self.scanner = [NSScanner scannerWithString:string];
     self.scanner.charactersToBeSkipped = [NSCharacterSet whitespaceCharacterSet];
     NSMutableDictionary *result = [NSMutableDictionary dictionary];
     NSCharacterSet *letters = [NSCharacterSet letterCharacterSet]
     while (!self.scanner.isAtEnd) {
          NSString *key = nil;
          UIColor *value = nil;
          BOOL didScan = [self.scanner scanCharactersFromSet:letters intoString:&key] &&
               [self.scanner scanString:@"=" intoString:NULL] &&
               [self scanColor:&value];
          result[key] = value;
          [self.scanner scanCharactersFromSet:[NSCharacterSet newlineCharacterSet]
               intoString:NULL]; // 繼續(xù)掃描下一行
     }
}
- (BOOL)scanColor:(UIColor **)out
{
     return [self scanHexColorIntoColor:out] || [self scanTupleColorIntoColor:out];
}
//掃描設(shè)置#ff0000這樣的
- (BOOL)scanHexColorIntoColor:(UIColor **)out
{
     NSCharacterSet *hexadecimalCharacterSet =
          [NSCharacterSet characterSetWithCharactersInString:@"0123456789abcdefABCDEF"];
     NSString *colorString = NULL;
     if ([self.scanner scanString:@"#" intoString:NULL] &&
          [self.scanner scanCharactersFromSet:hexadecimalCharacterSet
          intoString:&colorString] &&
          colorString.length == 6) {
          *out = [UIColor colorWithHexString:colorString];
          return YES;
     }
     return NO;
}
- (BOOL)scanTupleColorIntoColor:(UIColor **)out
{
     NSInteger red, green, blue = 0;
     BOOL didScan = [self.scanner scanString:@"(" intoString:NULL] &&
          [self.scanner scanInteger:&red] &&
          [self.scanner scanString:@"," intoString:NULL] &&
          [self.scanner scanInteger:&green] &&
          [self.scanner scanString:@"," intoString:NULL] &&
          [self.scanner scanInteger:&blue] &&
          [self.scanner scanString:@")" intoString:NULL];
     if (didScan) {
          *out = [UIColor colorWithRed:(CGFloat)red/255.
               green:(CGFloat)green/255.
               blue:(CGFloat)blue/255.
               alpha:1];
          return YES;
     else {
          return NO;
     }
}

    本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻(xiàn)花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多