From 19589a22067c92198ab8a8d96cb37c320d5d0311 Mon Sep 17 00:00:00 2001
From: cacaodev
Date: Mon, 3 Nov 2008 19:06:43 +0100
Subject: [PATCH] compare:options:range: implementation
---
Foundation/CPString.j | 19 +++++++++++++++++++
1 files changed, 19 insertions(+), 0 deletions(-)
diff --git a/Foundation/CPString.j b/Foundation/CPString.j
index 8929294..027716d 100644
--- a/Foundation/CPString.j
+++ b/Foundation/CPString.j
@@ -453,6 +453,25 @@ var CPStringHashes = new objj_dictionary();
}
/*!
+ Compares the receiver to the specified string, using options in range.
+ @param aString the string with which to compare the range of the receiver specified by range.
+ @param aMask the options to use for the comparison
+ @param range the range of the receiver over which to perform the comparison. The range must not exceed the bounds of the receiver.
+ @return the result of the comparison
+*/
+- (CPComparisonResult)compare:(CPString)aString options:(int)aMask range:(CPRange)range
+{
+ if (range.location + range.length > [self length])
+ [CPException raise:CPRangeException reason:"Range exceeds the length of the receiver"]; // should raise in cocoa but doesn't
+
+ var lhs = [self substringWithRange:range],
+ rhs = aString;
+
+ return [lhs compare:rhs options:aMask];
+ // special case "" is Nan in Javascipt and "" in cocoa. If lhs or rhs is nil, result is iundefined in cocoa
+}
+
+/*!
Returns YES
if the receiver starts
with the specified string. If aString
is empty, the method will return NO
.
--
1.6.0.2