Class CPString

CPObject
    extended byCPString

@implementation CPString : CPObject

CPString is an object that allows management of strings. Because CPString is based on the JavaScript String object, CPStrings are immutable, although the class does have methods that create new CPStrings generated from modifications to the receiving instance.

A handy feature of CPString instances is that they can be used wherever a JavaScript is required, and vice versa.


Global Variables
CPLiteralSearch = 2
        Exact character match
CPCaseInsensitiveSearch = 1
        A case insensitive search
CPAnchoredSearch = 8
        
CPBackwardsSearch = 4
        Start searching from the end of the string
CPNumericSearch = 64
        Numbers in the string are compared as numbers instead of strings

Method Summary
+(id)string
          Returns a new string.
+(id)stringWithHash:(unsigned)aHash
          Returns a CPString containing the specified hash.
+(id)stringWithString:(CPString)aString
          Returns a copy of the specified string.
-(id)initWithString:(CPString)aString
          Initializes the string with data from the specified string.
-(CPString)capitalizedString
          Returns a copy of the receiver with all the first letters of words capitalized.
-(CPComparisonResult)caseInsensitiveCompare:(CPString)aString
          Compares the receiver to the specified string.
-(CPString)characterAtIndex:(unsigned)anIndex
          Returns the character at the specified index.
-(CPComparisonResult)compare:(CPString)aString options:(int)aMask
          Compares the receiver to the specified string, using options.
-(CPArray)componentsSeparatedByString:(CPString)aString
          Tokenizes the receiver string using the specified delimiter.
-(CPString)copy
          Makes a deep copy of the receiver.
-(CPString)cssString
          Returns the string.
-(CPString)description
          Returns a description of this CPString object.
-(double)doubleValue
          Returns the text as a floating point value.
-(float)floatValue
          Returns the text as a float point value.
-(BOOL)hasPrefix:(CPString)aString
          Returns YES if the receiver starts with the specified string.
-(BOOL)hasSuffix:(CPString)aString
          Returns NO if the receiver ends with the specified string.
-(unsigned)hash
          Returns a hash of the string instance.
-(int)intValue
          Returns the text as an integer.
-(BOOL)isEqualToString:(CPString)aString
          Returns YES if the specified string contains the same characters as the receiver.
-(CPString)lastPathComponent
-(int)length
          Returns the number of UTF-8 characters in the string.
-(CPString)lowercaseString
          Returns a copy of the string with all its characters made lower case.
-(CPArray)pathComponents
          Returns an the path components of this string.
-(CPString)pathExtension
          Returns the extension of the file denoted by this string.
-(CPRange)rangeOfString:(CPString)aString
          Finds the range of characters in the receiver where the specified string exists.
-(CPRange)rangeOfString:(CPString)aString options:(int)aMask
          Finds the range of characters in the receiver where the specified string exists.
-(CGSize)sizeWithFont:(CPFont)aFont
-(CPString)string
          Returns the string (self).
-(CPString)stringByAppendingString:(CPString)aString
          Creates a new CPString from the concatenation of the receiver and the specified string.
-(CPString)stringByPaddingToLength:(unsigned)aLength withString:(CPString)aString startingAtIndex:(unsigned)anIndex
          Returns a new string formed by padding characters or removing them.
-(CPString)stringByStandardizingPath
-(CPString)substringFromIndex:(unsigned)anIndex
          Returns a substring starting from the specified index to the end of the receiver.
-(CPString)substringToIndex:(unsigned)anIndex
          Creates a substring from the beginning of the receiver to the specified index.
-(CPString)substringWithRange:(CPRange)aRange
          Returns a substring starting from the specified range location to the range length.
-(CPString)uppercaseString
          Returns a copy of the string with all its characters made upper case.

Methods inherited from class CPObject
initialize, alloc, class, instanceMethodForSelector, instancesRespondToSelector, isSubclassOfClass, load, new, setVersion, superclass, version, init, autorelease, awakeAfterUsingCoder, class, classForCoder, classForKeyedArchiver, className, copy, dealloc, description, doesNotRecognizeSelector, forwardInvocation, hash, isEqual, isKindOfClass, isMemberOfClass, isProxy, methodForSelector, methodSignatureForSelector, mutableCopy, performSelector, performSelector, performSelector, release, replacementObjectForArchiver, replacementObjectForCoder, replacementObjectForKeyedArchiver, respondsToSelector, retain, self, superclass


Method Detail

string

+(id)string
Returns a new string

stringWithHash

+(id)stringWithHash:(unsigned)aHash
Returns a CPString containing the specified hash.
Parameters:
aHash - the hash to represent as a string

stringWithString

+(id)stringWithString:(CPString)aString
Returns a copy of the specified string.
Parameters:
aString - a non-nil string to copy
Throws:
CPInvalidArgumentException - if aString is nil
Returns:
the new CPString

initWithString

-(id)initWithString:(CPString)aString
Initializes the string with data from the specified string.
Parameters:
aString - the string to copy data from
Returns:
the initialized CPString

capitalizedString

-(CPString)capitalizedString
Returns a copy of the receiver with all the first letters of words capitalized.

