NSArray *splitCamelCaseString(NSString *str)
{
NSCharacterSet *cs = [NSCharacterSet uppercaseLetterCharacterSet];
NSMutableArray *result = [[NSMutableArray new] autorelease];
if ([str length] == 0)
return result;
NSRange wordMatch, endMatch;
wordMatch.location = 0;
endMatch = [str rangeOfCharacterFromSet:cs
options:0
range:NSMakeRange(1, [str length] - 1)];
while (endMatch.location != NSNotFound) {
wordMatch.length = endMatch.location - wordMatch.location;
[result addObject:[str substringWithRange:wordMatch]];
wordMatch.location = endMatch.location;
endMatch = [str rangeOfCharacterFromSet:cs
options:0
range:NSMakeRange(wordMatch.location + 1,
[str length] - wordMatch.location - 1)];
}
// add last word
wordMatch.length = [str length] - wordMatch.location;
[result addObject:[str substringWithRange:wordMatch]];
return result;
}