public void insertString(FilterBypass fb, int offset, String string, AttributeSet attr) throws BadLocationException { StringBuilder builder = new StringBuilder(string); for (int i = builder.length() - 1; i >= 0; i--) { int cp = builder.codePointAt(i); if (!Character.isDigit(cp) && cp != '-') { builder.deleteCharAt(i); if (Character.isSupplementaryCodePoint(cp)) { i--; builder.deleteCharAt(i); } } } super.insertString(fb, offset, builder.toString(), attr); }
// 过滤整数字符,把所有非0~9的字符全部删除 private void filterInt(StringBuilder builder) { for (int i = builder.length() - 1; i >= 0; i--) { int cp = builder.codePointAt(i); if (cp > '9' || cp < '0') { builder.deleteCharAt(i); } } }
public static String concatSortedPercentEncodedParams(Map<String, String> params) { StringBuilder target = new StringBuilder(); for (String key : params.keySet()) { target.append(key); target.append(PAIR_SEPARATOR); target.append(params.get(key)); target.append(PARAM_SEPARATOR); } return target.deleteCharAt(target.length() - 1).toString(); }