package com.spookyinternet.cobweb; import java.util.*; public class HttpRoute { private List pieces; public HttpRoute(String path, HttpInspectFunction fn) throws Exception { } public HttpRoute(String path, HttpRequestFunction fn) throws Exception { this.pieces = new ArrayList(); if(path.charAt(0) != '/') { throw new Exception("Invalid HTTP route: " + path); } int idx = 0; int marker = 0; while(idx < path.length()) { char rune = path.charAt(idx); if(rune == '/' || rune == '*') { if(idx > marker) { pieces.add(path.substring(marker, idx)); } pieces.add(String.valueOf(rune)); marker = idx + 1; } else if(rune == '{') { if(idx > marker) { pieces.add(path.substring(marker, idx)); } marker = idx; } else if(rune == '}') { pieces.add(path.substring(marker, idx + 1)); marker = idx + 1; } idx += 1; } if(idx > marker) { pieces.add(path.substring(marker, idx + 1)); } } }