久久国产成人av_抖音国产毛片_a片网站免费观看_A片无码播放手机在线观看,色五月在线观看,亚洲精品m在线观看,女人自慰的免费网址,悠悠在线观看精品视频,一级日本片免费的,亚洲精品久,国产精品成人久久久久久久

分享

iOS字符串處理筆記(正則表達式,、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];
}
//掃描設置#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;
     }
}

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

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多