aboutsummaryrefslogtreecommitdiffstats
path: root/src/nodejs
diff options
context:
space:
mode:
authorslomo <steve.harrison@gmx.net>2011-01-28 17:21:42 +0100
committerslomo <steve.harrison@gmx.net>2011-01-28 17:21:42 +0100
commit422a1895cad4dcee2a82eba1aad86513268ed0ce (patch)
tree30f81f08b9308fd7ed23e9cb83b5e3e963e783cd /src/nodejs
parent5df2c8b916bf8845042be1f9df4656cd13a3ddbe (diff)
downloadosm-xapi-422a1895cad4dcee2a82eba1aad86513268ed0ce.tar.gz
osm-xapi-422a1895cad4dcee2a82eba1aad86513268ed0ce.tar.xz
osm-xapi-422a1895cad4dcee2a82eba1aad86513268ed0ce.zip
url parsing
Diffstat (limited to 'src/nodejs')
-rw-r--r--src/nodejs/main.js64
-rw-r--r--src/nodejs/parse.js48
-rw-r--r--src/nodejs/tests/urlToResObj.js4
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 }