From 1b600d53c9ae6bc26604337fdb9380bed5261cc1 Mon Sep 17 00:00:00 2001 From: Sergey Kuryanov Date: Thu, 20 Oct 2016 20:38:37 +0300 Subject: [PATCH] Use character set instead of regex --- librato-iOS/Categories/NSString+SanitizedForMetric.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/librato-iOS/Categories/NSString+SanitizedForMetric.m b/librato-iOS/Categories/NSString+SanitizedForMetric.m index 71a215a..838b31a 100644 --- a/librato-iOS/Categories/NSString+SanitizedForMetric.m +++ b/librato-iOS/Categories/NSString+SanitizedForMetric.m @@ -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)]; }