From 05811ca9658ea0af9b3820574338f4c37e4089e1 Mon Sep 17 00:00:00 2001 From: Vijay Duvvuri Date: Wed, 10 Sep 2008 19:40:54 +0200 Subject: [PATCH 01/12] - Added method rangeOfString:options:range: - Updated rangeOfString:options to call rangeOfString:options:range - Updated rangeOfString: to call rangeOfString:options --- Foundation/CPString.j | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index d52d3df7f..821668ee6 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -125,14 +125,17 @@ var CPStringHashes = new objj_dictionary(); - (CPRange)rangeOfString:(CPString)aString { - var location = indexOf(aString); - - return CPMakeRange(location, location == CPNotFound ? 0 : aString.length); + return [self rangeOfString:aString options:0]; } - (CPRange)rangeOfString:(CPString)aString options:(int)aMask { - var string = self, + return [self rangeOfString:aString options:aMask range:nil]; +} + +- (CPRange)rangeOfString:(CPString)aString options:(int)aMask range:(CPrange)aRange +{ + var string = (aRange == nil)?self:[self substringWithRange:aRange], location = CPNotFound; if (aMask & CPCaseInsensitiveSearch) @@ -141,9 +144,9 @@ var CPStringHashes = new objj_dictionary(); aString = aString.toLowerCase(); } - if (CPBackwardsSearch) location = lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0); - else if (aMask & CPAnchoredSearch) location = substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound; - else location = indexOf(aString); + if (aMask & CPBackwardsSearch) location = string.lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0); + else if (aMask & CPAnchoredSearch) location = string.substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound; + else location = string.indexOf(aString); return CPMakeRange(location, location == CPNotFound ? 0 : aString.length); } From 8aed3787fd5a1caf1ecd7c17cf5ce26ca7f095ac Mon Sep 17 00:00:00 2001 From: Vijay Duvvuri Date: Sat, 13 Sep 2008 11:09:09 +0200 Subject: [PATCH 02/12] - Added new line after if/else/else if --- Foundation/CPString.j | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 821668ee6..ec431ea63 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -144,9 +144,12 @@ var CPStringHashes = new objj_dictionary(); aString = aString.toLowerCase(); } - if (aMask & CPBackwardsSearch) location = string.lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0); - else if (aMask & CPAnchoredSearch) location = string.substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound; - else location = string.indexOf(aString); + if (aMask & CPBackwardsSearch) + location = string.lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0); + else if (aMask & CPAnchoredSearch) + location = string.substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound; + else + location = string.indexOf(aString); return CPMakeRange(location, location == CPNotFound ? 0 : aString.length); } @@ -268,7 +271,7 @@ var CPStringHashes = new objj_dictionary(); - (CPString)stringByDeletingLastPathComponent { - // FIMXE: this is wrong: a/a/ returns a/a/. + // FIXME: this is wrong: a/a/ returns a/a/. return substr(0, lastIndexOf('/') + 1); } From bae8e1c6b0c337e6108208120d727faecb027bd0 Mon Sep 17 00:00:00 2001 From: Vijay Duvvuri Date: Sat, 13 Sep 2008 11:22:04 +0200 Subject: [PATCH 03/12] Added method doc for rangeOfString:options:range: --- Foundation/CPString.j | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index b6a849d7f..cec4f9bbb 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -294,6 +294,24 @@ CPNumericSearch return [self rangeOfString:aString options:aMask range:nil]; } +/* + Finds the range of characters in the receiver + where the specified string exists in the given range + of the receiver.The search is subject to the options specified in the + specified mask which can be a combination of: +
+CPCaseInsensitiveSearch
+CPLiteralSearch
+CPBackwardsSearch
+CPAnchoredSearch
+CPNumericSearch
+
+ @param aString the string to search for + @param aMask the options to use in the search + @param aRange the range of the receiver in which to search for + @return the range of characters in the receiver. If the string was not found, + the length of the range will be 0. +*/ - (CPRange)rangeOfString:(CPString)aString options:(int)aMask range:(CPrange)aRange { var string = (aRange == nil)?self:[self substringWithRange:aRange], From 2eae5373bc31988eb43d76b3445444285749f8e2 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Sun, 14 Sep 2008 10:51:59 +0200 Subject: [PATCH 04/12] - Updated correct method names in the exception --- Foundation/CPString.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index cec4f9bbb..b054903d2 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -128,7 +128,7 @@ var CPStringHashes = new objj_dictionary(); { if (!format) [CPException raise:CPInvalidArgumentException - reason:"stringWithString: the format can't be 'nil'"]; + reason:"initWithFormat: the format can't be 'nil'"]; self = sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); return self; @@ -143,7 +143,7 @@ var CPStringHashes = new objj_dictionary(); { if (!format) [CPException raise:CPInvalidArgumentException - reason:"stringWithString: the format can't be 'nil'"]; + reason:"initWithFormat: the format can't be 'nil'"]; return sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); } From 1b2aadc6f0b30dce17f93332c5e2ba09e6d368c2 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Sun, 14 Sep 2008 11:35:28 +0200 Subject: [PATCH 05/12] Added boolValue method to CPString --- Foundation/CPString.j | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index b054903d2..18270f307 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -460,6 +460,19 @@ CPNumericSearch return eval(self); } +/* +Returns YES on encountering one of "Y", "y", "T", "t", or +a digit 1-9. Returns NO otherwise. This method skips the initial +whitespace characters, +,- followed by Zeroes. +*/ +- (BOOL)boolValue +{ + aString = self.replace(/^\s+[\+,-]*0*/,""); + if(aString.match(/[Y,y,t,T,[1-9]/) != null) + return YES; + return NO; +} + /* Returns the text as a float point value. */ From ffa91e0f59af0a040771e57b6954dcccbc4a006b Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Mon, 15 Sep 2008 20:35:26 +0200 Subject: [PATCH 06/12] updated according to coding guidelines --- Foundation/CPString.j | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 18270f307..e70459789 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -467,8 +467,8 @@ whitespace characters, +,- followed by Zeroes. */ - (BOOL)boolValue { - aString = self.replace(/^\s+[\+,-]*0*/,""); - if(aString.match(/[Y,y,t,T,[1-9]/) != null) + var aString = self.replace(/^\s+[\+,-]*0*/,""); + if (aString.match(/[Y,y,t,T,[1-9]/) != null) return YES; return NO; } From ec6c08e9ea1f901e1affbeefa3963b997f412cd2 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Tue, 16 Sep 2008 18:40:15 +0200 Subject: [PATCH 07/12] Fixed [CPString boolvalue] method with RegExps --- Foundation/CPString.j | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index e70459789..06cc03895 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -135,7 +135,8 @@ var CPStringHashes = new objj_dictionary(); } /* - Creates a new string using C printf-style formatting. First argument should be a constant format string, like ' "float val = %f" ', remaining arguments should be the variables to print the values of, comma-separated. + Creates a new string using C printf-style formatting. First argument should be a constant format string, + like ' "float val = %f" ', remaining arguments should be the variables to print the values of, comma-separated. @param format the format to be used, printf-style @return the initialized CPString */ @@ -174,6 +175,7 @@ var CPStringHashes = new objj_dictionary(); } // Combining strings + /* Creates a new CPString from the concatenation of the receiver and the specified string. @param aString the string to append to the receiver @@ -459,18 +461,16 @@ CPNumericSearch { return eval(self); } - /* -Returns YES on encountering one of "Y", "y", "T", "t", or -a digit 1-9. Returns NO otherwise. This method skips the initial -whitespace characters, +,- followed by Zeroes. + Returns YES on encountering one of "Y", "y", "T", "t", or + a digit 1-9. Returns NO otherwise. This method skips the initial + whitespace characters, +,- followed by Zeroes. */ + - (BOOL)boolValue { - var aString = self.replace(/^\s+[\+,-]*0*/,""); - if (aString.match(/[Y,y,t,T,[1-9]/) != null) - return YES; - return NO; + var replaceRegExp = new RegExp("^\\s*[\\+,\\-]*0*"); + return RegExp("^[Y,y,t,T,1-9]").test(self.replace(replaceRegExp, '')); } /* From 33c0dcd48212f97fb31da11bbb9dabaeee582706 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Tue, 16 Sep 2008 18:59:07 +0200 Subject: [PATCH 08/12] First unit test for CPString for method boolValue --- Tests/Foundation/CPStringTest.j | 42 +++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Tests/Foundation/CPStringTest.j diff --git a/Tests/Foundation/CPStringTest.j b/Tests/Foundation/CPStringTest.j new file mode 100644 index 000000000..d62682894 --- /dev/null +++ b/Tests/Foundation/CPStringTest.j @@ -0,0 +1,42 @@ +import + +@implementation CPStringTest : OJTestCase + +- (void) testBoolValue +{ + var testString = @" 090"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" YES"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" true"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" True"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" tTR"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" +98"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" -98"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" +08"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" -98"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" NO"; + [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" -N00"; + [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; +} + + +@end From 34f58026dfad4b93e5175d2fc28376b256ea0b15 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Wed, 17 Sep 2008 11:56:57 +0200 Subject: [PATCH 09/12] Updated assertFalse message in CPStringTest Converted tabs to spaces according to coding guidelines --- Foundation/CPString.j | 54 ++++++++++++++--------------- Tests/Foundation/CPStringTest.j | 60 +++++++++++++++++++-------------- 2 files changed, 61 insertions(+), 53 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 06cc03895..91794494e 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -136,7 +136,7 @@ var CPStringHashes = new objj_dictionary(); /* Creates a new string using C printf-style formatting. First argument should be a constant format string, - like ' "float val = %f" ', remaining arguments should be the variables to print the values of, comma-separated. + like ' "float val = %f" ', remaining arguments should be the variables to print the values of, comma-separated. @param format the format to be used, printf-style @return the initialized CPString */ @@ -279,13 +279,13 @@ var CPStringHashes = new objj_dictionary(); 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
-
+
+    CPCaseInsensitiveSearch
+    CPLiteralSearch
+    CPBackwardsSearch
+    CPAnchoredSearch
+    CPNumericSearch
+    
@param aString the string to search for @param aMask the options to use in the search @return the range of characters in the receiver. If the string was not found, @@ -293,30 +293,30 @@ CPNumericSearch */ - (CPRange)rangeOfString:(CPString)aString options:(int)aMask { - return [self rangeOfString:aString options:aMask range:nil]; + return [self rangeOfString:aString options:aMask range:nil]; } /* Finds the range of characters in the receiver where the specified string exists in the given range - of the receiver.The search is subject to the options specified in the + of the receiver.The search is subject to the options specified in the specified mask which can be a combination of: -
-CPCaseInsensitiveSearch
-CPLiteralSearch
-CPBackwardsSearch
-CPAnchoredSearch
-CPNumericSearch
-
+
+    CPCaseInsensitiveSearch
+    CPLiteralSearch
+    CPBackwardsSearch
+    CPAnchoredSearch
+    CPNumericSearch
+    
@param aString the string to search for @param aMask the options to use in the search - @param aRange the range of the receiver in which to search for + @param aRange the range of the receiver in which to search for @return the range of characters in the receiver. If the string was not found, the length of the range will be 0. */ - (CPRange)rangeOfString:(CPString)aString options:(int)aMask range:(CPrange)aRange { - var string = (aRange == nil)?self:[self substringWithRange:aRange], + var string = (aRange == nil)?self:[self substringWithRange:aRange], location = CPNotFound; if (aMask & CPCaseInsensitiveSearch) @@ -326,11 +326,11 @@ CPNumericSearch } if (aMask & CPBackwardsSearch) - location = string.lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0); + location = string.lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0); else if (aMask & CPAnchoredSearch) - location = string.substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound; + location = string.substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound; else - location = string.indexOf(aString); + location = string.indexOf(aString); return CPMakeRange(location, location == CPNotFound ? 0 : aString.length); } @@ -462,15 +462,15 @@ CPNumericSearch return eval(self); } /* - Returns YES on encountering one of "Y", "y", "T", "t", or - a digit 1-9. Returns NO otherwise. This method skips the initial - whitespace characters, +,- followed by Zeroes. + Returns YES on encountering one of "Y", "y", "T", "t", or + a digit 1-9. Returns NO otherwise. This method skips the initial + whitespace characters, +,- followed by Zeroes. */ - (BOOL)boolValue { - var replaceRegExp = new RegExp("^\\s*[\\+,\\-]*0*"); - return RegExp("^[Y,y,t,T,1-9]").test(self.replace(replaceRegExp, '')); + var replaceRegExp = new RegExp("^\\s*[\\+,\\-]*0*"); + return RegExp("^[Y,y,t,T,1-9]").test(self.replace(replaceRegExp, '')); } /* diff --git a/Tests/Foundation/CPStringTest.j b/Tests/Foundation/CPStringTest.j index d62682894..75b4d1269 100644 --- a/Tests/Foundation/CPStringTest.j +++ b/Tests/Foundation/CPStringTest.j @@ -4,39 +4,47 @@ import - (void) testBoolValue { - var testString = @" 090"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" YES"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" true"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" True"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + var testString = @" 090"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" YES"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" true"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + + testString = @" True"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - testString = @" tTR"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + testString = @" tTR"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - testString = @" +98"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + testString = @" +98"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - testString = @" -98"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + testString = @" -98"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - testString = @" +08"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + testString = @" +08"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - testString = @" -98"; - [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + testString = @" -98"; + [self assertTrue:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - testString = @" NO"; - [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; - - testString = @" -N00"; - [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return true"]; + testString = @" NO"; + [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; + + testString = @" -N00"; + [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; + + testString = @" 00"; + [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; + + testString = @" -00"; + [self assertFalse:[testString boolValue] message:"boolValue for the string " + testString + " should return false"]; + } + @end From 6c2a50f76738c802c821639b7167c82eec5bf516 Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Wed, 17 Sep 2008 22:52:11 +0200 Subject: [PATCH 10/12] Added method stringByAppendingFormat and a simple test case for the method --- Foundation/CPString.j | 27 ++++++++++++++++++++++++--- Tests/Foundation/CPStringTest.j | 10 ++++++++++ 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 91794494e..4809679b2 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -176,6 +176,22 @@ var CPStringHashes = new objj_dictionary(); // Combining strings +/* + Returns a string made by appending to the reciever a string constructed from a given format + string and the floowing arguments + @param format the format string in printf-style. + @return the initialized CPString +*/ +- (CPString)stringByAppendingFormat:(CPString)format, ... +{ + if (!format) + [CPException raise:CPInvalidArgumentException + reason:"initWithFormat: the format can't be 'nil'"]; + + + return self + sprintf.apply(this, Array.prototype.slice.call(arguments, 2)); +} + /* Creates a new CPString from the concatenation of the receiver and the specified string. @param aString the string to append to the receiver @@ -491,7 +507,7 @@ var CPStringHashes = new objj_dictionary(); /* Returns an the path components of this string. This - method assumes that the string's contents is a '/' + method assumes that the string's content is a '/' separated file system path. */ - (CPArray)pathComponents @@ -509,6 +525,11 @@ var CPStringHashes = new objj_dictionary(); return substr(lastIndexOf('.')+1); } +/* + Returns the last component of this string. + This method assumes that the string's content is a '/' + separated file system path. +*/ - (CPString)lastPathComponent { var components = [self pathComponents]; @@ -546,11 +567,11 @@ String.prototype.isa = CPString; var sprintfFormatRegex = new RegExp("([^%]+|%[\\+\\-\\ \\#0]*[0-9\\*]*(.[0-9\\*]+)?[hlL]?[cdieEfgGosuxXpn%])", "g"); var sprintfTagRegex = new RegExp("(%)([\\+\\-\\ \\#0]*)([0-9\\*]*)((.[0-9\\*]+)?)([hlL]?)([cdieEfgGosuxXpn%])"); -/** +/* Creates a new string using C printf-style formatting. First argument should be a constant format string, like ' "float val = %f" ', remaining arguments should be the variables to print the values of, comma-separated. @param format the format to be used, printf-style @return the initialized CPString - */ +*/ function sprintf(format) { var format = arguments[0], diff --git a/Tests/Foundation/CPStringTest.j b/Tests/Foundation/CPStringTest.j index 75b4d1269..d61a08f5a 100644 --- a/Tests/Foundation/CPStringTest.j +++ b/Tests/Foundation/CPStringTest.j @@ -2,6 +2,16 @@ import @implementation CPStringTest : OJTestCase +- (void)testStringByAppendingFormat +{ + var format = @"%d X %d = %d"; + var expectedString = "2 X 3 = 6"; + var dummyString = @""; + var actualString = [dummyString stringByAppendingFormat:format ,2 ,3 ,6]; + [self assertTrue:(expectedString === actualString) + message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString]; + +} - (void) testBoolValue { var testString = @" 090"; From 9a397bf03fba2673930fbf7e2ebf908f5992edaf Mon Sep 17 00:00:00 2001 From: vijaykiran Date: Wed, 17 Sep 2008 23:17:56 +0200 Subject: [PATCH 11/12] Added method stringByReplacingOccurrencesOfStringWithString and testcase for the same. --- Foundation/CPString.j | 31 +++++++++++++++++++++++++++++++ Tests/Foundation/CPStringTest.j | 12 ++++++++++++ 2 files changed, 43 insertions(+) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 4809679b2..c5ade8ee7 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -232,6 +232,7 @@ var CPStringHashes = new objj_dictionary(); if (difference) string += substring.substr(difference + substring.length); } +//Dividing Strings /* Tokenizes the receiver string using the specified delimiter. For example, if the receiver is: @@ -351,6 +352,36 @@ var CPStringHashes = new objj_dictionary(); return CPMakeRange(location, location == CPNotFound ? 0 : aString.length); } +//Replacing Substrings + +/* + Returns a new string in which all occurrences of a target string in the reciever are replaced by + another given string. + @param target The string to replace. + @param replacement the string with which to replace the
target
+*/
+
+- (CPString)stringByReplacingOccurrencesOfString:(CPString)target withString:(CPString)replacement
+{
+    return self.replace(new RegExp(target, "g"), replacement);
+}
+/*
+- (CPString)stringByReplacingOccurrencesOfString:(CPString)target 
+                                      withString:(CPString)replacement 
+                                         options:(int)options 
+                                           range:(CPRange)searchRange
+{
+    //TODO :Vijay implement the method
+
+}
+
+- (CPString)stringByReplacingCharactersInRange:(CPRange)range withString:(CPString)replacement
+{
+    //TODO :Vijay implement the method
+}
+*/
+
+
 // Identifying and comparing strings
 /*
     Compares the receiver to the specified string.
diff --git a/Tests/Foundation/CPStringTest.j b/Tests/Foundation/CPStringTest.j
index d61a08f5a..289663cdc 100644
--- a/Tests/Foundation/CPStringTest.j
+++ b/Tests/Foundation/CPStringTest.j
@@ -2,6 +2,18 @@ import 
 
 @implementation CPStringTest : OJTestCase
 
+
+- (void)testStringByReplacingOccurrencesOfStringWithString
+{
+    var expectedString = @"hello world. A new world!";
+    var dummyString = @"hello woold. A new woold!";
+    var actualString = [dummyString stringByReplacingOccurrencesOfString:@"woold" withString:@"world"];
+    [self assertTrue:(expectedString === actualString) 
+             message:"stringByAppendingFormat: expected:" + expectedString + " actual:" + actualString];
+    
+    
+    
+}
 - (void)testStringByAppendingFormat
 {
     var format = @"%d X %d = %d";

From dbedbfddfce94d88dfc6b27144d47eca7f81e7fb Mon Sep 17 00:00:00 2001
From: Ross Boucher 
Date: Wed, 24 Sep 2008 14:09:42 -0700
Subject: [PATCH 12/12] Fixed a few accessors and spacing issues.

---
 Foundation/CPString.j | 36 +++++++++++++++++-------------------
 1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/Foundation/CPString.j b/Foundation/CPString.j
index ef02d1060..d98b64a42 100644
--- a/Foundation/CPString.j
+++ b/Foundation/CPString.j
@@ -185,11 +185,9 @@ var CPStringHashes      = new objj_dictionary();
 - (CPString)stringByAppendingFormat:(CPString)format, ...
 {
     if (!format)
-           [CPException raise:CPInvalidArgumentException
-                       reason:"initWithFormat: the format can't be 'nil'"];
-    
+        [CPException raise:CPInvalidArgumentException reason:"initWithFormat: the format can't be 'nil'"];
 
-    return self + sprintf.apply(this, Array.prototype.slice.call(arguments, 2));   
+    return self + sprintf.apply(this, Array.prototype.slice.call(arguments, 2));
 }
 
 /*
@@ -280,6 +278,7 @@ var CPStringHashes      = new objj_dictionary();
 }
 
 // Finding characters and substrings
+
 /*
     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.
@@ -333,22 +332,22 @@ var CPStringHashes      = new objj_dictionary();
 */
 - (CPRange)rangeOfString:(CPString)aString options:(int)aMask range:(CPrange)aRange
 {
-    var string = (aRange == nil)?self:[self substringWithRange:aRange],
+    var string = (aRange == nil) ? self : [self substringWithRange:aRange],
         location = CPNotFound;
-    
+
     if (aMask & CPCaseInsensitiveSearch)
     {
         string = string.toLowerCase();
         aString = aString.toLowerCase();
     }
-    
-    if (aMask & CPBackwardsSearch) 
+
+    if (aMask & CPBackwardsSearch)
         location = string.lastIndexOf(aString, aMask & CPAnchoredSearch ? length - aString.length : 0);
-    else if (aMask & CPAnchoredSearch) 
+    else if (aMask & CPAnchoredSearch)
         location = string.substr(0, aString.length).indexOf(aString) != CPNotFound ? 0 : CPNotFound;
-    else 
+    else
         location = string.indexOf(aString);
-    
+
     return CPMakeRange(location, location == CPNotFound ? 0 : aString.length);
 }
 
@@ -365,11 +364,9 @@ var CPStringHashes      = new objj_dictionary();
 {
     return self.replace(new RegExp(target, "g"), replacement);
 }
+
 /*
-- (CPString)stringByReplacingOccurrencesOfString:(CPString)target 
-                                      withString:(CPString)replacement 
-                                         options:(int)options 
-                                           range:(CPRange)searchRange
+- (CPString)stringByReplacingOccurrencesOfString:(CPString)target withString:(CPString)replacement options:(int)options range:(CPRange)searchRange
 {
     //TODO :Vijay implement the method
 
@@ -383,6 +380,7 @@ var CPStringHashes      = new objj_dictionary();
 
 
 // Identifying and comparing strings
+
 /*
     Compares the receiver to the specified string.
     @param aString the string with which to compare
@@ -506,7 +504,7 @@ var CPStringHashes      = new objj_dictionary();
 */
 - (double)doubleValue
 {
-    return eval(self);
+    return parseFloat(self, 10);
 }
 /*
     Returns YES on encountering one of "Y", "y", "T", "t", or 
@@ -525,7 +523,7 @@ var CPStringHashes      = new objj_dictionary();
 */
 - (float)floatValue
 {
-    return eval(self);
+    return parseFloat(self, 10);
 }
 
 /*
@@ -533,7 +531,7 @@ var CPStringHashes      = new objj_dictionary();
 */
 - (int)intValue
 {
-    return parseInt(self);
+    return parseInt(self, 10);
 }
 
 /*
@@ -574,7 +572,7 @@ var CPStringHashes      = new objj_dictionary();
 - (CPString)stringByDeletingLastPathComponent
 {
     // FIXME: this is wrong: a/a/ returns a/a/.
-    return substr(0, lastIndexOf('/') + 1);  
+    return substr(0, lastIndexOf('/') + 1);
 }
 
 - (CPString)stringByStandardizingPath