mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-26 12:20:43 +00:00
- moved componentsSeparatedByCharactersInSet: into CPCharacterSetAdditions CPString category
- added tests for componentsSeparatedByCharactersInSet:
- ensured Cocoa compatibility of componentsSeparatedByCharactersInSet:
- added new test for CPString boolValue
- fixed CPString boolValue (" ++01" should return NO as in Cocoa, previously it returned YES)
This commit is contained in:
committed by
Alexander Ljungberg
parent
009683ddd4
commit
ddfac8d717
@@ -322,6 +322,43 @@ _CPCharacterSetTrimAtEnd = 1 << 2;
|
||||
|
||||
@implementation CPString (CPCharacterSetAdditions)
|
||||
|
||||
/*!
|
||||
Tokenizes the receiver string using the charactes
|
||||
in a given set. For example, if the receiver is:
|
||||
\c "Baku baku to jest skład."
|
||||
and the set is [CPCharacterSet whitespaceCharacterSet]
|
||||
the returned array would contain:
|
||||
<pre> ["Baku", "baku", "to", "jest", "", "skład."] </pre>
|
||||
Adjacent occurences of the separator characters produce empty strings in the result.
|
||||
@author Arkadiusz Młynarczyk <arek@tupux.com>
|
||||
@param A character set containing the characters to use to split the receiver. Must not be nil.
|
||||
@return An CPArray object containing substrings from the receiver that have been divided by characters in separator.
|
||||
*/
|
||||
- (CPArray)componentsSeparatedByCharactersInSet:(CPCharacterSet)separator
|
||||
{
|
||||
if (!separator)
|
||||
[CPException raise:CPInvalidArgumentException
|
||||
reason:"componentsSeparatedByCharactersInSet: the separator can't be 'nil'"];
|
||||
|
||||
var components = [CPMutableArray array];
|
||||
var componentRange = CPMakeRange(0, 0);
|
||||
|
||||
for (var i=0; i < self.length; i++)
|
||||
{
|
||||
if ([separator characterIsMember:self.charAt(i)])
|
||||
{
|
||||
componentRange.length = i - componentRange.location;
|
||||
[components addObject:[self substringWithRange:componentRange]];
|
||||
componentRange.location += componentRange.length + 1;
|
||||
}
|
||||
}
|
||||
|
||||
componentRange.length = self.length - componentRange.location;
|
||||
[components addObject:[self substringWithRange:componentRange]];
|
||||
|
||||
return components;
|
||||
}
|
||||
|
||||
// As per the Cocoa method.
|
||||
- (id)stringByTrimmingCharactersInSet:(CPCharacterSet)set
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user