aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorslomo <steve.harrison@gmx.net>2011-01-28 19:59:57 +0100
committerslomo <steve.harrison@gmx.net>2011-01-28 19:59:57 +0100
commit19a62867dda0885453c639e0efefd450721cfa72 (patch)
treef9db70ef688246dddff2c7189249c6b59e0344aa /src
parenta5f78c6428089f756c45c7cb4101070af38e367a (diff)
downloadosm-xapi-19a62867dda0885453c639e0efefd450721cfa72.tar.gz
osm-xapi-19a62867dda0885453c639e0efefd450721cfa72.tar.xz
osm-xapi-19a62867dda0885453c639e0efefd450721cfa72.zip
parsing first try
Diffstat (limited to 'src')
-rw-r--r--src/nodejs/parse.js30
-rw-r--r--src/nodejs/tests/urlToResObj.js63
2 files changed, 84 insertions, 9 deletions
diff --git a/src/nodejs/parse.js b/src/nodejs/parse.js
index 0338954..932f91f 100644
--- a/src/nodejs/parse.js
+++ b/src/nodejs/parse.js
@@ -5,14 +5,20 @@ exports.urlToXpathObj = function urlToXpathObj(url){
// filter no enough arguments
var parseKeyList = function(string){
- result = /(.+)(:?\|(.+))/.exec(string);
+
+ console.log("input f1: " + string);
+ result = /([^\|]*)/g.exec(string);
+ console.log(result);
result.shift();
return result;
}
var parseBboxList = function(string){
- result = /(.+)(:?,(.+)){3}/.exec(string);
+ console.log("input: " + string);
+ result = /(.+),(.+),(.+),(.+)/.exec(string);
+
+ console.log(result);
if(result.length != 4){
throw "error";
@@ -30,19 +36,25 @@ exports.urlToXpathObj = function urlToXpathObj(url){
var xp = {};
- result = /\/(*|node|way|relation)(:?\[(.*)=(.*)\])*/.exec(url);
+ result = url.match(/\/(\*|node|way|relation)\[(.*)=(.*)\]*/);
+ console.log("OUTER: " + result);
+
xp.object=result[1];
for(i=2;i<=result.length;i++){
- if(result[i]==="bbox"){
- xp.bbox = parseBboxValues(result[i+1]);
+ if(result[i]==="bbox" && result[i]){
+ xp.bbox = parseBboxList(result[i+1]);
} else {
- xp.tag ={};
- xp.tag.keys = parseKeyList(result[i]);
- xp.tag.values = parseKeyList(result[i+1]);
+ if(result[i]){
+ xp.tag ={};
+ xp.tag.keys = parseKeyList(result[i]);
+ xp.tag.values = parseKeyList(result[i+1]);
+ }
}
i++;
- }
+ }
+ console.log(xp);
+ return(xp);
}
diff --git a/src/nodejs/tests/urlToResObj.js b/src/nodejs/tests/urlToResObj.js
new file mode 100644
index 0000000..b45edfd
--- /dev/null
+++ b/src/nodejs/tests/urlToResObj.js
@@ -0,0 +1,63 @@
+var assert = require('assert');
+var test = require('../parse.js');
+
+
+//TODO function does not exist yet
+var toTest = test.urlToXpathObj;
+
+
+// test all simple objects { node, way, relation }
+
+var simpleNodeString = "/node";
+var expected = { object: "node" };
+assert.deepEqual(toTest(simpleNodeString), expected);
+
+var simpleNodeStringTrail = "/node/";
+var expected = { object: "node" };
+assert.deepEqual(toTest(simpleNodeStringTrail), expected);
+
+var simpleWayString = "/way";
+var expected = { object: "way" };
+assert.deepEqual(toTest(simpleWayString), expected);
+
+var simpleWayStringTrail = "/way/";
+var expected = { object: "way" };
+assert.deepEqual(toTest(simpleWayStringTrail), expected);
+
+var simpleRelationString = "/relation";
+var expected = { object: "relation" };
+assert.deepEqual(toTest(simpleRelationString), expected);
+
+var simpleRelationStringTrail = "/relation/";
+var expected = { object: "relation" };
+assert.deepEqual(toTest(simpleRelationStringTrail), expected);
+
+// TODO invalid object eg not (node, way, relation)
+
+var nodeWithBbox = "/node[bbox=0,51.5,0.25,51.75]";
+var expected = { object: "node", bbox: {left:0, bottom:51.5, right:0.25, top:51.75} };
+assert.deepEqual(toTest(nodeWithBbox), expected);
+
+var nodeWithSimpleTag = "/node[key=value]";
+var expected = { object: "node", tag: { key:["key"], value:["value"]}};
+assert.deepEqual(toTest(nodeWithSimpleTag), expected);
+
+var nodeWithTwoValues = "/node[tag=foo|bar]";
+var expected = { object: "node", tag: { key:["key"], value:["foo", "bar"]}};
+assert.deepEqual(toTest(nodeWithTwoValues), expected);
+
+var nodeWithTwoKeys = "/node[foo,bar=value]";
+var expected = { object: "node", tag: { key:["foo", "bar"], value:["value"]}};
+assert.deepEqual(toTest(nodeWithTwoKeys), expected);
+
+var tagCrossProduct = "/node[key1,key2=value1,value2]";
+var expected = { object: "node", tag: {key:["key1", "key2"], value:["value1", "value2"]}};
+assert.deepEqual(toTest(tagCrossProduct), expected);
+
+var nodeBboxTag = "/node[bbox=0,0,0,0][key=value]";
+var nodeTagBbox = "/node[bbox=0,0,0,0][key=value]";
+var expected = { object: "node", bbox: {left:0,bottom:0,right:0,top:0}, tag: {key:["key"], value:["value"]}};
+assert.deepEqual(toTest(nodeBboxTag), expected);
+assert.deepEqual(toTest(nodeTagBbox), expected);
+
+