OLD | NEW |
(Empty) | |
| 1 // -*- mode: ObjC -*- |
| 2 |
| 3 // This file is part of class-dump, a utility for examining the Objective-C seg
ment of Mach-O files. |
| 4 // Copyright (C) 1997-1998, 2000-2001, 2004-2010 Steve Nygard. |
| 5 |
| 6 #import "NSString-Extensions.h" |
| 7 |
| 8 #import "NSData-CDExtensions.h" |
| 9 |
| 10 @implementation NSString (CDExtensions) |
| 11 |
| 12 + (NSString *)stringWithFileSystemRepresentation:(const char *)str; |
| 13 { |
| 14 // 2004-01-16: I'm don't understand why we need to pass in the length. |
| 15 return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:st
r length:strlen(str)]; |
| 16 } |
| 17 |
| 18 + (NSString *)spacesIndentedToLevel:(NSUInteger)level; |
| 19 { |
| 20 return [self spacesIndentedToLevel:level spacesPerLevel:4]; |
| 21 } |
| 22 |
| 23 + (NSString *)spacesIndentedToLevel:(NSUInteger)level spacesPerLevel:(NSUInteger
)spacesPerLevel; |
| 24 { |
| 25 NSString *spaces = @" "; |
| 26 NSString *levelSpaces; |
| 27 NSMutableString *str; |
| 28 NSUInteger l; |
| 29 |
| 30 NSParameterAssert(spacesPerLevel <= [spaces length]); |
| 31 levelSpaces = [spaces substringToIndex:spacesPerLevel]; |
| 32 |
| 33 str = [NSMutableString string]; |
| 34 for (l = 0; l < level; l++) |
| 35 [str appendString:levelSpaces]; |
| 36 |
| 37 return str; |
| 38 } |
| 39 |
| 40 + (NSString *)stringWithUnichar:(unichar)character; |
| 41 { |
| 42 return [NSString stringWithCharacters:&character length:1]; |
| 43 } |
| 44 |
| 45 - (BOOL)isFirstLetterUppercase; |
| 46 { |
| 47 NSRange letterRange; |
| 48 |
| 49 letterRange = [self rangeOfCharacterFromSet:[NSCharacterSet letterCharacterS
et]]; |
| 50 if (letterRange.length == 0) |
| 51 return NO; |
| 52 |
| 53 return [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self
characterAtIndex:letterRange.location]]; |
| 54 } |
| 55 |
| 56 - (void)print; |
| 57 { |
| 58 NSData *data; |
| 59 |
| 60 data = [self dataUsingEncoding:NSUTF8StringEncoding]; |
| 61 [(NSFileHandle *)[NSFileHandle fileHandleWithStandardOutput] writeData:data]
; |
| 62 } |
| 63 |
| 64 - (NSString *)executablePathForFilename; |
| 65 { |
| 66 NSBundle *bundle; |
| 67 NSString *path; |
| 68 |
| 69 // I give up, all the methods dealing with paths seem to resolve symlinks wi
th a vengence. |
| 70 bundle = [NSBundle bundleWithPath:self]; |
| 71 if (bundle != nil) { |
| 72 if ([bundle executablePath] == nil) |
| 73 return nil; |
| 74 |
| 75 path = [[[bundle executablePath] stringByResolvingSymlinksInPath] string
ByStandardizingPath]; |
| 76 } else { |
| 77 path = [[self stringByResolvingSymlinksInPath] stringByStandardizingPath
]; |
| 78 } |
| 79 |
| 80 return path; |
| 81 } |
| 82 |
| 83 - (NSString *)SHA1DigestString; |
| 84 { |
| 85 return [[[self decomposedStringWithCanonicalMapping] dataUsingEncoding:NSUTF
8StringEncoding] SHA1DigestString]; |
| 86 } |
| 87 |
| 88 - (BOOL)hasUnderscoreCapitalPrefix; |
| 89 { |
| 90 if ([self length] < 2) |
| 91 return NO; |
| 92 |
| 93 return [self hasPrefix:@"_"] && [[NSCharacterSet uppercaseLetterCharacterSet
] characterIsMember:[self characterAtIndex:1]]; |
| 94 } |
| 95 |
| 96 - (NSString *)capitalizeFirstCharacter; |
| 97 { |
| 98 if ([self length] < 2) |
| 99 return [self capitalizedString]; |
| 100 |
| 101 return [NSString stringWithFormat:@"%@%@", [[self substringToIndex:1] capita
lizedString], [self substringFromIndex:1]]; |
| 102 } |
| 103 |
| 104 @end |
| 105 |
| 106 @implementation NSMutableString (CDExtensions) |
| 107 |
| 108 - (void)appendSpacesIndentedToLevel:(NSUInteger)level; |
| 109 { |
| 110 [self appendSpacesIndentedToLevel:level spacesPerLevel:4]; |
| 111 } |
| 112 |
| 113 - (void)appendSpacesIndentedToLevel:(NSUInteger)level spacesPerLevel:(NSUInteger
)spacesPerLevel; |
| 114 { |
| 115 NSString *spaces = @" "; |
| 116 NSString *levelSpaces; |
| 117 NSUInteger l; |
| 118 |
| 119 NSParameterAssert(spacesPerLevel <= [spaces length]); |
| 120 levelSpaces = [spaces substringToIndex:spacesPerLevel]; |
| 121 |
| 122 for (l = 0; l < level; l++) |
| 123 [self appendString:levelSpaces]; |
| 124 } |
| 125 |
| 126 @end |
OLD | NEW |