forked from nygard/class-dump
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNSString-Extensions.m
More file actions
54 lines (40 loc) · 1.51 KB
/
NSString-Extensions.m
File metadata and controls
54 lines (40 loc) · 1.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This file is part of class-dump, a utility for examining the Objective-C segment of Mach-O files.
// Copyright (C) 1997-1998, 2000-2001, 2004-2006 Steve Nygard
#import "NSString-Extensions.h"
#import <Foundation/Foundation.h>
@implementation NSString (CDExtensions)
+ (NSString *)stringWithFileSystemRepresentation:(const char *)str;
{
// 2004-01-16: I'm don't understand why we need to pass in the length.
return [[NSFileManager defaultManager] stringWithFileSystemRepresentation:str length:strlen(str)];
}
+ (NSString *)spacesIndentedToLevel:(int)level;
{
return [self spacesIndentedToLevel:level spacesPerLevel:4];
}
+ (NSString *)spacesIndentedToLevel:(int)level spacesPerLevel:(int)spacesPerLevel;
{
NSString *spaces = @" ";
NSString *levelSpaces;
NSMutableString *str;
int l;
assert(spacesPerLevel <= [spaces length]);
levelSpaces = [spaces substringToIndex:spacesPerLevel];
str = [NSMutableString string];
for (l = 0; l < level; l++)
[str appendString:levelSpaces];
return str;
}
+ (NSString *)stringWithUnichar:(unichar)character;
{
return [NSString stringWithCharacters:&character length:1];
}
- (BOOL)isFirstLetterUppercase;
{
NSRange letterRange;
letterRange = [self rangeOfCharacterFromSet:[NSCharacterSet letterCharacterSet]];
if (letterRange.length == 0)
return NO;
return [[NSCharacterSet uppercaseLetterCharacterSet] characterIsMember:[self characterAtIndex:letterRange.location]];
}
@end