private Boolean computeWhitespace() { int n = getContentLength(); // This will leave computedContentLength computed in case it's needed afterwards if (n == 0) { return Boolean.FALSE; // empty texts are NOT whitespace } char c; while (n-- != 0) { c = charAtContent(n); if (c != ' ' && c != '\n') { // shortcut - most characters in many templates are just whitespace. if (!Character.isWhitespace(c)) { return Boolean.FALSE; } } } return Boolean.TRUE; }
final boolean isInlineable() { Boolean i = this.computedContentIsInlineable; if (i == null) { this.computedContentIsInlineable = i = computeInlineable(); } return i.booleanValue(); }
final boolean isWhitespace() { Boolean w = this.computedContentIsWhitespace; if (w == null) { this.computedContentIsWhitespace = w = computeWhitespace(); } return w.booleanValue(); }
@Override public String toString() { return getContentText(); }
public final void writeContent(final Writer writer) throws IOException { if (this.contentStr != null) { writer.write(this.contentStr); } else if (this.computedContentStr != null) { writer.write(this.computedContentStr); } else if (this.contentCharSeq instanceof IWritableCharSequence) { // In the special case we are using a writable CharSequence, we will avoid creating a String // for the whole content ((IWritableCharSequence) this.contentCharSeq).write(writer); } else { writer.write(getContentText()); // We write, but make sure we cache the String we create } }
private Boolean computeInlineable() { int n = getContentLength(); // This will leave computedContentLength computed in case it's needed afterwards if (n == 0) { return Boolean.FALSE; } char c0, c1; c0 = 0x0; int inline = 0; while (n-- != 0) { c1 = charAtContent(n); if (n > 0 && c1 == ']' && c0 == ']') { inline = 1; n--; c1 = charAtContent(n); } else if (n > 0 && c1 == ')' && c0 == ']') { inline = 2; n--; c1 = charAtContent(n); } else if (inline == 1 && c1 == '[' && c0 == '[') { return Boolean.TRUE; } else if (inline == 2 && c1 == '[' && c0 == '(') { return Boolean.TRUE; } c0 = c1; } return Boolean.FALSE; }