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

Version Path
trackler-2.2.1.139 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.138 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.137 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.136 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.135 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.134 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.133 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.132 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.131 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.130 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.129 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.128 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.127 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.126 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.125 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.124 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.123 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.122 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.121 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.120 tracks/objective-c/exercises/acronym/AcronymExample.m