Sha256: f99fe3aa493c7480d5122e70f3b6551b3e11b1122b853dda362ebd635d21e765
Contents?: true
Size: 1.33 KB
Versions: 396
Compression:
Stored size: 1.33 KB
Contents
#import "AcronymExample.h" @implementation Acronym + (NSString *)abbreviate:(NSString *)text { NSMutableString *result = [[NSMutableString alloc] init]; NSMutableCharacterSet *characterSet = [NSMutableCharacterSet whitespaceCharacterSet]; [characterSet formUnionWithCharacterSet:[NSCharacterSet punctuationCharacterSet]]; NSArray *components = [text componentsSeparatedByCharactersInSet:characterSet]; for (NSString *component in components) { unichar previousCharacter = 0; for (int i = 0; i < [component length]; i++) { unichar character = [component characterAtIndex:i]; BOOL includeForCamelcase = [self isUppercaseCharacter:character] && [self isLowercaseCharacter:previousCharacter]; if (i == 0 || includeForCamelcase) { result = [[result stringByAppendingString:[NSString stringWithFormat:@"%c", character]] mutableCopy]; } previousCharacter = character; } } return [result uppercaseString]; } + (BOOL)isUppercaseCharacter:(unichar)character { return [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:character]; } + (BOOL)isLowercaseCharacter:(unichar)character { return [[NSCharacterSet lowercaseLetterCharacterSet] characterIsMember:character]; } @end
Version data entries
396 entries across 396 versions & 1 rubygems