diff --git a/Foundation/CPCharacterSet.j b/Foundation/CPCharacterSet.j index c9b376f34..b0d90cd6f 100644 --- a/Foundation/CPCharacterSet.j +++ b/Foundation/CPCharacterSet.j @@ -147,7 +147,8 @@ var _builtInCharacterSets = {}; + (id)_sharedCharacterSetWithName:(id)csname { var cs = _builtInCharacterSets[csname]; - if (cs == nil) + + if (cs === nil) { var i = 0, ranges = [CPArray array], @@ -160,6 +161,7 @@ var _builtInCharacterSets = {}; range = CPMakeRange(loc,length); [ranges addObject:range]; } + cs = [[_CPRangeCharacterSet alloc] initWithRanges:ranges]; _builtInCharacterSets[csname] = cs; } @@ -252,17 +254,29 @@ var CPCharacterSetInvertedKey = @"CPCharacterSetInvertedKey"; - (BOOL)hasMemberInPlane:(int)plane // TO DO : when inverted { - // FIXME: range is undefined... don't know what's supposed to be going on here. - // the highest Unicode plane we reach. - // (There are 65536 code points in each plane.) - var maxPlane = FLOOR((range.start + range.length - 1) / 65536); // FIXME: should iterate _ranges + // JavaScript strings can only return char codes + // up to 0xFFFF (per the ECMA standard), so + // they all live in the Basic Multilingual Plane + // (aka plane 0). - return (plane <= maxPlane); + if (plane !== 0) + return NO; + + var enu = [_ranges objectEnumerator], + range; + + while ((range = [enu nextObject]) !== nil) + { + if (!CPEmptyRange(range)) + return YES; + } + + return NO; } - (void)addCharactersInRange:(CPRange)aRange // Needs _inverted support { - [_ranges addObject:aRange]; + [_ranges addObject:aRange]; } - (void)addCharactersInString:(CPString)aString // Needs _inverted support @@ -317,7 +331,7 @@ var CPCharacterSetInvertedKey = @"CPCharacterSetInvertedKey"; - (BOOL)characterIsMember:(CPString)c { - return (_string.indexOf(c.charAt(0)) != -1) == !_inverted; + return (_string.indexOf(c.charAt(0)) !== -1) === !_inverted; } - (CPString)description @@ -331,9 +345,8 @@ var CPCharacterSetInvertedKey = @"CPCharacterSetInvertedKey"; // up to 0xFFFF (per the ECMA standard), so // they all live in the Basic Multilingual Plane // (aka plane 0). - // TODO if the above is wrong, this must be changed! - return plane == 0; + return _string.length && plane === 0; } - (void)addCharactersInRange:(CPRange)aRange // Needs _inverted support @@ -379,7 +392,7 @@ var CPCharacterSetInvertedKey = @"CPCharacterSetInvertedKey"; if (!aCharacterSet) return NO; - return _string == aCharacterSet._string && _inverted == aCharacterSet._inverted; + return _string === aCharacterSet._string && _inverted === aCharacterSet._inverted; } @end diff --git a/Foundation/CPKeyValueObserving.j b/Foundation/CPKeyValueObserving.j index ecf7e1c1d..b0d8a5906 100644 --- a/Foundation/CPKeyValueObserving.j +++ b/Foundation/CPKeyValueObserving.j @@ -23,6 +23,7 @@ @import "CPArray.j" @import "CPDictionary.j" @import "CPException.j" +@import "CPIndexSet.j" @import "CPNull.j" @import "CPObject.j" @import "CPSet.j" diff --git a/Foundation/CPPredicate/CPComparisonPredicate.j b/Foundation/CPPredicate/CPComparisonPredicate.j index 962d4e277..ffe374e7a 100644 --- a/Foundation/CPPredicate/CPComparisonPredicate.j +++ b/Foundation/CPPredicate/CPComparisonPredicate.j @@ -22,142 +22,15 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPComparisonPredicate_Constants.j" + @import "CPArray.j" @import "CPEnumerator.j" -@import "CPExpression.j" @import "CPNull.j" -@import "_CPPredicate.j" @import "CPString.j" +@import "_CPExpression.j" +@import "_CPPredicate.j" -/*! - A predicate to directly compare the left and right hand sides. - @global - @class CPComparisonPredicate -*/ -CPDirectPredicateModifier = 0; -/*! - A predicate to compare all entries in the destination of a to-many relationship. - - The left hand side must be a collection. The corresponding predicate compares each value in the left hand side with the right hand side, and returns NO when it finds the first mismatch—or YES if all match. - @global - @class CPComparisonPredicate -*/ -CPAllPredicateModifier = 1; -/*! - A predicate to match with any entry in the destination of a to-many relationship. - - The left hand side must be a collection. The corresponding predicate compares each value in the left hand side against the right hand side and returns YES when it finds the first match—or NO if no match is found. - @global - @class CPComparisonPredicate -*/ -CPAnyPredicateModifier = 2; - -/*! - A case-insensitive predicate. - @global - @class CPComparisonPredicate -*/ -CPCaseInsensitivePredicateOption = 1; -/*! - A diacritic-insensitive predicate. - @global - @class CPComparisonPredicate -*/ -CPDiacriticInsensitivePredicateOption = 2; -CPDiacriticInsensitiveSearch = 128; - -/*! - A less-than predicate. - @global - @class CPComparisonPredicate -*/ -CPLessThanPredicateOperatorType = 0; -/*! - A less-than-or-equal-to predicate. - @global - @class CPComparisonPredicate -*/ -CPLessThanOrEqualToPredicateOperatorType = 1; -/*! - A greater-than predicate. - @global - @class CPComparisonPredicate -*/ -CPGreaterThanPredicateOperatorType = 2; -/*! - A greater-than-or-equal-to predicate. - @global - @class CPComparisonPredicate -*/ -CPGreaterThanOrEqualToPredicateOperatorType = 3; -/*! - An equal-to predicate. - @global - @class CPComparisonPredicate -*/ -CPEqualToPredicateOperatorType = 4; -/*! - A not-equal-to predicate. - @global - @class CPComparisonPredicate -*/ -CPNotEqualToPredicateOperatorType = 5; -/*! - A full regular expression matching predicate. - @global - @class CPComparisonPredicate -*/ -CPMatchesPredicateOperatorType = 6; -/*! - A simple subset of the matches predicate, similar in behavior to SQL LIKE. - @global - @class CPComparisonPredicate -*/ -CPLikePredicateOperatorType = 7; -/*! - A begins-with predicate. - @global - @class CPComparisonPredicate -*/ -CPBeginsWithPredicateOperatorType = 8; -/*! - An ends-with predicate. - @global - @class CPComparisonPredicate -*/ -CPEndsWithPredicateOperatorType = 9; -/*! - A predicate to determine if the left hand side is in the right hand side. - - For strings, returns YES if the left hand side is a substring of the right hand side. For collections, returns YES if the left hand side is in the right hand side. - @global - @class CPComparisonPredicate -*/ -CPInPredicateOperatorType = 10; -/*! - Predicate that uses a custom selector that takes a single argument and returns a BOOL value. - - The selector is invoked on the left hand side with the right hand side. - @global - @class CPComparisonPredicate -*/ -CPCustomSelectorPredicateOperatorType = 11; -/*! - A predicate to determine if the left hand side contains the right hand side. - - Returns YES if [lhs contains rhs]; the left hand side must be a CPExpression object that evaluates to a collection - @global - @class CPComparisonPredicate -*/ -CPContainsPredicateOperatorType = 99; -/*! - A predicate to determine if the right hand side lies between bounds specified by the left hand side. - - Returns YES if [lhs between rhs]; the right hand side must be an array in which the first element sets the lower bound and the second element the upper, inclusive. Comparison is performed using compare: or the class-appropriate equivalent. - @global - @class CPComparisonPredicate -*/ -CPBetweenPredicateOperatorType = 100; var CPComparisonPredicateModifier, CPPredicateOperatorType; diff --git a/Foundation/CPPredicate/CPComparisonPredicate_Constants.j b/Foundation/CPPredicate/CPComparisonPredicate_Constants.j new file mode 100644 index 000000000..8a0e5e1a1 --- /dev/null +++ b/Foundation/CPPredicate/CPComparisonPredicate_Constants.j @@ -0,0 +1,153 @@ +/* + * CPComparisonPredicate_Constants.j + * + * Portions based on NSComparisonPredicate.m in Cocotron (http://www.cocotron.org/) + * Copyright (c) 2006-2007 Christopher J. W. Lloyd + * + * Created by cacaodev. + * Copyright 2010. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/*! + A predicate to directly compare the left and right hand sides. + @global + @class CPComparisonPredicate +*/ +CPDirectPredicateModifier = 0; +/*! + A predicate to compare all entries in the destination of a to-many relationship. + + The left hand side must be a collection. The corresponding predicate compares each value in the left hand side with the right hand side, and returns NO when it finds the first mismatch—or YES if all match. + @global + @class CPComparisonPredicate +*/ +CPAllPredicateModifier = 1; +/*! + A predicate to match with any entry in the destination of a to-many relationship. + + The left hand side must be a collection. The corresponding predicate compares each value in the left hand side against the right hand side and returns YES when it finds the first match—or NO if no match is found. + @global + @class CPComparisonPredicate +*/ +CPAnyPredicateModifier = 2; + +/*! + A case-insensitive predicate. + @global + @class CPComparisonPredicate +*/ +CPCaseInsensitivePredicateOption = 1; +/*! + A diacritic-insensitive predicate. + @global + @class CPComparisonPredicate +*/ +CPDiacriticInsensitivePredicateOption = 2; +CPDiacriticInsensitiveSearch = 128; + +/*! + A less-than predicate. + @global + @class CPComparisonPredicate +*/ +CPLessThanPredicateOperatorType = 0; +/*! + A less-than-or-equal-to predicate. + @global + @class CPComparisonPredicate +*/ +CPLessThanOrEqualToPredicateOperatorType = 1; +/*! + A greater-than predicate. + @global + @class CPComparisonPredicate +*/ +CPGreaterThanPredicateOperatorType = 2; +/*! + A greater-than-or-equal-to predicate. + @global + @class CPComparisonPredicate +*/ +CPGreaterThanOrEqualToPredicateOperatorType = 3; +/*! + An equal-to predicate. + @global + @class CPComparisonPredicate +*/ +CPEqualToPredicateOperatorType = 4; +/*! + A not-equal-to predicate. + @global + @class CPComparisonPredicate +*/ +CPNotEqualToPredicateOperatorType = 5; +/*! + A full regular expression matching predicate. + @global + @class CPComparisonPredicate +*/ +CPMatchesPredicateOperatorType = 6; +/*! + A simple subset of the matches predicate, similar in behavior to SQL LIKE. + @global + @class CPComparisonPredicate +*/ +CPLikePredicateOperatorType = 7; +/*! + A begins-with predicate. + @global + @class CPComparisonPredicate +*/ +CPBeginsWithPredicateOperatorType = 8; +/*! + An ends-with predicate. + @global + @class CPComparisonPredicate +*/ +CPEndsWithPredicateOperatorType = 9; +/*! + A predicate to determine if the left hand side is in the right hand side. + + For strings, returns YES if the left hand side is a substring of the right hand side. For collections, returns YES if the left hand side is in the right hand side. + @global + @class CPComparisonPredicate +*/ +CPInPredicateOperatorType = 10; +/*! + Predicate that uses a custom selector that takes a single argument and returns a BOOL value. + + The selector is invoked on the left hand side with the right hand side. + @global + @class CPComparisonPredicate +*/ +CPCustomSelectorPredicateOperatorType = 11; +/*! + A predicate to determine if the left hand side contains the right hand side. + + Returns YES if [lhs contains rhs]; the left hand side must be a CPExpression object that evaluates to a collection + @global + @class CPComparisonPredicate +*/ +CPContainsPredicateOperatorType = 99; +/*! + A predicate to determine if the right hand side lies between bounds specified by the left hand side. + + Returns YES if [lhs between rhs]; the right hand side must be an array in which the first element sets the lower bound and the second element the upper, inclusive. Comparison is performed using compare: or the class-appropriate equivalent. + @global + @class CPComparisonPredicate +*/ +CPBetweenPredicateOperatorType = 100; diff --git a/Foundation/CPPredicate/CPCompoundPredicate.j b/Foundation/CPPredicate/CPCompoundPredicate.j index 97aabe002..8eaeb709f 100644 --- a/Foundation/CPPredicate/CPCompoundPredicate.j +++ b/Foundation/CPPredicate/CPCompoundPredicate.j @@ -22,28 +22,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ +@import "CPCompoundPredicate_Constants.j" @import "CPArray.j" @import "_CPPredicate.j" -/*! - A predicate to directly compare the left and right hand sides. - @global - @class CPCompoundPredicate -*/ -CPNotPredicateType = 0; -/*! - A predicate to directly compare the left and right hand sides. - @global - @class CPCompoundPredicate -*/ -CPAndPredicateType = 1; -/*! - A predicate to directly compare the left and right hand sides. - @global - @class CPCompoundPredicate -*/ -CPOrPredicateType = 2; - var CPCompoundPredicateType; /*! diff --git a/Foundation/CPPredicate/CPCompoundPredicate_Constants.j b/Foundation/CPPredicate/CPCompoundPredicate_Constants.j new file mode 100644 index 000000000..fc96b8071 --- /dev/null +++ b/Foundation/CPPredicate/CPCompoundPredicate_Constants.j @@ -0,0 +1,42 @@ +/* + * CPCompoundPredicate_h.j + * + * Portions based on NSCompoundPredicate.m in Cocotron (http://www.cocotron.org/) + * Copyright (c) 2006-2007 Christopher J. W. Lloyd + * + * Created by cacaodev. + * Copyright 2010. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +/*! + A predicate to directly compare the left and right hand sides. + @global + @class CPCompoundPredicate +*/ +CPNotPredicateType = 0; +/*! + A predicate to directly compare the left and right hand sides. + @global + @class CPCompoundPredicate +*/ +CPAndPredicateType = 1; +/*! + A predicate to directly compare the left and right hand sides. + @global + @class CPCompoundPredicate +*/ +CPOrPredicateType = 2; diff --git a/Foundation/CPPredicate/_CPAggregateExpression.j b/Foundation/CPPredicate/_CPAggregateExpression.j index 40214f895..b010881a7 100644 --- a/Foundation/CPPredicate/_CPAggregateExpression.j +++ b/Foundation/CPPredicate/_CPAggregateExpression.j @@ -20,8 +20,8 @@ */ @import "CPArray.j" -@import "CPExpression.j" @import "CPString.j" +@import "_CPExpression.j" @implementation _CPAggregateExpression : CPExpression { diff --git a/Foundation/CPPredicate/_CPConstantValueExpression.j b/Foundation/CPPredicate/_CPConstantValueExpression.j index e94f97d4d..5ffa9e07a 100644 --- a/Foundation/CPPredicate/_CPConstantValueExpression.j +++ b/Foundation/CPPredicate/_CPConstantValueExpression.j @@ -23,7 +23,7 @@ */ @import "CPDictionary.j" -@import "CPExpression.j" +@import "_CPExpression.j" @implementation _CPConstantValueExpression : CPExpression { diff --git a/Foundation/CPPredicate/_CPFunctionExpression.j b/Foundation/CPPredicate/_CPFunctionExpression.j index c3d07e77f..75b1619fc 100644 --- a/Foundation/CPPredicate/_CPFunctionExpression.j +++ b/Foundation/CPPredicate/_CPFunctionExpression.j @@ -23,8 +23,8 @@ @import "CPDate.j" @import "CPDictionary.j" @import "CPException.j" -@import "CPExpression.j" @import "CPString.j" +@import "_CPExpression.j" @implementation _CPFunctionExpression : CPExpression { diff --git a/Foundation/CPPredicate/_CPKeyPathExpression.j b/Foundation/CPPredicate/_CPKeyPathExpression.j index 53b1cfc2e..c0694b395 100644 --- a/Foundation/CPPredicate/_CPKeyPathExpression.j +++ b/Foundation/CPPredicate/_CPKeyPathExpression.j @@ -22,10 +22,10 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -@import "CPExpression.j" -@import "_CPFunctionExpression.j" @import "CPKeyValueCoding.j" @import "CPString.j" +@import "_CPExpression.j" +@import "_CPFunctionExpression.j" @import "_CPConstantValueExpression.j" @implementation _CPKeyPathExpression : _CPFunctionExpression diff --git a/Foundation/CPPredicate/_CPPredicate.j b/Foundation/CPPredicate/_CPPredicate.j index 2fc1392fe..5fd8ac967 100644 --- a/Foundation/CPPredicate/_CPPredicate.j +++ b/Foundation/CPPredicate/_CPPredicate.j @@ -30,32 +30,15 @@ @import "CPSet.j" @import "CPValue.j" @import "CPCharacterSet.j" +@import "CPComparisonPredicate_Constants.j" +@import "CPCompoundPredicate_Constants.j" +@import "_CPExpression.j" @class CPCompoundPredicate @class CPComparisonPredicate +@class _CPKeyPathExpression @class _CPSubqueryExpression -@global CPAndPredicateType -@global CPDirectPredicateModifier -@global CPAnyPredicateModifier -@global CPAllPredicateModifier -@global CPOrPredicateType -@global CPEqualToPredicateOperatorType -@global CPNotEqualToPredicateOperatorType -@global CPLessThanPredicateOperatorType -@global CPGreaterThanPredicateOperatorType -@global CPLessThanOrEqualToPredicateOperatorType -@global CPGreaterThanOrEqualToPredicateOperatorType -@global CPMatchesPredicateOperatorType -@global CPLikePredicateOperatorType -@global CPBeginsWithPredicateOperatorType -@global CPEndsWithPredicateOperatorType -@global CPInPredicateOperatorType -@global CPContainsPredicateOperatorType -@global CPBetweenPredicateOperatorType -@global CPCaseInsensitivePredicateOption -@global CPDiacriticInsensitivePredicateOption - /*! @ingroup foundation @@ -995,7 +978,3 @@ var CPRaiseParseError = function CPRaiseParseError(aScanner, target) { [CPException raise:CPInvalidArgumentException reason:@"unable to parse " + target + " at index " + [aScanner scanLocation]]; }; - -//@import "CPCompoundPredicate.j" -//@import "CPComparisonPredicate.j" -//@import "CPExpression.j" diff --git a/Foundation/CPPredicate/_CPSelfExpression.j b/Foundation/CPPredicate/_CPSelfExpression.j index 6dd2a62a5..e0bc57adc 100644 --- a/Foundation/CPPredicate/_CPSelfExpression.j +++ b/Foundation/CPPredicate/_CPSelfExpression.j @@ -20,8 +20,8 @@ */ @import "CPDictionary.j" -@import "CPExpression.j" @import "CPString.j" +@import "_CPExpression.j" var evaluatedObject = nil; diff --git a/Foundation/CPPredicate/_CPSetExpression.j b/Foundation/CPPredicate/_CPSetExpression.j index 35468c3f1..f7d4e673b 100644 --- a/Foundation/CPPredicate/_CPSetExpression.j +++ b/Foundation/CPPredicate/_CPSetExpression.j @@ -20,8 +20,8 @@ */ @import "CPException.j" -@import "CPExpression.j" @import "CPSet.j" +@import "_CPExpression.j" @implementation _CPSetExpression : CPExpression { diff --git a/Foundation/CPPredicate/_CPSubqueryExpression.j b/Foundation/CPPredicate/_CPSubqueryExpression.j index 5becdd1b3..d1b0fa31f 100644 --- a/Foundation/CPPredicate/_CPSubqueryExpression.j +++ b/Foundation/CPPredicate/_CPSubqueryExpression.j @@ -21,8 +21,8 @@ @import "CPArray.j" @import "CPDictionary.j" -@import "CPExpression.j" -@import "CPPredicate.j" +@import "_CPExpression.j" +@import "_CPPredicate.j" @implementation _CPSubqueryExpression : CPExpression { diff --git a/Foundation/CPPredicate/_CPVariableExpression.j b/Foundation/CPPredicate/_CPVariableExpression.j index 30e7b0e2e..c426d6c60 100644 --- a/Foundation/CPPredicate/_CPVariableExpression.j +++ b/Foundation/CPPredicate/_CPVariableExpression.j @@ -24,8 +24,8 @@ @import "CPDictionary.j" @import "CPException.j" -@import "CPExpression.j" @import "CPString.j" +@import "_CPExpression.j" @implementation _CPVariableExpression : CPExpression { diff --git a/Foundation/CPSet+KVO.j b/Foundation/CPSet+KVO.j index 6153cf5d1..2bc3560d0 100644 --- a/Foundation/CPSet+KVO.j +++ b/Foundation/CPSet+KVO.j @@ -23,6 +23,7 @@ @import "CPException.j" @import "CPObject.j" @import "CPMutableSet.j" +@import "CPNull.j" @import "_CPCollectionKVCOperators.j" @implementation CPObject (CPSetKVO) diff --git a/Foundation/CPString.j b/Foundation/CPString.j index 7983111dc..1dd8c1526 100644 --- a/Foundation/CPString.j +++ b/Foundation/CPString.j @@ -29,6 +29,7 @@ @import "CPValue.j" @class CPException +@class CPURL @global CPInvalidArgumentException @global CPRangeException