Skip to content
This repository was archived by the owner on Feb 5, 2020. It is now read-only.

Commit d0f90ff

Browse files
committed
Abbreviate commonly used N3Util functions.
1 parent cd26443 commit d0f90ff

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/util/SparqlExpressionEvaluator.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ var XSD = 'http://www.w3.org/2001/XMLSchema#',
1313
var evaluators, operators,
1414
UnsupportedExpressionError, UnsupportedOperatorError, InvalidArgumentsNumberError;
1515

16+
var isLiteral = N3Util.isLiteral,
17+
literalValue = N3Util.getLiteralValue;
18+
1619
/**
1720
* Creates a function that evaluates the given SPARQL expression.
1821
* @constructor
@@ -87,11 +90,11 @@ evaluators = {
8790
// Convert the arguments if necessary
8891
switch (operator.type) {
8992
case 'numeric':
90-
args[i] = parseFloat(N3Util.getLiteralValue(arg));
93+
args[i] = parseFloat(literalValue(arg));
9194
break;
9295
case 'boolean':
9396
args[i] = arg !== XSD_FALSE &&
94-
(!N3Util.isLiteral(arg) || N3Util.getLiteralValue(arg) !== '0');
97+
(!isLiteral(arg) || literalValue(arg) !== '0');
9598
break;
9699
}
97100
}
@@ -136,17 +139,17 @@ operators = {
136139
return a.toLowerCase() === b.toLowerCase();
137140
},
138141
'contains': function (string, substring) {
139-
substring = N3Util.getLiteralValue(substring);
140-
string = N3Util.getLiteralValue(string);
142+
substring = literalValue(substring);
143+
string = literalValue(string);
141144
return string.indexOf(substring) >= 0;
142145
},
143146
'regex': function (subject, pattern) {
144-
if (N3Util.isLiteral(subject))
145-
subject = N3Util.getLiteralValue(subject);
146-
return new RegExp(N3Util.getLiteralValue(pattern)).test(subject);
147+
if (isLiteral(subject))
148+
subject = literalValue(subject);
149+
return new RegExp(literalValue(pattern)).test(subject);
147150
},
148151
'str': function (a) {
149-
return N3Util.isLiteral(a) ? a : '"' + a + '"';
152+
return isLiteral(a) ? a : '"' + a + '"';
150153
},
151154
'http://www.w3.org/2001/XMLSchema#integer': function (a) {
152155
return '"' + Math.floor(a) + '"^^http://www.w3.org/2001/XMLSchema#integer';

0 commit comments

Comments
 (0)