use of com.google.template.soy.data.restricted.SoyString in project closure-templates by google.
the class BidiDirectivesRuntime method bidiUnicodeWrap.
public static SoyString bidiUnicodeWrap(BidiGlobalDir dir, SoyValue value) {
// normalize null between tofu and jbcsrc
value = value == null ? NullData.INSTANCE : value;
ContentKind valueKind = null;
Dir valueDir = null;
if (value instanceof SanitizedContent) {
SanitizedContent sanitizedContent = (SanitizedContent) value;
valueKind = sanitizedContent.getContentKind();
valueDir = sanitizedContent.getContentDirection();
}
BidiFormatter bidiFormatter = BidiFormatter.getInstance(dir.toDir());
// We treat the value as HTML if and only if it says it's HTML, even though in legacy usage, we
// sometimes have an HTML string (not SanitizedContent) that is passed to an autoescape="false"
// template or a {print $foo |noAutoescape}, with the output going into an HTML context without
// escaping. We simply have no way of knowing if this is what is happening when we get
// non-SanitizedContent input, and most of the time it isn't.
boolean isHtml = valueKind == ContentKind.HTML;
String wrappedValue = bidiFormatter.unicodeWrap(valueDir, value.coerceToString(), isHtml);
// Unicode-wrapping safe HTML.
if (valueKind == ContentKind.TEXT || valueKind == ContentKind.HTML) {
// run.
return UnsafeSanitizedContentOrdainer.ordainAsSafe(wrappedValue, valueKind, dir.toDir());
}
// TEXT, or HTML.
if (valueKind != null) {
return StringData.forValue(wrappedValue);
}
// The input was not SanitizedContent, so our output isn't SanitizedContent either.
return StringData.forValue(wrappedValue);
}
use of com.google.template.soy.data.restricted.SoyString in project closure-templates by google.
the class DetachableContentProvider method getResolvedValue.
private SoyString getResolvedValue() {
SoyString local = resolvedValue;
if (local == null) {
if (buffer != null) {
String string = buffer.toString();
// when it has to by making sure that renderAndResolve is used for all printing usecases
if (contentKind != null) {
local = UnsafeSanitizedContentOrdainer.ordainAsSafe(string, contentKind);
} else {
local = StringData.forValue(string);
}
resolvedValue = local;
} else {
throw new AssertionError("getResolvedValue() should only be called if the value isDone.");
}
}
return local;
}
use of com.google.template.soy.data.restricted.SoyString in project closure-templates by google.
the class StrIndexOfFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
SoyValue arg1 = args.get(1);
Preconditions.checkArgument(arg0 instanceof SoyString, "First argument to strIndexOf() function is not StringData or SanitizedContent: %s", arg0);
Preconditions.checkArgument(arg1 instanceof SoyString, "Second argument to strIndexOf() function is not StringData or SanitizedContent: %s", arg1);
String strArg0 = arg0.coerceToString();
String strArg1 = arg1.coerceToString();
return IntegerData.forValue(strArg0.indexOf(strArg1));
}
use of com.google.template.soy.data.restricted.SoyString in project closure-templates by google.
the class StrLenFunction method computeForJava.
@Override
public SoyValue computeForJava(List<SoyValue> args) {
SoyValue arg0 = args.get(0);
Preconditions.checkArgument(arg0 instanceof SoyString, "First argument to strLen() function is not StringData or SanitizedContent: %s", arg0);
return IntegerData.forValue(arg0.coerceToString().length());
}
use of com.google.template.soy.data.restricted.SoyString in project closure-templates by google.
the class DetachableContentProvider method resolve.
@Override
public final SoyValue resolve() {
checkState(isDone(), "called resolve() before status() returned ready.");
SoyString local = getResolvedValue();
checkState(local != TombstoneValue.INSTANCE, "called resolve() after calling renderAndResolve with isLast == true");
return local;
}
Aggregations