// // RQCommonItemViewModel.m // RQCommon // // Created by 张嵘 on 2018/11/27. // Copyright © 2018 张嵘. All rights reserved. // #import "RQCommonItemViewModel.h" @implementation RQCommonItemViewModel + (instancetype)itemViewModelWithTitle:(NSString *)title icon:(NSString *)icon{ RQCommonItemViewModel *item = [[self alloc] init]; item.title = title; item.icon = icon; return item; } + (instancetype)itemViewModelWithTitle:(NSString *)title{ return [self itemViewModelWithTitle:title icon:nil]; } - (instancetype)init { self = [super init]; if (self) { _selectionStyle = UITableViewCellSelectionStyleGray; _rowHeight = RQ_FIT_HORIZONTAL(60.0f); _delegate = self; } return self; } - (NSString *)itemClassName { return @"RQCommonCell"; } //获取字典 - (NSArray *)getKeyRangeList:(NSString *)originalText readText:(NSString*)readText { if(originalText==nil||readText==nil)return @[]; NSError *error = nil; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"【(.*?)】" options:0 error:&error]; NSMutableArray *array = nil; if (!error) { NSLog(@"readText=%@",readText); array = @[].mutableCopy; NSArray *matches = [regex matchesInString:originalText options:0 range:NSMakeRange(0, originalText.length)]; for (NSTextCheckingResult *match in matches) { NSMutableDictionary *dict = [NSMutableDictionary dictionary]; NSRange matchedRange = [match rangeAtIndex:1]; NSString *extractedText = [originalText substringWithRange:matchedRange]; NSRange range = [readText rangeOfString:extractedText]; dict[extractedText] = @[@(range.location),@(range.length)]; [array addObject:dict]; NSLog(@"Extracted Text: %@", extractedText); NSLog(@"Matched Range: %@", NSStringFromRange(matchedRange)); } } else { NSLog(@"Regex Error: %@", error.localizedDescription); } return array; } @end