@Test public void testChild() { childTestsPack("/test", "/test/one/two/three/"); childTestsPack("/test", "/test/one/two/three"); childTestsPack("/test/", "/test/one/two/three"); }
public static String child(String prefix, String path, int childNum) { if(!path.startsWith(prefix)) { return null; } int start = prefix.length(); if(prefix.charAt(start - 1) != '/') { start += 1; } int end; while(true) { end = path.indexOf('/', start); if(childNum <= 0) { break; } if(end < start) { return null; } childNum--; start = end + 1; } if(start == path.length()) { return null; } if(end < start) { return path.substring(start); } return path.substring(start, end); }
KvUtils { public static String child(String prefix, String path, int childNum) { if(!path.startsWith(prefix)) { return null; } int start = prefix.length(); if(prefix.charAt(start - 1) != '/') { start += 1; } int end; while(true) { end = path.indexOf('/', start); if(childNum <= 0) { break; } if(end < start) { return null; } childNum--; start = end + 1; } if(start == path.length()) { return null; } if(end < start) { return path.substring(start); } return path.substring(start, end); } }
KvUtils { public static String child(String prefix, String path, int childNum) { if(!path.startsWith(prefix)) { return null; } int start = prefix.length(); if(prefix.charAt(start - 1) != '/') { start += 1; } int end; while(true) { end = path.indexOf('/', start); if(childNum <= 0) { break; } if(end < start) { return null; } childNum--; start = end + 1; } if(start == path.length()) { return null; } if(end < start) { return path.substring(start); } return path.substring(start, end); }  }
KvUtils { public static String child(String prefix, String path, int childNum) { if(!path.startsWith(prefix)) { return null; } int start = prefix.length(); if(prefix.charAt(start - 1) != '/') { start += 1; } int end; while(true) { end = path.indexOf('/', start); if(childNum <= 0) { break; } if(end < start) { return null; } childNum--; start = end + 1; } if(start == path.length()) { return null; } if(end < start) { return path.substring(start); } return path.substring(start, end); }  static boolean predicate(String pattern, String key); static String join(String ... components); static String suffix(String prefix, String path); static String name(String prefix, String path); static String child(String prefix, String path, int childNum); }
KvUtils { public static String child(String prefix, String path, int childNum) { if(!path.startsWith(prefix)) { return null; } int start = prefix.length(); if(prefix.charAt(start - 1) != '/') { start += 1; } int end; while(true) { end = path.indexOf('/', start); if(childNum <= 0) { break; } if(end < start) { return null; } childNum--; start = end + 1; } if(start == path.length()) { return null; } if(end < start) { return path.substring(start); } return path.substring(start, end); }  static boolean predicate(String pattern, String key); static String join(String ... components); static String suffix(String prefix, String path); static String name(String prefix, String path); static String child(String prefix, String path, int childNum);  }