Permalink
Browse files

hand-rolled splitting for IE

  • Loading branch information...
1 parent 3f2b6c5 commit a31baa8aec564abb0f7386a73871f3796600d7bb @joshbuddy committed Aug 18, 2010
Showing with 36 additions and 3 deletions.
  1. +36 −3 lib/sherpa.js
View
@@ -14,16 +14,14 @@ RegExp.escape = function(text) {
}
Sherpa = {
- SplitRegex: /\//,
Router: function(options) {
this.routes = {};
this.root = new Sherpa.Node();
this.requestKeys = options && options['requestKeys'] || ['method'];
},
Path: function(route, uri) {
this.route = route;
- var regex = /(\/|:[a-zA-Z0-9_]+|(?:\\:|[^:\/]+)*)/;
- var splitUri = uri.split(regex);
+ var splitUri = this.pathSplit(uri);
this.compiledUri = [];
@@ -374,6 +372,41 @@ Sherpa.Route.prototype = {
};
Sherpa.Path.prototype = {
+ pathSplit: function(path) {
+ var splitParts = [];
+ var parts = path.split('/');
+ if (parts[0] == '') parts.shift();
+
+ for(var i = 0; i != parts.length; i++) {
+ splitParts.push("/");
+ splitParts.push("");
+ partChars = parts[i].split('');
+
+ var inVariable = false;
+
+ for (var j = 0; j != partChars.length; j++) {
+ if (inVariable) {
+ var code = partChars[j].charCodeAt(0);
+ if ((code >= 48 && code <= 57) || (code >= 65 && code <= 90) || (code >= 97 && code <= 122) || code == 95) {
+ splitParts[splitParts.length - 1] += partChars[j];
+ } else {
+ inVariable = false;
+ splitParts.push(partChars[j]);
+ }
+ } else if (partChars[j] == ':') {
+ inVariable = true;
+ if (splitParts[splitParts.length - 1] == '') {
+ splitParts[splitParts.length - 1] += ":";
+ } else {
+ splitParts.push(":");
+ }
+ } else {
+ splitParts[splitParts.length - 1] += partChars[j];
+ }
+ }
+ }
+ return splitParts;
+ },
generate: function(params) {
for(var varIdx = 0; varIdx != this.variableNames.length; varIdx++) {
if (!params[this.variableNames[varIdx]]) return undefined;

0 comments on commit a31baa8

Please sign in to comment.