/* */ package org.jaxen.function;
/* */
/* */ import java.util.
List;
/* */ import org.jaxen.
Context;
/* */ import org.jaxen.
Function;
/* */ import org.jaxen.
FunctionCallException;
/* */ import org.jaxen.
Navigator;
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public class
StringLengthFunction
/* */ implements
Function
/* */ {
/* */ public
Object call(
Context context,
List args) throws
FunctionCallException {
/* 102 */ if (
args.
size() == 0)
/* */ {
/* 104 */ return
evaluate(
context.
getNodeSet(),
context.
getNavigator());
/* */ }
/* */
/* 107 */ if (
args.
size() == 1)
/* */ {
/* 109 */ return
evaluate(
args.
get(0),
context.
getNavigator());
/* */ }
/* */
/* */
/* 113 */ throw new
FunctionCallException("string-length() requires one argument.");
/* */ }
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */
/* */ public static
Double evaluate(
Object obj,
Navigator nav) throws
FunctionCallException {
/* 131 */
String str =
StringFunction.
evaluate(
obj,
nav);
/* */
/* 133 */ char[]
data =
str.
toCharArray();
/* 134 */ int
length = 0;
/* 135 */ for (int
i = 0;
i <
data.length;
i++) {
/* 136 */ char
c =
data[
i];
/* 137 */
length++;
/* */
/* */
/* 140 */ if (
c >= '?') {
/* */ try {
/* 142 */ char
low =
data[
i + 1];
/* 143 */ if (
low < '?' ||
low > '?') {
/* 144 */ throw new
FunctionCallException("Bad surrogate pair in string " +
str);
/* */ }
/* 146 */
i++;
/* */ }
/* 148 */ catch (
ArrayIndexOutOfBoundsException ex) {
/* 149 */ throw new
FunctionCallException("Bad surrogate pair in string " +
str);
/* */ }
/* */ }
/* */ }
/* 153 */ return new
Double(
length);
/* */ }
/* */ }
/* Location: /Users/tommy/.m2/repository/jaxen/jaxen/1.1.1/jaxen-1.1.1.jar!/org/jaxen/function/StringLengthFunction.class
* Java compiler version: 2 (46.0)
* JD-Core Version: 1.1.3
*/