Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions ConciseKitSpecs/Spec/NSStringConciseKitSpec.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
assertThat([@"ab cd ef" $split], equalTo($arr(@"ab",@"cd",@"ef")));
});
});

describe(@"-$trim", ^{
it(@"removes leading and trailing whitespace", ^{
assertThat([@"\t \n foo \t \n " $trim], equalTo(@"foo"));
});
});

});

describe(@"NSMutableString (ConciseKit)", ^{
Expand Down Expand Up @@ -91,6 +98,16 @@
assertThat(mstring, equalTo(@"bar"));
});
});

describe(@"-$chars", ^{
it(@"splits the string into characters", ^{
assertThat([@"abc" $chars], equalTo($arr(@"a", @"b", @"c")));
});

it(@"returns an empty array for an empty string", ^{
assertThat([@"" $chars], equalTo($arr(nil)));
});
});
});
}
DESCRIBE_END
2 changes: 2 additions & 0 deletions src/NSString+ConciseKit.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
- (NSString *)$prepend:(NSString *)aString;
- (NSArray *)$split:(NSString *)aString;
- (NSArray *)$split;
- (NSArray *)$chars;
- (NSString *)$trim;

@end

Expand Down
15 changes: 14 additions & 1 deletion src/NSString+ConciseKit.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,20 @@ @implementation NSString (ConciseKit)
}

- (NSArray *)$split {
return [self componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
return [self componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

- (NSArray *)$chars {
NSMutableArray *array = [[[NSMutableArray alloc] init] autorelease];
for (int i=0; i < [self length]; i++) {
NSString *spot = [NSString stringWithFormat:@"%c", [self characterAtIndex:i]];
[array addObject: spot];
}
return array;
}

- (NSString*)$trim {
return [self stringByTrimmingCharactersInSet: [NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

@end
Expand Down