mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-12-04 03:44:58 +00:00
CPPredicate lint, import fixes, and some bug fixes
This commit is contained in:
1 parent
b70018bd80
commit
66b6b44f86
13 files changed
+547
-291
No files matched your search
@@ -1,17 +1,37 @@
|
||||
/*
|
||||
* CPComparisonPredicate.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPArray.j"
|
||||
@import "CPNull.j"
|
||||
@import "CPString.j"
|
||||
@import "CPEnumerator.j"
|
||||
@import "CPPredicate.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPNull.j"
|
||||
@import "CPPredicate.j"
|
||||
@import "CPString.j"
|
||||
|
||||
/*!
|
||||
A predicate to directly compare the left and right hand sides.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPDirectPredicateModifier = 0;
|
||||
CPDirectPredicateModifier = 0;
|
||||
/*!
|
||||
A predicate to compare all entries in the destination of a to-many relationship.
|
||||
|
||||
@@ -19,7 +39,7 @@ CPDirectPredicateModifier = 0;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPAllPredicateModifier = 1;
|
||||
CPAllPredicateModifier = 1;
|
||||
/*!
|
||||
A predicate to match with any entry in the destination of a to-many relationship.
|
||||
|
||||
@@ -27,28 +47,28 @@ CPAllPredicateModifier = 1;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPAnyPredicateModifier = 2;
|
||||
CPAnyPredicateModifier = 2;
|
||||
|
||||
/*!
|
||||
A case-insensitive predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPCaseInsensitivePredicateOption = 1;
|
||||
CPCaseInsensitivePredicateOption = 1;
|
||||
/*!
|
||||
A diacritic-insensitive predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPDiacriticInsensitivePredicateOption = 2;
|
||||
CPDiacriticInsensitiveSearch = 128;
|
||||
CPDiacriticInsensitivePredicateOption = 2;
|
||||
CPDiacriticInsensitiveSearch = 128;
|
||||
|
||||
/*!
|
||||
A less-than predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPLessThanPredicateOperatorType = 0;
|
||||
CPLessThanPredicateOperatorType = 0;
|
||||
/*!
|
||||
A less-than-or-equal-to predicate.
|
||||
@global
|
||||
@@ -60,7 +80,7 @@ CPLessThanOrEqualToPredicateOperatorType = 1;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPGreaterThanPredicateOperatorType = 2;
|
||||
CPGreaterThanPredicateOperatorType = 2;
|
||||
/*!
|
||||
A greater-than-or-equal-to predicate.
|
||||
@global
|
||||
@@ -72,37 +92,37 @@ CPGreaterThanOrEqualToPredicateOperatorType = 3;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPEqualToPredicateOperatorType = 4;
|
||||
CPEqualToPredicateOperatorType = 4;
|
||||
/*!
|
||||
A not-equal-to predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPNotEqualToPredicateOperatorType = 5;
|
||||
CPNotEqualToPredicateOperatorType = 5;
|
||||
/*!
|
||||
A full regular expression matching predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPMatchesPredicateOperatorType = 6;
|
||||
CPMatchesPredicateOperatorType = 6;
|
||||
/*!
|
||||
A simple subset of the matches predicate, similar in behavior to SQL LIKE.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPLikePredicateOperatorType = 7;
|
||||
CPLikePredicateOperatorType = 7;
|
||||
/*!
|
||||
A begins-with predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPBeginsWithPredicateOperatorType = 8;
|
||||
CPBeginsWithPredicateOperatorType = 8;
|
||||
/*!
|
||||
An ends-with predicate.
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPEndsWithPredicateOperatorType = 9;
|
||||
CPEndsWithPredicateOperatorType = 9;
|
||||
/*!
|
||||
A predicate to determine if the left hand side is in the right hand side.
|
||||
|
||||
@@ -110,7 +130,7 @@ CPEndsWithPredicateOperatorType = 9;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPInPredicateOperatorType = 10;
|
||||
CPInPredicateOperatorType = 10;
|
||||
/*!
|
||||
Predicate that uses a custom selector that takes a single argument and returns a BOOL value.
|
||||
|
||||
@@ -118,7 +138,7 @@ CPInPredicateOperatorType = 10;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPCustomSelectorPredicateOperatorType = 11;
|
||||
CPCustomSelectorPredicateOperatorType = 11;
|
||||
/*!
|
||||
A predicate to determine if the left hand side contains the right hand side.
|
||||
|
||||
@@ -126,7 +146,7 @@ CPCustomSelectorPredicateOperatorType = 11;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPContainsPredicateOperatorType = 99;
|
||||
CPContainsPredicateOperatorType = 99;
|
||||
/*!
|
||||
A predicate to determine if the right hand side lies between bounds specified by the left hand side.
|
||||
|
||||
@@ -134,7 +154,7 @@ CPContainsPredicateOperatorType = 99;
|
||||
@global
|
||||
@class CPComparisonPredicate
|
||||
*/
|
||||
CPBetweenPredicateOperatorType = 100;
|
||||
CPBetweenPredicateOperatorType = 100;
|
||||
|
||||
var CPComparisonPredicateModifier,
|
||||
CPPredicateOperatorType;
|
||||
@@ -193,12 +213,17 @@ var CPComparisonPredicateModifier,
|
||||
*/
|
||||
- (id)initWithLeftExpression:(CPExpression)left rightExpression:(CPExpression)right customSelector:(SEL)selector
|
||||
{
|
||||
_left = left;
|
||||
_right = right;
|
||||
_modifier = CPDirectPredicateModifier;
|
||||
_type = CPCustomSelectorPredicateOperatorType;
|
||||
_options = 0;
|
||||
_customSelector = selector;
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_left = left;
|
||||
_right = right;
|
||||
_modifier = CPDirectPredicateModifier;
|
||||
_type = CPCustomSelectorPredicateOperatorType;
|
||||
_options = 0;
|
||||
_customSelector = selector;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -214,18 +239,23 @@ var CPComparisonPredicateModifier,
|
||||
*/
|
||||
- (id)initWithLeftExpression:(CPExpression)left rightExpression:(CPExpression)right modifier:(CPComparisonPredicateModifier)modifier type:(CPPredicateOperatorType)type options:(unsigned)options
|
||||
{
|
||||
_left = left;
|
||||
_right = right;
|
||||
_modifier = modifier;
|
||||
_type = type;
|
||||
_options = (type != CPMatchesPredicateOperatorType &&
|
||||
type != CPLikePredicateOperatorType &&
|
||||
type != CPBeginsWithPredicateOperatorType &&
|
||||
type != CPEndsWithPredicateOperatorType &&
|
||||
type != CPInPredicateOperatorType &&
|
||||
type != CPContainsPredicateOperatorType) ? 0 : options;
|
||||
self = [super init];
|
||||
|
||||
_customSelector = NULL;
|
||||
if (self)
|
||||
{
|
||||
_left = left;
|
||||
_right = right;
|
||||
_modifier = modifier;
|
||||
_type = type;
|
||||
_options = (type != CPMatchesPredicateOperatorType &&
|
||||
type != CPLikePredicateOperatorType &&
|
||||
type != CPBeginsWithPredicateOperatorType &&
|
||||
type != CPEndsWithPredicateOperatorType &&
|
||||
type != CPInPredicateOperatorType &&
|
||||
type != CPContainsPredicateOperatorType) ? 0 : options;
|
||||
|
||||
_customSelector = NULL;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -292,81 +322,63 @@ var CPComparisonPredicateModifier,
|
||||
|
||||
switch (_modifier)
|
||||
{
|
||||
case CPDirectPredicateModifier:
|
||||
modifier = "";
|
||||
break;
|
||||
case CPAllPredicateModifier:
|
||||
modifier = "ALL ";
|
||||
break;
|
||||
case CPAnyPredicateModifier:
|
||||
modifier = "ANY ";
|
||||
break;
|
||||
default:
|
||||
modifier = "";
|
||||
break;
|
||||
case CPDirectPredicateModifier: modifier = "";
|
||||
break;
|
||||
case CPAllPredicateModifier: modifier = "ALL ";
|
||||
break;
|
||||
case CPAnyPredicateModifier: modifier = "ANY ";
|
||||
break;
|
||||
|
||||
default: modifier = "";
|
||||
break;
|
||||
}
|
||||
|
||||
var options;
|
||||
|
||||
switch (_options)
|
||||
{
|
||||
case CPCaseInsensitivePredicateOption:
|
||||
options = "[c]";
|
||||
break;
|
||||
case CPDiacriticInsensitivePredicateOption:
|
||||
options = "[d]";
|
||||
break;
|
||||
case CPCaseInsensitivePredicateOption: options = "[c]";
|
||||
break;
|
||||
case CPDiacriticInsensitivePredicateOption: options = "[d]";
|
||||
break;
|
||||
case CPCaseInsensitivePredicateOption | CPDiacriticInsensitivePredicateOption:
|
||||
options = "[cd]";
|
||||
break;
|
||||
default:
|
||||
options = "";
|
||||
break;
|
||||
options = "[cd]";
|
||||
break;
|
||||
|
||||
default: options = "";
|
||||
break;
|
||||
}
|
||||
|
||||
var operator;
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case CPLessThanPredicateOperatorType:
|
||||
operator = "<";
|
||||
break;
|
||||
case CPLessThanOrEqualToPredicateOperatorType:
|
||||
operator = "<=";
|
||||
break;
|
||||
case CPGreaterThanPredicateOperatorType:
|
||||
operator = ">";
|
||||
break;
|
||||
case CPGreaterThanOrEqualToPredicateOperatorType:
|
||||
operator = ">=";
|
||||
break;
|
||||
case CPEqualToPredicateOperatorType:
|
||||
operator = "==";
|
||||
break;
|
||||
case CPNotEqualToPredicateOperatorType:
|
||||
operator = "!=";
|
||||
break;
|
||||
case CPMatchesPredicateOperatorType:
|
||||
operator = "MATCHES";
|
||||
break;
|
||||
case CPLikePredicateOperatorType:
|
||||
operator = "LIKE";
|
||||
break;
|
||||
case CPBeginsWithPredicateOperatorType:
|
||||
operator = "BEGINSWITH";
|
||||
break;
|
||||
case CPEndsWithPredicateOperatorType:
|
||||
operator = "ENDSWITH";
|
||||
break;
|
||||
case CPInPredicateOperatorType:
|
||||
operator = "IN";
|
||||
break;
|
||||
case CPContainsPredicateOperatorType:
|
||||
operator = "CONTAINS";
|
||||
break;
|
||||
case CPCustomSelectorPredicateOperatorType:
|
||||
operator = CPStringFromSelector(_customSelector);
|
||||
break;
|
||||
case CPLessThanPredicateOperatorType: operator = "<";
|
||||
break;
|
||||
case CPLessThanOrEqualToPredicateOperatorType: operator = "<=";
|
||||
break;
|
||||
case CPGreaterThanPredicateOperatorType: operator = ">";
|
||||
break;
|
||||
case CPGreaterThanOrEqualToPredicateOperatorType: operator = ">=";
|
||||
break;
|
||||
case CPEqualToPredicateOperatorType: operator = "==";
|
||||
break;
|
||||
case CPNotEqualToPredicateOperatorType: operator = "!=";
|
||||
break;
|
||||
case CPMatchesPredicateOperatorType: operator = "MATCHES";
|
||||
break;
|
||||
case CPLikePredicateOperatorType: operator = "LIKE";
|
||||
break;
|
||||
case CPBeginsWithPredicateOperatorType: operator = "BEGINSWITH";
|
||||
break;
|
||||
case CPEndsWithPredicateOperatorType: operator = "ENDSWITH";
|
||||
break;
|
||||
case CPInPredicateOperatorType: operator = "IN";
|
||||
break;
|
||||
case CPContainsPredicateOperatorType: operator = "CONTAINS";
|
||||
break;
|
||||
case CPCustomSelectorPredicateOperatorType: operator = CPStringFromSelector(_customSelector);
|
||||
break;
|
||||
}
|
||||
|
||||
return [CPString stringWithFormat:@"%s%s %s%s %s",modifier,[_left description],operator,options,[_right description]];
|
||||
@@ -399,76 +411,66 @@ var CPComparisonPredicateModifier,
|
||||
// left and right should be casted first [CAST()] following 10.5 rules.
|
||||
switch (_type)
|
||||
{
|
||||
case CPLessThanPredicateOperatorType:
|
||||
return ([lhs compare:rhs] == CPOrderedAscending);
|
||||
case CPLessThanOrEqualToPredicateOperatorType:
|
||||
return ([lhs compare:rhs] != CPOrderedDescending);
|
||||
case CPGreaterThanPredicateOperatorType:
|
||||
return ([lhs compare:rhs] == CPOrderedDescending);
|
||||
case CPGreaterThanOrEqualToPredicateOperatorType:
|
||||
return ([lhs compare:rhs] != CPOrderedAscending);
|
||||
case CPEqualToPredicateOperatorType:
|
||||
return [lhs isEqual:rhs];
|
||||
case CPNotEqualToPredicateOperatorType:
|
||||
return (![lhs isEqual:rhs]);
|
||||
case CPMatchesPredicateOperatorType:
|
||||
var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g";
|
||||
if (_options & CPDiacriticInsensitivePredicateOption)
|
||||
{
|
||||
lhs = lhs.stripDiacritics();
|
||||
rhs = rhs.stripDiacritics();
|
||||
}
|
||||
case CPLessThanPredicateOperatorType: return ([lhs compare:rhs] == CPOrderedAscending);
|
||||
case CPLessThanOrEqualToPredicateOperatorType: return ([lhs compare:rhs] != CPOrderedDescending);
|
||||
case CPGreaterThanPredicateOperatorType: return ([lhs compare:rhs] == CPOrderedDescending);
|
||||
case CPGreaterThanOrEqualToPredicateOperatorType: return ([lhs compare:rhs] != CPOrderedAscending);
|
||||
case CPEqualToPredicateOperatorType: return [lhs isEqual:rhs];
|
||||
case CPNotEqualToPredicateOperatorType: return (![lhs isEqual:rhs]);
|
||||
|
||||
return (new RegExp(rhs,commut)).test(lhs);
|
||||
case CPLikePredicateOperatorType:
|
||||
if (_options & CPDiacriticInsensitivePredicateOption)
|
||||
{
|
||||
lhs = lhs.stripDiacritics();
|
||||
rhs = rhs.stripDiacritics();
|
||||
}
|
||||
var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g",
|
||||
reg = new RegExp(rhs.escapeForRegExp(),commut);
|
||||
return reg.test(lhs);
|
||||
case CPBeginsWithPredicateOperatorType:
|
||||
var range = CPMakeRange(0,[rhs length]);
|
||||
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
|
||||
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
|
||||
case CPMatchesPredicateOperatorType: var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g";
|
||||
if (_options & CPDiacriticInsensitivePredicateOption)
|
||||
{
|
||||
lhs = lhs.stripDiacritics();
|
||||
rhs = rhs.stripDiacritics();
|
||||
}
|
||||
return (new RegExp(rhs,commut)).test(lhs);
|
||||
|
||||
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);
|
||||
case CPEndsWithPredicateOperatorType:
|
||||
var range = CPMakeRange([lhs length] - [rhs length],[rhs length]);
|
||||
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
|
||||
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
|
||||
case CPLikePredicateOperatorType: if (_options & CPDiacriticInsensitivePredicateOption)
|
||||
{
|
||||
lhs = lhs.stripDiacritics();
|
||||
rhs = rhs.stripDiacritics();
|
||||
}
|
||||
var commut = (_options & CPCaseInsensitivePredicateOption) ? "gi":"g",
|
||||
reg = new RegExp(rhs.escapeForRegExp(),commut);
|
||||
return reg.test(lhs);
|
||||
|
||||
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);
|
||||
case CPCustomSelectorPredicateOperatorType:
|
||||
return [lhs performSelector:_customSelector withObject:rhs];
|
||||
case CPInPredicateOperatorType:
|
||||
var a = lhs; // swap
|
||||
lhs = rhs;
|
||||
rhs = a;
|
||||
case CPContainsPredicateOperatorType:
|
||||
if (![lhs isKindOfClass:[CPString class]])
|
||||
{
|
||||
if (![lhs respondsToSelector: @selector(objectEnumerator)])
|
||||
[CPException raise:CPInvalidArgumentException reason:@"The left/right hand side for a CONTAINS/IN operator must be a collection or a string"];
|
||||
case CPBeginsWithPredicateOperatorType: var range = CPMakeRange(0,[rhs length]);
|
||||
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
|
||||
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
|
||||
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);
|
||||
|
||||
return [lhs containsObject:rhs];
|
||||
}
|
||||
case CPEndsWithPredicateOperatorType: var range = CPMakeRange([lhs length] - [rhs length],[rhs length]);
|
||||
if (_options & CPCaseInsensitivePredicateOption) string_compare_options |= CPCaseInsensitiveSearch;
|
||||
if (_options & CPDiacriticInsensitivePredicateOption) string_compare_options |= CPDiacriticInsensitiveSearch;
|
||||
return ([lhs compare:rhs options:string_compare_options range:range] == CPOrderedSame);
|
||||
|
||||
if (_options & CPCaseInsensitivePredicateOption)
|
||||
string_compare_options |= CPCaseInsensitiveSearch;
|
||||
if (_options & CPDiacriticInsensitivePredicateOption)
|
||||
string_compare_options |= CPDiacriticInsensitiveSearch;
|
||||
case CPCustomSelectorPredicateOperatorType: return [lhs performSelector:_customSelector withObject:rhs];
|
||||
|
||||
return ([lhs rangeOfString:rhs options:string_compare_options].location != CPNotFound);
|
||||
case CPBetweenPredicateOperatorType:
|
||||
if ([rhs count] < 2)
|
||||
[CPException raise:CPInvalidArgumentException reason:@"The right hand side for a BETWEEN operator must contain 2 objects"];
|
||||
case CPInPredicateOperatorType: var a = lhs; // swap
|
||||
lhs = rhs;
|
||||
rhs = a;
|
||||
case CPContainsPredicateOperatorType: if (![lhs isKindOfClass:[CPString class]])
|
||||
{
|
||||
if (![lhs respondsToSelector: @selector(objectEnumerator)])
|
||||
[CPException raise:CPInvalidArgumentException reason:@"The left/right hand side for a CONTAINS/IN operator must be a collection or a string"];
|
||||
|
||||
return ([lhs compare:rhs[0]] == CPOrderedDescending && [lhs compare:rhs[1]] == CPOrderedAscending);
|
||||
default:
|
||||
return NO;
|
||||
return [lhs containsObject:rhs];
|
||||
}
|
||||
|
||||
if (_options & CPCaseInsensitivePredicateOption)
|
||||
string_compare_options |= CPCaseInsensitiveSearch;
|
||||
if (_options & CPDiacriticInsensitivePredicateOption)
|
||||
string_compare_options |= CPDiacriticInsensitiveSearch;
|
||||
|
||||
return ([lhs rangeOfString:rhs options:string_compare_options].location != CPNotFound);
|
||||
|
||||
case CPBetweenPredicateOperatorType: if ([rhs count] < 2)
|
||||
[CPException raise:CPInvalidArgumentException reason:@"The right hand side for a BETWEEN operator must contain 2 objects"];
|
||||
|
||||
return ([lhs compare:rhs[0]] == CPOrderedDescending && [lhs compare:rhs[1]] == CPOrderedAscending);
|
||||
|
||||
default: return NO;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -541,8 +543,10 @@ var source = ['*','?','(',')','{','}','.','+','|','/','$','^'],
|
||||
|
||||
String.prototype.escapeForRegExp = function()
|
||||
{
|
||||
var foundChar = false;
|
||||
for (var i = 0; i < source.length; ++i)
|
||||
var foundChar = false,
|
||||
i = 0;
|
||||
|
||||
for (; i < source.length; ++i)
|
||||
{
|
||||
if (this.indexOf(source[i]) !== -1)
|
||||
{
|
||||
@@ -554,9 +558,9 @@ String.prototype.escapeForRegExp = function()
|
||||
if (!foundChar)
|
||||
return this;
|
||||
|
||||
var result = "",
|
||||
sourceIndex;
|
||||
for (var i = 0; i < this.length; ++i)
|
||||
var result = "";
|
||||
|
||||
for (i = 0; i < this.length; ++i)
|
||||
{
|
||||
var sourceIndex = source.indexOf(this.charAt(i));
|
||||
if (sourceIndex !== -1)
|
||||
|
||||
@@ -1,4 +1,25 @@
|
||||
/*
|
||||
* CPCompoundPredicate.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPArray.j"
|
||||
@import "CPPredicate.j"
|
||||
|
||||
/*!
|
||||
@@ -45,8 +66,13 @@ var CPCompoundPredicateType;
|
||||
*/
|
||||
- (id)initWithType:(CPCompoundPredicateType)type subpredicates:(CPArray)predicates
|
||||
{
|
||||
_type = type;
|
||||
_predicates = predicates;
|
||||
self = [super init];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_type = type;
|
||||
_predicates = predicates;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -103,10 +129,10 @@ var CPCompoundPredicateType;
|
||||
- (CPPredicate)predicateWithSubstitutionVariables:(CPDictionary)variables
|
||||
{
|
||||
var subp = [CPArray array],
|
||||
count = [subp count];
|
||||
i;
|
||||
count = [subp count],
|
||||
i = 0;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var p = [subp objectAtIndex:i],
|
||||
sp = [p predicateWithSubstitutionVariables:variables];
|
||||
@@ -122,12 +148,12 @@ var CPCompoundPredicateType;
|
||||
var result = "",
|
||||
args = [CPArray array],
|
||||
count = [_predicates count],
|
||||
i;
|
||||
i = 0;
|
||||
|
||||
if (count == 0)
|
||||
return @"TRUPREDICATE";
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var subpredicate = [_predicates objectAtIndex:i],
|
||||
precedence = [subpredicate predicateFormat];
|
||||
@@ -141,21 +167,20 @@ var CPCompoundPredicateType;
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case CPNotPredicateType:
|
||||
result += "NOT %s" + [args objectAtIndex:0];
|
||||
break;
|
||||
case CPAndPredicateType:
|
||||
result += [args objectAtIndex:0];
|
||||
var count = [args count];
|
||||
for (var j = 1; j < count; j++)
|
||||
result += " AND " + [args objectAtIndex:j];
|
||||
break;
|
||||
case CPOrPredicateType:
|
||||
result += [args objectAtIndex:0];
|
||||
var count = [args count];
|
||||
for (var j = 1; j < count; j++)
|
||||
result += " OR " + [args objectAtIndex:j];
|
||||
break;
|
||||
case CPNotPredicateType: result += "NOT %s" + [args objectAtIndex:0];
|
||||
break;
|
||||
|
||||
case CPAndPredicateType: result += [args objectAtIndex:0];
|
||||
var count = [args count];
|
||||
for (var j = 1; j < count; j++)
|
||||
result += " AND " + [args objectAtIndex:j];
|
||||
break;
|
||||
|
||||
case CPOrPredicateType: result += [args objectAtIndex:0];
|
||||
var count = [args count];
|
||||
for (var j = 1; j < count; j++)
|
||||
result += " OR " + [args objectAtIndex:j];
|
||||
break;
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -170,31 +195,30 @@ var CPCompoundPredicateType;
|
||||
{
|
||||
var result = NO,
|
||||
count = [_predicates count],
|
||||
i;
|
||||
i = 0;
|
||||
|
||||
if (count == 0)
|
||||
return YES;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var predicate = [_predicates objectAtIndex:i];
|
||||
|
||||
switch (_type)
|
||||
{
|
||||
case CPNotPredicateType:
|
||||
return ![predicate evaluateWithObject:object substitutionVariables:variables];
|
||||
case CPAndPredicateType:
|
||||
if (i == 0)
|
||||
result = [predicate evaluateWithObject:object substitutionVariables:variables];
|
||||
else
|
||||
result = result && [predicate evaluateWithObject:object substitutionVariables:variables];
|
||||
if (!result)
|
||||
return NO;
|
||||
break;
|
||||
case CPOrPredicateType:
|
||||
if ([predicate evaluateWithObject:object substitutionVariables:variables])
|
||||
return YES;
|
||||
break;
|
||||
case CPNotPredicateType: return ![predicate evaluateWithObject:object substitutionVariables:variables];
|
||||
|
||||
case CPAndPredicateType: if (i == 0)
|
||||
result = [predicate evaluateWithObject:object substitutionVariables:variables];
|
||||
else
|
||||
result = result && [predicate evaluateWithObject:object substitutionVariables:variables];
|
||||
if (!result)
|
||||
return NO;
|
||||
break;
|
||||
|
||||
case CPOrPredicateType: if ([predicate evaluateWithObject:object substitutionVariables:variables])
|
||||
return YES;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,34 @@
|
||||
/*
|
||||
* CPExpression.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPString.j"
|
||||
@import "CPArray.j"
|
||||
@import "CPKeyValueCoding.j"
|
||||
@import "CPDictionary.j"
|
||||
@import "CPKeyValueCoding.j"
|
||||
@import "CPObject.j"
|
||||
@import "CPString.j"
|
||||
|
||||
/*!
|
||||
An expression that always returns the same value.
|
||||
*/
|
||||
CPConstantValueExpressionType = 0;
|
||||
CPConstantValueExpressionType = 0;
|
||||
/*!
|
||||
An expression that always returns the parameter object itself.
|
||||
*/
|
||||
@@ -15,35 +36,35 @@ CPEvaluatedObjectExpressionType = 1;
|
||||
/*!
|
||||
An expression that always returns whatever value is associated with the key specified by ‘variable’ in the bindings dictionary.
|
||||
*/
|
||||
CPVariableExpressionType = 2;
|
||||
CPVariableExpressionType = 2;
|
||||
/*!
|
||||
An expression that returns something that can be used as a key path.
|
||||
*/
|
||||
CPKeyPathExpressionType = 3;
|
||||
CPKeyPathExpressionType = 3;
|
||||
/*!
|
||||
An expression that returns the result of evaluating a function.
|
||||
*/
|
||||
CPFunctionExpressionType = 4;
|
||||
CPFunctionExpressionType = 4;
|
||||
/*!
|
||||
An expression that defines an aggregate of CPExpression objects.
|
||||
*/
|
||||
CPAggregateExpressionType = 5;
|
||||
CPAggregateExpressionType = 5;
|
||||
/*!
|
||||
An expression that filters a collection using a subpredicate.
|
||||
*/
|
||||
CPSubqueryExpressionType = 6;
|
||||
CPSubqueryExpressionType = 6;
|
||||
/*!
|
||||
An expression that creates a union of the results of two nested expressions.
|
||||
*/
|
||||
CPUnionSetExpressionType = 7;
|
||||
CPUnionSetExpressionType = 7;
|
||||
/*!
|
||||
An expression that creates an intersection of the results of two nested expressions.
|
||||
*/
|
||||
CPIntersectSetExpressionType = 8;
|
||||
CPIntersectSetExpressionType = 8;
|
||||
/*!
|
||||
An expression that combines two nested expression results by set subtraction.
|
||||
*/
|
||||
CPMinusSetExpressionType = 9;
|
||||
CPMinusSetExpressionType = 9;
|
||||
|
||||
/*!
|
||||
@ingroup foundation
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
/*
|
||||
* CPExpression_aggregate.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPExpression.j"
|
||||
@import "CPArray.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
|
||||
@implementation CPExpression_aggregate : CPExpression
|
||||
@@ -10,8 +30,10 @@
|
||||
|
||||
- (id)initWithAggregate:(CPArray)collection
|
||||
{
|
||||
[super initWithExpressionType:CPAggregateExpressionType];
|
||||
_aggregate = collection;
|
||||
self = [super initWithExpressionType:CPAggregateExpressionType];
|
||||
|
||||
if (self)
|
||||
_aggregate = collection;
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -48,11 +70,11 @@
|
||||
|
||||
- (CPString)description
|
||||
{
|
||||
var i,
|
||||
var i = 0,
|
||||
count = [_aggregate count],
|
||||
result = "{";
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
result = result + [CPString stringWithFormat:@"%s%s", [[_aggregate objectAtIndex:i] description], (i + 1 < count) ? @", " : @""];
|
||||
|
||||
result = result + "}";
|
||||
@@ -64,9 +86,9 @@
|
||||
{
|
||||
var subst_array = [CPArray array],
|
||||
count = [_aggregate count],
|
||||
i;
|
||||
i = 0;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
[subst_array addObject:[[_aggregate objectAtIndex:i] _expressionWithSubstitutionVariables:variables]];
|
||||
|
||||
return [CPExpression expressionForAggregate:subst_array];
|
||||
|
||||
@@ -1,6 +1,26 @@
|
||||
/*
|
||||
* CPExpression_constant.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPExpression.j"
|
||||
@import "CPDictionary.j"
|
||||
@import "CPExpression.j"
|
||||
|
||||
@implementation CPExpression_constant : CPExpression
|
||||
{
|
||||
@@ -9,8 +29,10 @@
|
||||
|
||||
- (id)initWithValue:(id)value
|
||||
{
|
||||
[super initWithExpressionType:CPConstantValueExpressionType];
|
||||
_value = value;
|
||||
self = [super initWithExpressionType:CPConstantValueExpressionType];
|
||||
|
||||
if (self)
|
||||
_value = value;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,30 @@
|
||||
/*
|
||||
* CPExpression_function.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPArray.j"
|
||||
@import "CPDate.j"
|
||||
@import "CPDictionary.j"
|
||||
@import "CPException.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
@import "CPArray.j"
|
||||
@import "CPDictionary.j"
|
||||
|
||||
@implementation CPExpression_function : CPExpression
|
||||
{
|
||||
@@ -30,16 +52,18 @@
|
||||
|
||||
- (id)initWithTarget:(CPExpression)operand selector:(SEL)aSelector arguments:(CPArray)parameters type:(int)type
|
||||
{
|
||||
[super initWithExpressionType:type];
|
||||
|
||||
// Cocoa doc: "This method throws an exception immediately if the selector is unknown"
|
||||
// but operand's value (the target) may be resolved only at runtime.
|
||||
_selector = aSelector;
|
||||
_operand = operand;
|
||||
_arguments = parameters;
|
||||
_argc = [parameters count];
|
||||
_maxargs = [[CPStringFromSelector(_selector) componentsSeparatedByString:@":"] count] - 1;
|
||||
self = [super initWithExpressionType:type];
|
||||
|
||||
if (self)
|
||||
{
|
||||
// Cocoa doc: "This method throws an exception immediately if the selector is unknown"
|
||||
// but operand's value (the target) may be resolved only at runtime.
|
||||
_selector = aSelector;
|
||||
_operand = operand;
|
||||
_arguments = parameters;
|
||||
_argc = [parameters count];
|
||||
_maxargs = [[CPStringFromSelector(_selector) componentsSeparatedByString:@":"] count] - 1;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -78,9 +102,9 @@
|
||||
{
|
||||
var target = [_operand expressionValueWithObject:object context:context],
|
||||
objj_args = [target, _selector],
|
||||
i;
|
||||
i = 0;
|
||||
|
||||
for (i = 0; i < _argc; i++)
|
||||
for (; i < _argc; i++)
|
||||
{
|
||||
var arg = [_arguments[i] expressionValueWithObject:object context:context];
|
||||
objj_args.push(arg);
|
||||
@@ -119,9 +143,10 @@
|
||||
- (CPExpression)_expressionWithSubstitutionVariables:(CPDictionary)variables
|
||||
{
|
||||
var operand = [[self operand] _expressionWithSubstitutionVariables:variables],
|
||||
args = [CPArray array];
|
||||
args = [CPArray array],
|
||||
i = 0;
|
||||
|
||||
for (var i = 0; i < _argc; i++)
|
||||
for (; i < _argc; i++)
|
||||
[args addObject:[_arguments[i] _expressionWithSubstitutionVariables:variables]];
|
||||
|
||||
return [CPExpression expressionForFunction:operand selectorName:[self _function] arguments:args];
|
||||
@@ -129,9 +154,9 @@
|
||||
|
||||
@end
|
||||
|
||||
var CPSelectorNameKey = @"CPSelectorName",
|
||||
CPArgumentsKey = @"CPArguments",
|
||||
CPOperandKey = @"CPOperand",
|
||||
var CPSelectorNameKey = @"CPSelectorName",
|
||||
CPArgumentsKey = @"CPArguments",
|
||||
CPOperandKey = @"CPOperand",
|
||||
CPExpressionTypeKey = @"CPExpressionType";
|
||||
|
||||
@implementation CPExpression_function (CPCoding)
|
||||
@@ -283,4 +308,3 @@ var CPSelectorNameKey = @"CPSelectorName",
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@@ -1,8 +1,28 @@
|
||||
/*
|
||||
* CPExpression_keypath.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPExpression.j"
|
||||
@import "CPExpression_function.j"
|
||||
@import "CPString.j"
|
||||
@import "CPKeyValueCoding.j"
|
||||
@import "CPString.j"
|
||||
|
||||
@implementation CPExpression_keypath : CPExpression_function
|
||||
{
|
||||
|
||||
@@ -1,9 +1,30 @@
|
||||
/*
|
||||
* CPExpression_self.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPDictionary.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
@import "CPDictionary.j"
|
||||
|
||||
var evaluatedObject = nil;
|
||||
|
||||
@implementation CPExpression_self : CPExpression
|
||||
{
|
||||
}
|
||||
@@ -18,7 +39,7 @@ var evaluatedObject = nil;
|
||||
|
||||
- (id)init
|
||||
{
|
||||
[super initWithExpressionType:CPEvaluatedObjectExpressionType];
|
||||
self = [super initWithExpressionType:CPEvaluatedObjectExpressionType];
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,27 @@
|
||||
/*
|
||||
* CPExpression_set.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPException.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPSet.j"
|
||||
|
||||
@implementation CPExpression_set : CPExpression
|
||||
{
|
||||
@@ -9,9 +31,13 @@
|
||||
|
||||
- (id)initWithType:(int)type left:(CPExpression)left right:(CPExpression)right
|
||||
{
|
||||
[super initWithExpressionType:type];
|
||||
_left = left;
|
||||
_right = right;
|
||||
self = [super initWithExpressionType:type];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_left = left;
|
||||
_right = right;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
@@ -45,11 +71,11 @@
|
||||
switch (_type)
|
||||
{
|
||||
case CPIntersectSetExpressionType : [result intersectSet:right];
|
||||
break;
|
||||
break;
|
||||
case CPUnionSetExpressionType : [result unionSet:right];
|
||||
break;
|
||||
break;
|
||||
case CPMinusSetExpressionType : [result minusSet:right];
|
||||
break;
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -78,11 +104,11 @@
|
||||
switch (_type)
|
||||
{
|
||||
case CPIntersectSetExpressionType : desc = @" INTERSECT ";
|
||||
break;
|
||||
case CPUnionSetExpressionType : desc = @" UNION ";
|
||||
break;
|
||||
case CPMinusSetExpressionType : desc = @" MINUS ";
|
||||
break;
|
||||
break;
|
||||
case CPUnionSetExpressionType : desc = @" UNION ";
|
||||
break;
|
||||
case CPMinusSetExpressionType : desc = @" MINUS ";
|
||||
break;
|
||||
default:
|
||||
}
|
||||
|
||||
@@ -91,9 +117,9 @@
|
||||
|
||||
@end
|
||||
|
||||
var CPLeftExpressionKey = @"CPLeftExpression",
|
||||
CPRightExpressionKey = @"CPRightExpression",
|
||||
CPExpressionType = @"CPExpressionType";
|
||||
var CPLeftExpressionKey = @"CPLeftExpression",
|
||||
CPRightExpressionKey = @"CPRightExpression",
|
||||
CPExpressionType = @"CPExpressionType";
|
||||
|
||||
@implementation CPExpression_set (CPCoding)
|
||||
|
||||
|
||||
@@ -1,5 +1,28 @@
|
||||
/*
|
||||
* CPExpression_subquery.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPArray.j"
|
||||
@import "CPDictionary.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPPredicate.j"
|
||||
|
||||
@implementation CPExpression_subquery : CPExpression
|
||||
{
|
||||
@@ -16,12 +39,14 @@
|
||||
|
||||
- (id)initWithExpression:(CPExpression)collection usingIteratorExpression:(CPExpression)variableExpression predicate:(CPPredicate)subpredicate
|
||||
{
|
||||
[super initWithExpressionType:CPSubqueryExpressionType];
|
||||
|
||||
_subpredicate = subpredicate;
|
||||
_collection = collection;
|
||||
_variableExpression = variableExpression;
|
||||
self = [super initWithExpressionType:CPSubqueryExpressionType];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_subpredicate = subpredicate;
|
||||
_collection = collection;
|
||||
_variableExpression = variableExpression;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@@ -30,10 +55,10 @@
|
||||
var collection = [_collection expressionValueWithObject:object context:context],
|
||||
count = [collection count],
|
||||
result = [CPArray array],
|
||||
bindings = [CPDictionary dictionaryWithObject:[CPExpression expressionForEvaluatedObject] forKey:[self variable]],
|
||||
i = 0;
|
||||
|
||||
bindings = [CPDictionary dictionaryWithObject:[CPExpression expressionForEvaluatedObject] forKey:[self variable]];
|
||||
|
||||
for (var i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var item = [collection objectAtIndex:i];
|
||||
if ([_subpredicate evaluateWithObject:item substitutionVariables:bindings])
|
||||
@@ -90,9 +115,9 @@
|
||||
}
|
||||
@end
|
||||
|
||||
var CPExpressionKey = @"CPExpression",
|
||||
CPSubpredicateKey = @"CPSubpredicate",
|
||||
CPVariableKey = @"CPVariable";
|
||||
var CPExpressionKey = @"CPExpression",
|
||||
CPSubpredicateKey = @"CPSubpredicate",
|
||||
CPVariableKey = @"CPVariable";
|
||||
|
||||
@implementation CPExpression_subquery (CPCoding)
|
||||
|
||||
|
||||
@@ -1,7 +1,28 @@
|
||||
/*
|
||||
* CPExpression_variable.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPDictionary.j"
|
||||
@import "CPException.j"
|
||||
@import "CPExpression.j"
|
||||
@import "CPString.j"
|
||||
@import "CPDictionary.j"
|
||||
|
||||
@implementation CPExpression_variable : CPExpression
|
||||
{
|
||||
@@ -10,9 +31,12 @@
|
||||
|
||||
- (id)initWithVariable:(CPString)variable
|
||||
{
|
||||
[super initWithExpressionType:CPVariableExpressionType];
|
||||
_variable = [variable copy];
|
||||
self = [super initWithExpressionType:CPVariableExpressionType];
|
||||
|
||||
if (self)
|
||||
{
|
||||
_variable = [variable copy];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,32 @@
|
||||
/*
|
||||
* CPPredicate.j
|
||||
* Foundation
|
||||
*
|
||||
* Copyright 2009, 280 North, Inc.
|
||||
*
|
||||
* 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
|
||||
*/
|
||||
|
||||
@import "CPValue.j"
|
||||
@import "CPArray.j"
|
||||
@import "CPSet.j"
|
||||
@import "CPException.j"
|
||||
@import "CPNull.j"
|
||||
@import "CPObject.j"
|
||||
@import "CPScanner.j"
|
||||
@import "CPSet.j"
|
||||
@import "CPValue.j"
|
||||
@import "CPCharacterSet.j"
|
||||
|
||||
/*!
|
||||
@ingroup foundation
|
||||
@@ -164,9 +187,9 @@
|
||||
{
|
||||
var count = [self count],
|
||||
result = [CPArray array],
|
||||
i;
|
||||
i = 0;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var object = self[i];
|
||||
if ([predicate evaluateWithObject:object])
|
||||
@@ -195,9 +218,9 @@
|
||||
{
|
||||
var count = [self count],
|
||||
result = [CPSet set],
|
||||
i;
|
||||
i = 0;
|
||||
|
||||
for (i = 0; i < count; i++)
|
||||
for (; i < count; i++)
|
||||
{
|
||||
var object = [self objectAtIndex:i];
|
||||
|
||||
@@ -240,8 +263,9 @@ function(newValue)\
|
||||
|
||||
- (id)initWithString:(CPString)format args:(CPArray)args
|
||||
{
|
||||
self = [super initWithString:format];
|
||||
if (self != nil)
|
||||
self = [super initWithString:format]
|
||||
|
||||
if (self)
|
||||
{
|
||||
_args = [args objectEnumerator];
|
||||
}
|
||||
@@ -255,8 +279,7 @@ function(newValue)\
|
||||
|
||||
- (BOOL)scanPredicateKeyword:(CPString)key
|
||||
{
|
||||
var loc = [self scanLocation],
|
||||
c;
|
||||
var loc = [self scanLocation];
|
||||
|
||||
[self setCaseSensitive:NO];
|
||||
if (![self scanString:key intoString:NULL])
|
||||
@@ -265,7 +288,7 @@ function(newValue)\
|
||||
if ([self isAtEnd])
|
||||
return YES;
|
||||
|
||||
c = [[self string] characterAtIndex:[self scanLocation]];
|
||||
var c = [[self string] characterAtIndex:[self scanLocation]];
|
||||
if (![[CPCharacterSet alphanumericCharacterSet] characterIsMember:c])
|
||||
return YES;
|
||||
|
||||
@@ -285,7 +308,7 @@ function(newValue)\
|
||||
}
|
||||
catch(error)
|
||||
{
|
||||
CPLogConsole(@"Unable to parse predicate '"+[self string]+"' with " + error);
|
||||
CPLogConsole(@"Unable to parse predicate '" + [self string] + "' with " + error);
|
||||
}
|
||||
finally
|
||||
{
|
||||
|
||||
@@ -320,7 +320,7 @@
|
||||
|
||||
if (f)
|
||||
{
|
||||
var pos = current,
|
||||
var pos = current,
|
||||
foundDash = NO;
|
||||
/*
|
||||
var decimalSeparatorString;
|
||||
@@ -367,7 +367,7 @@
|
||||
|
||||
if (i)
|
||||
{
|
||||
var pos = current,
|
||||
var pos = current,
|
||||
foundDash = NO;
|
||||
|
||||
for (; pos < current + str.length; pos++)
|
||||
|
||||
Reference in new issue
Block a user