use of com.google.template.soy.data.restricted.StringData in project closure-templates by google.
the class StrSubFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
SoyValue arg2 = args.size() == 3 ? args.get(2) : null;
Preconditions.checkArgument(arg0 instanceof StringData || arg0 instanceof SanitizedContent, "First argument to strSub() function is not StringData or SanitizedContent: %s", arg0);
Preconditions.checkArgument(arg1 instanceof IntegerData, "Second argument to strSub() function is not IntegerData: %s", arg1);
if (arg2 != null) {
Preconditions.checkArgument(arg2 instanceof IntegerData, "Third argument to strSub() function is not IntegerData: %s", arg2);
}
String strArg0 = arg0.coerceToString();
int intArg1 = arg1.integerValue();
if (arg2 != null) {
return StringData.forValue(strArg0.substring(intArg1, arg2.integerValue()));
} else {
return StringData.forValue(strArg0.substring(intArg1));
}
}
use of com.google.template.soy.data.restricted.StringData in project closure-templates by google.
the class StrContainsFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
Preconditions.checkArgument(arg0 instanceof StringData || arg0 instanceof SanitizedContent, "First argument to strContains() function is not StringData or SanitizedContent: %s", arg0);
String strArg0 = arg0.coerceToString();
String strArg1 = arg1.coerceToString();
return BooleanData.forValue(strArg0.contains(strArg1));
}
Aggregations