@Override public String filter(CharSequence text) { if (filters==null) { return text.toString(); } else { String modified = text.toString(); for (TextFilter filter : filters) { modified = filter.filter(modified); } return modified; } } }
@Override public String filter(CharSequence text) { if (filters==null) { return text.toString(); } else { String modified = text.toString(); for (TextFilter filter : filters) { modified = filter.filter(modified); } return modified; } } }
/** * Append the target text for language detection. * If the total size of target text exceeds the limit size , * the rest is cut down. * * @param text the target text to append */ @Override public TextObject append(CharSequence text) { if (maxTextLength>0 && stringBuilder.length()>=maxTextLength) return this; text = textFilter.filter(text); //unfortunately this code can't be put into a TextFilter because: //1) the limit could not be detected early, a lot of work would be done to waste time and memory //2) the last character of the existing string builder could not be seen. if it is a space, we don't want // to add yet another space. char pre = stringBuilder.length()==0 ? 0 : stringBuilder.charAt(stringBuilder.length()-1); for (int i=0; i<text.length() && (maxTextLength==0 || stringBuilder.length()<maxTextLength); i++) { char c = CharNormalizer.normalize(text.charAt(i)); if (c != ' ' || pre != ' ') { stringBuilder.append(c); } pre = c; } return this; }
/** * Append the target text for language detection. * If the total size of target text exceeds the limit size , * the rest is cut down. * * @param text the target text to append */ @Override public TextObject append(CharSequence text) { if (maxTextLength>0 && stringBuilder.length()>=maxTextLength) return this; text = textFilter.filter(text); //unfortunately this code can't be put into a TextFilter because: //1) the limit could not be detected early, a lot of work would be done to waste time and memory //2) the last character of the existing string builder could not be seen. if it is a space, we don't want // to add yet another space. char pre = stringBuilder.length()==0 ? 0 : stringBuilder.charAt(stringBuilder.length()-1); for (int i=0; i<text.length() && (maxTextLength==0 || stringBuilder.length()<maxTextLength); i++) { char c = CharNormalizer.normalize(text.charAt(i)); if (c != ' ' || pre != ' ') { stringBuilder.append(c); } pre = c; } return this; }