public Match(String path) {
// IF DEBUG: System.out.print("\n[" + path + "]");
params = new HashMap<>();
public Match(String path) {
// IF DEBUG: System.out.print("\n[" + path + "]");
params = new HashMap<>();
String[] pa = path.split("/");
values = new byte[pa.length][];
vars = new Integer[pa.length];
int val = 0;
String key;
String[] pa = path.split("/");
values = new byte[pa.length][];
vars = new Integer[pa.length];
int val = 0;
String key;
- for(int i=0;i<pa.length && !wildcard;++i) {
- if(pa[i].startsWith(":")) {
- if(pa[i].endsWith("*")) {
+ for (int i=0;i<pa.length && !wildcard;++i) {
+ if (pa[i].startsWith(":")) {
+ if (pa[i].endsWith("*")) {
val = i | pa.length<<16; // load end value in high order bits
key = pa[i].substring(0, pa[i].length()-1);// remove *
wildcard = true;
val = i | pa.length<<16; // load end value in high order bits
key = pa[i].substring(0, pa[i].length()-1);// remove *
wildcard = true;
/* remove * from value */
int newlength = values[i].length-1;
byte[] real = new byte[newlength];
/* remove * from value */
int newlength = values[i].length-1;
byte[] real = new byte[newlength];
*/
public String param(String path,String key) {
Integer val = params.get(key); // :key or key
*/
public String param(String path,String key) {
Integer val = params.get(key); // :key or key
int lastByte = pabytes.length;
boolean fieldMatched = false; // = lastByte>0?(pabytes[0]=='/'):false;
// IF DEBUG: System.out.println("\n -- " + path + " --");
int lastByte = pabytes.length;
boolean fieldMatched = false; // = lastByte>0?(pabytes[0]=='/'):false;
// IF DEBUG: System.out.println("\n -- " + path + " --");
- for(int i=0;rv && i<lastByte;++i) {
- if(field>=lastField) { // checking here allows there to be a non-functional ending /
+ for (int i=0;rv && i<lastByte;++i) {
+ if (field>=lastField) { // checking here allows there to be a non-functional ending /
- if(values[field]==null) { // it's a variable, just look for /s
- if(wildcard && field==lastField-1) return true;// we've made it this far. We accept all remaining characters
+ if (values[field]==null) { // it's a variable, just look for /s
+ if (wildcard && field==lastField-1) return true;// we've made it this far. We accept all remaining characters
Integer val = vars[field];
int start = val & 0xFFFF;
int end = (val >> 16) & 0xFFFF;
Integer val = vars[field];
int start = val & 0xFFFF;
int end = (val >> 16) & 0xFFFF;
- if(k==lastByte && pabytes[k-1]!='/')++field;
- if(k>i)i=k-1; // if we've incremented, have to accommodate the outer for loop incrementing as well
+ if (k==lastByte && pabytes[k-1]!='/')++field;
+ if (k>i)i=k-1; // if we've incremented, have to accommodate the outer for loop incrementing as well
// double slash in path, but content in field. We check specially here to avoid
// Array out of bounds issues.
rv = false;
} else {
// double slash in path, but content in field. We check specially here to avoid
// Array out of bounds issues.
rv = false;
} else {
rv =false; // field is already matched, now there's too many bytes
} else {
rv = pabytes[i]==values[field][fieldIdx++]; // compare expected (pabytes[i]) with value for particular field
fieldMatched=values[field].length==fieldIdx; // are all the bytes match in the field?
rv =false; // field is already matched, now there's too many bytes
} else {
rv = pabytes[i]==values[field][fieldIdx++]; // compare expected (pabytes[i]) with value for particular field
fieldMatched=values[field].length==fieldIdx; // are all the bytes match in the field?