8032909: XSLT string-length returns incorrect length when string includes complementary chars
Reviewed-by: joehw, dfuchs
This commit is contained in:
parent
43d3e02a42
commit
2c18d040ba
@ -26,7 +26,7 @@ package com.sun.org.apache.xalan.internal.xsltc.compiler;
|
||||
import java.util.Vector;
|
||||
|
||||
import com.sun.org.apache.bcel.internal.generic.ConstantPoolGen;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKEVIRTUAL;
|
||||
import com.sun.org.apache.bcel.internal.generic.INVOKESTATIC;
|
||||
import com.sun.org.apache.bcel.internal.generic.InstructionList;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.ClassGenerator;
|
||||
import com.sun.org.apache.xalan.internal.xsltc.compiler.util.MethodGenerator;
|
||||
@ -51,7 +51,8 @@ final class StringLengthCall extends FunctionCall {
|
||||
il.append(methodGen.loadContextNode());
|
||||
Type.Node.translateTo(classGen, methodGen, Type.String);
|
||||
}
|
||||
il.append(new INVOKEVIRTUAL(cpg.addMethodref(STRING_CLASS,
|
||||
"length", "()I")));
|
||||
il.append(new INVOKESTATIC(cpg.addMethodref(BASIS_LIBRARY_CLASS,
|
||||
"getStringLength",
|
||||
"(Ljava/lang/String;)I")));
|
||||
}
|
||||
}
|
||||
|
@ -1660,5 +1660,14 @@ public final class BasisLibrary {
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility method to calculate string-length as a number of code points,
|
||||
* to avoid possible errors with string that contains
|
||||
* complementary characters
|
||||
*/
|
||||
public static int getStringLength(String str) {
|
||||
return str.codePointCount(0,str.length());
|
||||
}
|
||||
|
||||
//-- End utility functions
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user