]]> ]]>

CamelCase в Objective-C

Пример для версий gcc 3.4.5 (Objective-C)
#import <Foundation/Foundation.h>

#define LETTERS @"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"

NSString *camelCase(NSString *s) {
  return [[[s capitalizedString] componentsSeparatedByCharactersInSet:[[NSCharacterSet characterSetWithCharactersInString:LETTERS] invertedSet]] componentsJoinedByString:@""];
}

int main (int argc, const char * argv[]) {
    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];

    NSLog(@"%@", camelCase(@"Test Example One"));
    NSLog(@"%@", camelCase(@"exampleTwo "));
    NSLog(@"%@", camelCase(@"!!! is_this_3RD EXAMPLE?.."));

    [pool drain];
    return 0;
}

Комментарии

]]>

blog comments powered by Disqus

]]>

Работа программистам