|
|
@@ -1,23 +1,15 @@
|
|
|
"use strict";
|
|
|
|
|
|
-var FieldRef = require('./FieldRef');
|
|
|
+var FieldRef = require('./FieldRef'),
|
|
|
+ ErrorCodes = require('../../Errors.js').ErrorCodes;
|
|
|
|
|
|
-// Autogenerated by cport.py on 2013-09-17 14:37
|
|
|
var ElementPath = module.exports = function ElementPath(){
|
|
|
this._fieldRef = new FieldRef();
|
|
|
this._shouldTraverseLeafArray = false;
|
|
|
}, klass = ElementPath, base = Object , proto = klass.prototype = Object.create(base.prototype, {constructor:{value:klass}});
|
|
|
|
|
|
-
|
|
|
-// File: path.h lines: 41-41
|
|
|
-// FieldRef _fieldRef;
|
|
|
-
|
|
|
proto._fieldRef = undefined;
|
|
|
|
|
|
-
|
|
|
-// File: path.h lines: 42-42
|
|
|
-// bool _shouldTraverseLeafArray;
|
|
|
-
|
|
|
proto._shouldTraverseLeafArray = undefined;
|
|
|
|
|
|
/**
|
|
|
@@ -29,7 +21,6 @@ proto._shouldTraverseLeafArray = undefined;
|
|
|
* @param idxPathObj This is an object with a pathID element. This allows for pass by ref in calling function.
|
|
|
* */
|
|
|
klass.getFieldDottedOrArray = function getFieldDottedOrArray(doc, path, idxPathObj){
|
|
|
- // File path_internal.cpp lines 31-72
|
|
|
if (path.numParts() === 0 ) { return doc; }
|
|
|
|
|
|
var res,curr = doc,
|
|
|
@@ -37,7 +28,7 @@ klass.getFieldDottedOrArray = function getFieldDottedOrArray(doc, path, idxPathO
|
|
|
partNum = 0;
|
|
|
while (partNum < path.numParts() && !stop) {
|
|
|
res = curr[path.getPart( partNum)];
|
|
|
- if(res == {}){
|
|
|
+ if(res instanceof Object && Object.keys(res).length === 0){
|
|
|
stop = true;
|
|
|
} else if (res instanceof Object) {
|
|
|
curr = res;
|
|
|
@@ -53,7 +44,7 @@ klass.getFieldDottedOrArray = function getFieldDottedOrArray(doc, path, idxPathO
|
|
|
|
|
|
}
|
|
|
|
|
|
- //idxPathObj.pathID = partNum;
|
|
|
+ idxPathObj.pathID = partNum;
|
|
|
return res;
|
|
|
};
|
|
|
|
|
|
@@ -65,7 +56,6 @@ klass.getFieldDottedOrArray = function getFieldDottedOrArray(doc, path, idxPathO
|
|
|
*/
|
|
|
|
|
|
klass.isAllDigits = function isAllDigits ( str ){
|
|
|
- // File path_internal.cpp lines 23-29
|
|
|
var digitCheck = /\D/g;
|
|
|
if (digitCheck.exec(str) === null){ return true; }
|
|
|
return false;
|
|
|
@@ -82,8 +72,7 @@ klass.isAllDigits = function isAllDigits ( str ){
|
|
|
* @param
|
|
|
*
|
|
|
*/
|
|
|
-proto.fieldRef = function fieldRef( /* */ ){
|
|
|
-// File: path.h lines: 37-36
|
|
|
+proto.fieldRef = function fieldRef(){
|
|
|
return this._fieldRef;
|
|
|
};
|
|
|
|
|
|
@@ -95,11 +84,10 @@ proto.fieldRef = function fieldRef( /* */ ){
|
|
|
* @param path
|
|
|
*
|
|
|
*/
|
|
|
-proto.init = function init( path ){ // const StringData& path
|
|
|
-// File: path.cpp lines: 26-29
|
|
|
+proto.init = function init( path ){
|
|
|
this._shouldTraverseLeafArray = true;
|
|
|
this._fieldRef.parse( path );
|
|
|
- return {'code':'OK'};
|
|
|
+ return {'code':ErrorCodes.OK};
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -110,8 +98,7 @@ proto.init = function init( path ){ // const StringData& path
|
|
|
* @param
|
|
|
*
|
|
|
*/
|
|
|
-proto.setTraverseLeafArray = function setTraverseLeafArray( b ){ // bool b
|
|
|
-// File: path.h lines: 35-34
|
|
|
+proto.setTraverseLeafArray = function setTraverseLeafArray( b ){
|
|
|
this._shouldTraverseLeafArray = b;
|
|
|
};
|
|
|
|
|
|
@@ -123,27 +110,27 @@ proto.setTraverseLeafArray = function setTraverseLeafArray( b ){ // bool b
|
|
|
* @param
|
|
|
*
|
|
|
*/
|
|
|
-proto.shouldTraverseLeafArray = function shouldTraverseLeafArray( /* */ ){
|
|
|
-// File: path.h lines: 38-37
|
|
|
+proto.shouldTraverseLeafArray = function shouldTraverseLeafArray( ){
|
|
|
return this._shouldTraverseLeafArray;
|
|
|
};
|
|
|
|
|
|
+
|
|
|
proto.objAtPath = function objAtPath(doc) {
|
|
|
return klass.objAtPath(doc, this._fieldRef._path);
|
|
|
};
|
|
|
|
|
|
klass.objAtPath = function objAtPath(doc, path) {
|
|
|
- if(path.length === 0) {
|
|
|
+ if (path.length === 0) {
|
|
|
return doc;
|
|
|
}
|
|
|
- if (path.length > 0 && Object.keys(doc).length === 0){
|
|
|
+ if (path.length > 0 && Object.keys(doc).length === 0) {
|
|
|
return {};
|
|
|
}
|
|
|
if (doc === null || doc === undefined) {
|
|
|
return doc;
|
|
|
}
|
|
|
var tpath = path.split('.');
|
|
|
- return klass.objAtPath(doc[tpath[0]],tpath.slice(1).join('.'));
|
|
|
+ return klass.objAtPath(doc[tpath[0]], tpath.slice(1).join('.'));
|
|
|
};
|
|
|
|
|
|
|
|
|
@@ -171,16 +158,16 @@ proto._matches = function _matches(doc, details, checker) {
|
|
|
* @param function checker this function is used to check for a valid item at the end of the path
|
|
|
*
|
|
|
*/
|
|
|
-klass._matches = function _matches(doc, path, shouldTraverseLeafArray, details, checker){
|
|
|
+klass._matches = function _matches(doc, path, shouldTraverseLeafArray, details, checker) {
|
|
|
// File: expression_array.cpp lines: 34-53
|
|
|
var k, result, ii, il,
|
|
|
curr = doc,
|
|
|
item = doc;
|
|
|
for (k = 0; k < path.length; k++) {
|
|
|
- if((curr instanceof Object) && (path[k] in curr)) {
|
|
|
+ if ((curr instanceof Object) && (path[k] in curr)) {
|
|
|
item = curr[path[k]];
|
|
|
}
|
|
|
- if(path[k].length === 0)
|
|
|
+ if (path[k].length === 0)
|
|
|
continue;
|
|
|
item = curr[path[k]];
|
|
|
if (item instanceof Object && item.constructor === Object) {
|
|
|
@@ -195,7 +182,7 @@ klass._matches = function _matches(doc, path, shouldTraverseLeafArray, details,
|
|
|
curr = item;
|
|
|
continue;
|
|
|
} else if (item instanceof Object && item.constructor === Array) {
|
|
|
- if (k == path.length-1) {
|
|
|
+ if (k == path.length - 1) {
|
|
|
if ((shouldTraverseLeafArray) && (isNaN(parseInt(path[k], 10)))) {
|
|
|
for (ii = 0, il = item.length; ii < il; ii++) {
|
|
|
result = checker(item[ii]);
|
|
|
@@ -205,20 +192,20 @@ klass._matches = function _matches(doc, path, shouldTraverseLeafArray, details,
|
|
|
return result;
|
|
|
}
|
|
|
}
|
|
|
- if(item.length === 0)
|
|
|
+ if (item.length === 0)
|
|
|
return checker({});
|
|
|
-
|
|
|
+
|
|
|
}
|
|
|
curr = item;
|
|
|
break; // this is the end of the path, so check this array
|
|
|
- } else if (!(isNaN(parseInt(path[k+1], 10)))) {
|
|
|
+ } else if (!(isNaN(parseInt(path[k + 1], 10)))) {
|
|
|
curr = item;
|
|
|
continue; // the *next* path section is an item in the array so we don't check this whole array
|
|
|
}
|
|
|
// otherwise, check each item in the array against the rest of the path
|
|
|
- for(ii = 0, il = item.length; ii < il; ii++){
|
|
|
+ for (ii = 0, il = item.length; ii < il; ii++) {
|
|
|
var subitem = item[ii];
|
|
|
- if (subitem.constructor !== Object) continue; // can't look for a subfield in a non-object value.
|
|
|
+ if (subitem.constructor !== Object) continue; // can't look for a subfield in a non-object value.
|
|
|
if (this._matches(subitem, path.slice(k), shouldTraverseLeafArray, null, checker)) { // check the item against the rest of the path
|
|
|
if (details && details.needRecord())
|
|
|
details.setElemMatchKey(ii.toString());
|