/** * Create a route matcher for the a request. * * @param path the path * @param requestParams the query parameters * @return the route matcher */ public final Iterator<RouteMatch> matcher(String path, Map<String, String[]> requestParams) { // Always start with a '/' if (!path.startsWith("/")) { path = "/" + path; } // return new RouteMatcher(this, Path.parse(path), requestParams); }
Path subPath(int index) { if (index < 0) { throw new IndexOutOfBoundsException("No negative index accepted"); } else if (index == 0) { return this; } else { int i = offset + index; if (i > data.value.length()) { throw new IndexOutOfBoundsException("Index can't be greater than length"); } return new Path(data, i); } }
boolean isEscaped(int index) { return data.isEscaped(innerIndex(index)); }
while (POS < current.path.length() && current.path.charAt(POS) == '/') { POS++; int pos = current.path.indexOf('/', POS); if (pos == -1) { pos = current.path.length(); String segment = current.path.getValue().substring(POS, pos); Path nextSegmentPath = current.path.subPath(pos); if (path.length() > 0 && path.charAt(0) == '/') { path = path.subPath(1); RE.Match[] matches = patternRoute.pattern.re.matcher().find(path.getValue()); Path nextPath = path.subPath(nextPos); StringBuilder sb = new StringBuilder(); for (int from = match.getStart();from < match.getEnd();from++) { char c = path.charAt(from); if (c == child.router.separatorEscape && !path.isEscaped(from)) { c = '/'; while (pos < current.path.length() && current.path.charAt(pos) == '/') { pos++; if (pos == current.path.length()) { if (current.route instanceof EmptyRoute) {
@Test public void testFoo() throws Exception { assertEquals("", Path.parse("").getValue()); assertEquals("a", Path.parse("a").getValue()); assertEquals("?", Path.parse("%3F").getValue()); assertEquals(" ", Path.parse("%20").getValue()); assertEquals("? ", Path.parse("%3F%20").getValue()); // Path p2 = Path.parse("_"); assertEquals("_", p2.getValue()); assertFalse(p2.isEscaped(0)); // Path p3 = Path.parse("a%5Fb%5Fc"); assertEquals("a_b_c", p3.getValue()); assertFalse(p3.isEscaped(0)); assertTrue(p3.isEscaped(1)); assertFalse(p3.isEscaped(2)); assertTrue(p3.isEscaped(3)); assertFalse(p3.isEscaped(4)); // Path p4 = p3.subPath(2); assertFalse(p4.isEscaped(0)); assertTrue(p4.isEscaped(1)); assertFalse(p4.isEscaped(2)); }
@Test public void testSubPath() { Path path = Path.parse("foo"); assertEquals("foo", path.subPath(0).getValue()); assertEquals("oo", path.subPath(1).getValue()); assertEquals("o", path.subPath(2).getValue()); assertEquals("", path.subPath(3).getValue()); try { path.subPath(4); fail(); } catch (IndexOutOfBoundsException expected) { } try { path.subPath(-1); fail(); } catch (IndexOutOfBoundsException expected) { } }
while (POS < current.path.length() && current.path.charAt(POS) == '/') { POS++; int pos = current.path.indexOf('/', POS); if (pos == -1) { pos = current.path.length(); String segment = current.path.getValue().substring(POS, pos); Path nextSegmentPath = current.path.subPath(pos); if (path.length() > 0 && path.charAt(0) == '/') { path = path.subPath(1); RE.Match[] matches = patternRoute.pattern.re.matcher().find(path.getValue()); Path nextPath = path.subPath(nextPos); StringBuilder sb = new StringBuilder(); for (int from = match.getStart();from < match.getEnd();from++) { char c = path.charAt(from); if (c == child.router.separatorEscape && !path.isEscaped(from)) { c = '/'; while (pos < current.path.length() && current.path.charAt(pos) == '/') { pos++; if (pos == current.path.length()) { if (current.route instanceof EmptyRoute) {
@Test public void testFoo() throws Exception { assertEquals("", Path.parse("").getValue()); assertEquals("a", Path.parse("a").getValue()); assertEquals("?", Path.parse("%3F").getValue()); assertEquals(" ", Path.parse("%20").getValue()); assertEquals("? ", Path.parse("%3F%20").getValue()); // Path p2 = Path.parse("_"); assertEquals("_", p2.getValue()); assertFalse(p2.isEscaped(0)); // Path p3 = Path.parse("a%5Fb%5Fc"); assertEquals("a_b_c", p3.getValue()); assertFalse(p3.isEscaped(0)); assertTrue(p3.isEscaped(1)); assertFalse(p3.isEscaped(2)); assertTrue(p3.isEscaped(3)); assertFalse(p3.isEscaped(4)); // Path p4 = p3.subPath(2); assertFalse(p4.isEscaped(0)); assertTrue(p4.isEscaped(1)); assertFalse(p4.isEscaped(2)); }
@Test public void testSubPath() { Path path = Path.parse("foo"); assertEquals("foo", path.subPath(0).getValue()); assertEquals("oo", path.subPath(1).getValue()); assertEquals("o", path.subPath(2).getValue()); assertEquals("", path.subPath(3).getValue()); try { path.subPath(4); fail(); } catch (IndexOutOfBoundsException expected) { } try { path.subPath(-1); fail(); } catch (IndexOutOfBoundsException expected) { } }
/** * Create a route matcher for the a request. * * @param path the path * @param requestParams the query parameters * @return the route matcher */ public final Iterator<RouteMatch> matcher(String path, Map<String, String[]> requestParams) { // Always start with a '/' if (!path.startsWith("/")) { path = "/" + path; } // return new RouteMatcher(this, Path.parse(path), requestParams); }
Path subPath(int index) { if (index < 0) { throw new IndexOutOfBoundsException("No negative index accepted"); } else if (index == 0) { return this; } else { int i = offset + index; if (i > data.value.length()) { throw new IndexOutOfBoundsException("Index can't be greater than length"); } return new Path(data, i); } }
boolean isEscaped(int index) { return data.isEscaped(innerIndex(index)); }
private void assertInvalid(String s) { try { Path.parse(s); fail("Was expecting " + s + " to be invalid"); } catch (IllegalArgumentException ignore) { } } }
static Path parse(String path) throws UndeclaredIOException { try { Data data = new Data(path); return new Path(data, 0); } catch (IOException e) { throw new UndeclaredIOException(e); } }