Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions Objective-C/FlickerNumber/Classes/UILabel+FlickerNumber.m
Original file line number Diff line number Diff line change
Expand Up @@ -399,21 +399,16 @@ - (NSNumberFormatter *)defaultFormatter {
* @return The string-format String.
*/
- (NSString *)regexNumberFormat:(NSString *)formatString {
NSError *regexError = nil;
NSRegularExpression *regex =
[NSRegularExpression regularExpressionWithPattern:@"^%((\\d+.\\d+)|(\\d+).|(.\\d+))f$"
options:NSRegularExpressionCaseInsensitive
error:&regexError];
if (!regexError) {
NSTextCheckingResult *match = [regex firstMatchInString:formatString
options:0
range:NSMakeRange(0, [formatString length])];
if (match) {
NSString *result = [formatString substringWithRange:match.range];
return result;
}
} else {
NSLog(@"error - %@", regexError);
error:nil];
NSTextCheckingResult *match = [regex firstMatchInString:formatString
options:0
range:NSMakeRange(0, [formatString length])];
if (match) {
NSString *result = [formatString substringWithRange:match.range];
return result;
}
return @"%f";
}
Expand Down
14 changes: 5 additions & 9 deletions Swift/FlickerNumber-Swift/UILabel+FlickerNumber.swift
Original file line number Diff line number Diff line change
Expand Up @@ -438,15 +438,11 @@ extension UILabel {
*/
fileprivate func regexNumberFormat(_ format: String) -> String {
let patternStr = "^%((\\d+.\\d+)|(\\d+).|(.\\d+))f$"
do {
let regex : NSRegularExpression = try NSRegularExpression(pattern: patternStr, options: .caseInsensitive)
let fRange = NSRange(location: 0, length: format.count)
if let match = regex.firstMatch(in: format, options: .reportProgress, range: fRange) {
let result = (format as NSString).substring(with: match.range)
return result
}
} catch {
print("Exception")
let regex = try! NSRegularExpression(pattern: patternStr, options: .caseInsensitive)
let fRange = NSRange(location: 0, length: format.count)
if let match = regex.firstMatch(in: format, options: .reportProgress, range: fRange) {
let result = (format as NSString).substring(with: match.range)
return result
}
return "%f"
}
Expand Down