Skip to content

Commit

Permalink
Use character set instead of regex
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyKuryanov committed Oct 20, 2016
1 parent 01f1fee commit 1b600d5
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions librato-iOS/Categories/NSString+SanitizedForMetric.m
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ @implementation NSString (SanitizedForMetric)

- (NSString *)sanitizedForMetric
{
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[^A-Za-z0-9.:-_]" options:0 error:NULL];
NSString *cleaned = [regex stringByReplacingMatchesInString:self options:0 range:NSMakeRange(0, self.length) withTemplate:@"-"];
NSCharacterSet *allowedSet = [NSCharacterSet characterSetWithCharactersInString:@"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.:-_"];
NSString *cleaned = [[self componentsSeparatedByCharactersInSet:allowedSet.invertedSet] componentsJoinedByString:@"-"];
return [cleaned substringToIndex:(self.length < 255 ? self.length : 255)];
}

Expand Down

0 comments on commit 1b600d5

Please sign in to comment.