static char[] bufOf(String s) { try { return Unsafe.bufOf(s); } catch (Exception e) { return s.toCharArray(); } }
@Override public String toString() { char[] newBuf = charArray(); try { return Unsafe.stringOf(newBuf); } catch (Exception e) { return new String(newBuf); } }
@Override public String toString() { char[] newBuf = charArray(); try { return Unsafe.stringOf(newBuf); } catch (Exception e) { return new String(newBuf); } }
static char[] bufOf(String s) { try { return Unsafe.bufOf(s); } catch (Exception e) { return s.toCharArray(); } }
public byte[] getBytesAscII() { int sz = size(); if (sz == 0) { return new byte[0]; } try { char[] chars; if (sz == buf.length && begin == 0) { chars = buf; } else { chars = new char[sz]; System.arraycopy(buf, begin, chars, 0, sz); } return Unsafe.stringOf(chars).getBytes(Charsets.US_ASCII); } catch (Exception e) { return toString().getBytes(Charsets.US_ASCII); } }
public RequestHandler findStaticGetHandler(String url) { Iterator<String> path = Path.tokenizer(Unsafe.bufOf(url)); Node node = root(H.Method.GET); while (null != node && path.hasNext()) { String nodeName = path.next(); node = node.staticChildren.get(nodeName); if (null == node || node.terminateRouteSearch()) { break; } } return null == node ? null : node.handler; }
public String with(String replacement) { if (null != pattern) { return pattern.matcher(text).replaceAll(replacement); } else { if (text.length() < keyword.length()) { return text; } int firstId = this.text.indexOf(this.keyword); if (firstId < 0) { return this.text; } char[] text = Unsafe.bufOf(this.text); char[] target = this.keyword.toCharArray(); char[] replace = replacement.toCharArray(); char[] result = this.replacer.replace(text, target, replace, firstId); return (result == text) ? this.text : Unsafe.stringOf(result); } } }
public byte[] getBytesAscII() { int sz = size(); if (sz == 0) { return new byte[0]; } try { char[] chars; if (sz == buf.length && begin == 0) { chars = buf; } else { chars = new char[sz]; System.arraycopy(buf, begin, chars, 0, sz); } return Unsafe.stringOf(chars).getBytes(Charsets.US_ASCII); } catch (Exception e) { return toString().getBytes(Charsets.US_ASCII); } }
public RequestHandler findStaticGetHandler(String url) { Iterator<String> path = Path.tokenizer(Unsafe.bufOf(url)); Node node = root(H.Method.GET); while (null != node && path.hasNext()) { String nodeName = path.next(); node = node.staticChildren.get(nodeName); if (null == node || node.terminateRouteSearch()) { break; } } return null == node ? null : node.handler; }
public String with(String replacement) { if (null != pattern) { return pattern.matcher(text).replaceAll(replacement); } else { if (text.length() < keyword.length()) { return text; } int firstId = this.text.indexOf(this.keyword); if (firstId < 0) { return this.text; } char[] text = Unsafe.bufOf(this.text); char[] target = this.keyword.toCharArray(); char[] replace = replacement.toCharArray(); char[] result = this.replacer.replace(text, target, replace, firstId); return (result == text) ? this.text : Unsafe.stringOf(result); } } }
@Override public byte[] getBytesUTF8() { int sz = size(); if (sz == 0) { return new byte[0]; } try { char[] chars; if (sz == buf.length && begin == 0) { chars = buf; } else { chars = new char[sz]; System.arraycopy(buf, begin, chars, 0, sz); } return Unsafe.stringOf(chars).getBytes(Charsets.UTF_8); } catch (Exception e) { return toString().getBytes(Charsets.UTF_8); } }
private Node _search(H.Method method, String path) { Node node = root(method); assert node != null; E.unsupportedIf(null == node, "Method %s is not supported", method); if (path.length() == 1 && path.charAt(0) == '/') { return node; } String sUrl = path; List<String> paths = Path.tokenize(Unsafe.bufOf(sUrl)); int len = paths.size(); for (int i = 0; i < len - 1; ++i) { node = node.findChild(paths.get(i)); if (null == node) return null; } return node.findChild(paths.get(len - 1)); }
public String in(String text) { if (null != replacementFunction) { E.illegalStateIf(null != pattern, "Replace with function doesnot support regex search"); replacement = replacementFunction.apply(keyword); } if (null != pattern) { return pattern.matcher(text).replaceAll(replacement); } if (text.length() < keyword.length()) { return text; } int firstId = text.indexOf(this.keyword); if (firstId < 0) { return text; } char[] textArray = Unsafe.bufOf(text); char[] target = this.keyword.toCharArray(); char[] replace = replacement.toCharArray(); char[] result = this.replacer.replace(textArray, target, replace, firstId); return (result == textArray) ? text : Unsafe.stringOf(result); } }
@Override public byte[] getBytesUTF8() { int sz = size(); if (sz == 0) { return new byte[0]; } try { char[] chars; if (sz == buf.length && begin == 0) { chars = buf; } else { chars = new char[sz]; System.arraycopy(buf, begin, chars, 0, sz); } return Unsafe.stringOf(chars).getBytes(Charsets.UTF_8); } catch (Exception e) { return toString().getBytes(Charsets.UTF_8); } }
private Node _search(H.Method method, String path) { Node node = root(method); assert node != null; E.unsupportedIf(null == node, "Method %s is not supported", method); if (path.length() == 1 && path.charAt(0) == '/') { return node; } String sUrl = path; List<String> paths = Path.tokenize(Unsafe.bufOf(sUrl)); int len = paths.size(); for (int i = 0; i < len - 1; ++i) { node = node.findChild(paths.get(i)); if (null == node) return null; } return node.findChild(paths.get(len - 1)); }
public String in(String text) { if (null != replacementFunction) { E.illegalStateIf(null != pattern, "Replace with function doesnot support regex search"); replacement = replacementFunction.apply(keyword); } if (null != pattern) { return pattern.matcher(text).replaceAll(replacement); } if (text.length() < keyword.length()) { return text; } int firstId = text.indexOf(this.keyword); if (firstId < 0) { return text; } char[] textArray = Unsafe.bufOf(text); char[] target = this.keyword.toCharArray(); char[] replace = replacement.toCharArray(); char[] result = this.replacer.replace(textArray, target, replace, firstId); return (result == textArray) ? text : Unsafe.stringOf(result); } }
public FastStr urlEncode() { String s; try { s = Unsafe.stringOf(buf); } catch (Exception e) { s = toString(); } return unsafeOf(S.urlEncode(s)); }
public boolean startsWith(CharSequence suffix, int toffset) { if (suffix.length() == 0) return true; int sz2 = suffix.length(), sz = size(); if (toffset < 0 || toffset > sz - sz2) { return false; } int po = 0, pc = sz2, to = toffset; char[] buf1 = buf; try { char[] buf2 = Unsafe.bufOf(suffix); while (--pc >= 0) { if (buf1[toInternalId(to++)] != buf2[po++]) { return false; } } return true; } catch (RuntimeException e) { while (--pc >= 0) { if (buf1[toInternalId(to++)] != suffix.charAt(po++)) { return false; } } return true; } }