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.180 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.179 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.178 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.177 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.176 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.175 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.174 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.173 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.172 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.171 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.170 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.169 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.167 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.166 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.165 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.164 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.163 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.162 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.161 tracks/objective-c/exercises/acronym/AcronymExample.m
trackler-2.2.1.160 tracks/objective-c/exercises/acronym/AcronymExample.m