Text Filter localization

[亡魂溺海] 提交于 2019-12-10 12:07:46

问题


if i create a text filter in the following manner

class AlphaTextFilter extends TextFilter {

    public char convert(char c, int status) {
        if (!validate(c))
                return 0;
        return c;
    }

    public boolean validate(char c) {
        return ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z'));
    }
}

will it work if the code is run on a device with some language other than english...? how can i make a localized....?


回答1:


That depends on what your definition of "work" is. If by "work" you mean accepts only [a-zA-Z], then yes.

If you mean would it meet the expectations of international users who expect to be using alphabetic, syllabic or ideographic characters (or "letters" in more common usage), then no. Most platforms now offer some mechanism for identifying the unicode character class, and most newer regex engines support matching based on unicode character classes. In your case, \p{letter} would appear to be the most appropriate character class.




回答2:


What about using something like CharacterUtilities.isLetter() to check if it's a letter?




回答3:


Yes, I believe so.

A char is a char no matter what locale you're in. It's all Unicode anyway, so there shouldn't be any sort of localisation issues.



来源:https://stackoverflow.com/questions/2016817/text-filter-localization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!