@@ -98,15 +98,35 @@ - (NSString *)parameterNameOfProperty:(NSString *)propertyName withSeparator:(NS
9898 return propertyName;
9999 }
100100
101- static NSRegularExpression *parameterNameRegex;
102- static dispatch_once_t onceToken;
103- dispatch_once (&onceToken, ^{
104- parameterNameRegex = [NSRegularExpression regularExpressionWithPattern: @" ([a-z])([A-Z])" options: kNilOptions error: NULL ];
105- });
101+ NSMutableString *parameterName = [NSMutableString new ];
102+ const char *chars = propertyName.UTF8String ;
103+ for (NSUInteger i = 0 ; i < propertyName.length ; i++) {
104+ BOOL hasPrevious = i != 0 ;
105+ BOOL hasNext = i + 1 < propertyName.length ;
106+ BOOL prependUnderscore = NO ;
107+ char ch = chars[i];
108+ if (isupper (ch)) {
109+ if (hasPrevious) {
110+ if (!isupper (chars[i - 1 ])) {
111+ prependUnderscore = YES ;
112+ }
113+ }
114+ if (hasNext && !prependUnderscore) {
115+ if (!isupper (chars[i + 1 ])) {
116+ prependUnderscore = YES ;
117+ }
118+ }
119+ ch = tolower (ch);
120+ }
121+ if (prependUnderscore) {
122+ [parameterName appendFormat: @" _%c " , ch];
123+ }
124+ else {
125+ [parameterName appendFormat: @" %c " , ch];
126+ }
127+ }
106128
107- NSString *parameterName = [parameterNameRegex stringByReplacingMatchesInString: propertyName options: kNilOptions range: NSMakeRange (0 , propertyName.length) withTemplate: [NSString stringWithFormat: @" $1%@ $2" , separator]];
108- parameterName = parameterName.lowercaseString ;
109- return parameterName;
129+ return [NSString stringWithString: parameterName];
110130}
111131
112132@end
0 commit comments