diff options
-rw-r--r-- | src/nodejs/main.js | 64 | ||||
-rw-r--r-- | src/nodejs/parse.js | 48 | ||||
-rw-r--r-- | src/nodejs/tests/urlToResObj.js | 4 |
3 files changed, 114 insertions, 2 deletions
diff --git a/src/nodejs/main.js b/src/nodejs/main.js index 4411081..1c01b78 100644 --- a/src/nodejs/main.js +++ b/src/nodejs/main.js @@ -80,6 +80,70 @@ function rowToWay(row){ // #################### MAY be put to different module later + +// #################### my little clutch replacments + + +var urlToXpathObj = function urlToXpathObj(url){ + + // FIXME: more validaiton + // filter stars in keys + // filter no enough arguments + + var parseKeyList = function(string){ + result = /(.+)(:?\|(.+))/.exec(string); + result.shift(); + return result; + } + + var parseBboxList = function(string){ + + result = /(.+)(:?,(.+)){3}/.exec(string): + + if(result.length != 4){ + throw "error"; + } + + result.shift(); + + return { + 'left' : result[0]; + 'bottom' : result[1]; + 'right' : result[2]; + 'top' : result[3]; + } + + var xp = {}; + + result = /\/(*|node|way|relation)(:?\[(.*)=(.*)\])*/.exec(url); + + xp.object=result[1]; + + for(i=2;i<=result.length();i++){ + if(result[i]==="bbox"){ + xp.bbox = parseBboxValues(result[i+1]); + } else { + xp.tag ={}; + xp.tag.keys = parseKeyList(result[i]); + xp.tag.values = parseKeyList(result[i+1]); + } + i++; + } +} + + + + + + + +// ################## end my little clutch replacments + + + + + + var options = [ { short : 'c', long : 'config', diff --git a/src/nodejs/parse.js b/src/nodejs/parse.js new file mode 100644 index 0000000..0338954 --- /dev/null +++ b/src/nodejs/parse.js @@ -0,0 +1,48 @@ +exports.urlToXpathObj = function urlToXpathObj(url){ + + // FIXMEresult.shift(): more validaiton + // filter stars in keys + // filter no enough arguments + + var parseKeyList = function(string){ + result = /(.+)(:?\|(.+))/.exec(string); + result.shift(); + return result; + } + + var parseBboxList = function(string){ + + result = /(.+)(:?,(.+)){3}/.exec(string); + + if(result.length != 4){ + throw "error"; + } + + result.shift(); + + return { + 'left' : result[0], + 'bottom' : result[1], + 'right' : result[2], + 'top' : result[3] + } + } + + var xp = {}; + + result = /\/(*|node|way|relation)(:?\[(.*)=(.*)\])*/.exec(url); + + xp.object=result[1]; + + for(i=2;i<=result.length;i++){ + if(result[i]==="bbox"){ + xp.bbox = parseBboxValues(result[i+1]); + } else { + xp.tag ={}; + xp.tag.keys = parseKeyList(result[i]); + xp.tag.values = parseKeyList(result[i+1]); + } + i++; + } +} + diff --git a/src/nodejs/tests/urlToResObj.js b/src/nodejs/tests/urlToResObj.js index 3740745..a29fb3f 100644 --- a/src/nodejs/tests/urlToResObj.js +++ b/src/nodejs/tests/urlToResObj.js @@ -1,7 +1,7 @@ var assert = require('assert'); -//var test = require(''); +var test = require('../parse.js'); //TODO function does not exist yet -var toTest = new function(id) { return id; }; +var toTest = test.urlToXpathObj; // test all simple objects { node, way, relation } |