caseInsensitiveCompare

-(CPComparisonResult)caseInsensitiveCompare:(CPString)aString
Compares the receiver to the specified string.
Parameters:
aString - the string with which to compare
Returns:
the result of the comparison

characterAtIndex

-(CPString)characterAtIndex:(unsigned)anIndex
Returns the character at the specified index.
Parameters:
anIndex - the index of the desired character

compare

-(CPComparisonResult)compare:(CPString)aString options:(int)aMask
Compares the receiver to the specified string, using options.
Parameters:
aString - the string with which to compare
aMask - the options to use for the comparison
Returns:
the result of the comparison

componentsSeparatedByString

-(CPArray)componentsSeparatedByString:(CPString)aString
Tokenizes the receiver string using the specified delimiter. For example, if the receiver is:
"arash.francisco.ross.tom"
and the delimiter is:
"."
the returned array would contain:
["arash", "francisco", "ross", "tom"]
Parameters:
aString
Returns:
the array of tokens

copy

-(CPString)copy
Makes a deep copy of the receiver. The copy should be functionally equivalent to the receiver.
Returns:
the copy of the receiver

cssString

-(CPString)cssString
Returns the string

description

-(CPString)description
Returns a description of this CPString object.

doubleValue

-(double)doubleValue
Returns the text as a floating point value.

floatValue

-(float)floatValue
Returns the text as a float point value.

hasPrefix

-(BOOL)hasPrefix:(CPString)aString
Returns YES if the receiver starts with the specified string. If aString is empty, the method will return NO.
Parameters:
aString

hasSuffix

-(BOOL)hasSuffix:(CPString)aString
Returns NO if the receiver ends with the specified string. If aString is empty, the method will return NO.
Parameters:
aString

hash

-(unsigned)hash
Returns a hash of the string instance.

intValue

-(int)intValue
Returns the text as an integer

isEqualToString

-(BOOL)isEqualToString:(CPString)aString
Returns YES if the specified string contains the same characters as the receiver.
Parameters:
aString

lastPathComponent

-(CPString)lastPathComponent

length

-(int)length
Returns the number of UTF-8 characters in the string.

lowercaseString

-(CPString)lowercaseString
Returns a copy of the string with all its characters made lower case.

pathComponents

-(CPArray)pathComponents
Returns an the path components of this string. This method assumes that the string's contents is a '/' separated file system path.

pathExtension

-(CPString)pathExtension
Returns the extension of the file denoted by this string. The '.' is not a part of the extension. This method assumes that the string's contents is the path to a file or just a filename.

rangeOfString

-(CPRange)rangeOfString:(CPString)aString
Finds the range of characters in the receiver where the specified string exists. If the string does not exist in the receiver, the range length will be 0.
Parameters:
aString - the string to search for in the receiver
Returns:
the range of charactrs in the receiver

rangeOfString

-(CPRange)rangeOfString:(CPString)aString options:(int)aMask
Finds the range of characters in the receiver where the specified string exists. The search is subject to the options specified in the specified mask which can be a combination of:
CPCaseInsensitiveSearch
CPLiteralSearch
CPBackwardsSearch
CPAnchoredSearch
CPNumericSearch
Parameters:
aString - the string to search for
aMask - the options to use in the search
Returns:
the range of characters in the receiver. If the string was not found, the length of the range will be 0.

sizeWithFont

-(CGSize)sizeWithFont:(CPFont)aFont
Parameters:
aFont

string

-(CPString)string
Returns the string (self).

stringByAppendingString

-(CPString)stringByAppendingString:(CPString)aString
Creates a new CPString from the concatenation of the receiver and the specified string.
Parameters:
aString - the string to append to the receiver
Returns:
the new string

stringByPaddingToLength

-(CPString)stringByPaddingToLength:(unsigned)aLength withString:(CPString)aString startingAtIndex:(unsigned)anIndex
Returns a new string formed by padding characters or removing them. If the padding length is shorter than the receiver's length, the new string will be trimmed down to the padding length size. If the padding length is longer than the receiver's length, then the new string is repeatedly padded with the characters from the specified string starting at the specified index.
Parameters:
aLength - the desired length of the new CPString
aString - the padding string to use (if necessary)
anIndex - the index of the padding string to start from (if necessary to use)
Returns:
the new padded string

stringByStandardizingPath

-(CPString)stringByStandardizingPath

substringFromIndex

-(CPString)substringFromIndex:(unsigned)anIndex
Returns a substring starting from the specified index to the end of the receiver.
Parameters:
anIndex - the starting string (inclusive)
Returns:
the substring

substringToIndex

-(CPString)substringToIndex:(unsigned)anIndex
Creates a substring from the beginning of the receiver to the specified index.
Parameters:
anIndex - the last index of the receiver to use for the substring (inclusive)
Returns:
the substring

substringWithRange

-(CPString)substringWithRange:(CPRange)aRange
Returns a substring starting from the specified range location to the range length.
Parameters:
aRange
Returns:
the substring

uppercaseString

-(CPString)uppercaseString
Returns a copy of the string with all its characters made upper case.

Created on Sat Sep 13 14:15:43 PDT 2008