public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { if (string != null) { StringBuilder builder = new StringBuilder(string); // 过滤用户替换的所有字符 filterInt(builder); string = builder.toString(); } super.replace(fb, offset, length, string, attr); }
public void replace(FilterBypass fb, int offset, int length, String string, AttributeSet attr) throws BadLocationException { if (string != null) { 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); } } } string = builder.toString(); } super.replace(fb, offset, length, string, attr); }
public void replace(FilterBypass fb, int offs, int length, String str, AttributeSet a) throws BadLocationException { if ("\n".equals(str)) str = addWhiteSpace(fb.getDocument(), offs); super.replace(fb, offs, length, str, a); }