我需要创建一个对应于
https://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive/的Collator,即在进行比较时忽略ASCII A-Z和a-z字符的区分大小写.
我用以下ICU4j RuleBasedCollator尝试了这个:
final RuleBasedCollator collator = new RuleBasedCollator("&a=A,b=B,c=C,d=D,e=E,f=F,g=G,h=H," + "i=I,j=J,k=K,l=L,m=M,n=N,o=O,p=P,q=Q,r=R,s=S,t=T," + "u=U,v=V,u=U,w=W,x=X,y=Y,z=Z").freeze();@H_502_5@但是,以下比较似乎失败了,我希望它能成功(即返回true):
final SearchIterator searchIterator = new StringSearch( "pu",new StringCharacterIterator("iNPut"),collator); return searchIterator.first() >= 0;@H_502_5@我的规则中缺少什么?
解决方法
>这个W3C“整理”看起来不像通常意义上的Collator.它是一个没有排序的ASCII不区分大小写的匹配器.我怀疑它通常是用低级代码实现的,它不区分大小写地匹配ASCII字母,而其他所有字符都精确匹配.见
https://www.w3.org/TR/xpath-functions-31/#html-ascii-case-insensitive-collation
> Collator规则可能不会按照您的想法执行.逗号是用于三次差异的旧语法,因此& a = A,b = B,c = C与& a = A<<<<<<<<<<<<<<<> c = C.我认为你打算像& a = A& b = B& c = C等.
> Collator规则可能不会按照您的想法执行.逗号是用于三次差异的旧语法,因此& a = A,b = B,c = C与& a = A<<<<<<<<<<<<<<<> c = C.我认为你打算像& a = A& b = B& c = C等.
> http://userguide.icu-project.org/collation/customization
> http://demo.icu-project.org/icu-bin/collation.html
> http://www.unicode.org/reports/tr35/tr35-collation.html#Rules