/** Set the text of an XML element, safely encode it if needed. */ @NotNull public static Element setSafeXmlText(@NotNull Element element, @NotNull String text) { final Character first = firstCharacter(text); final Character last = lastCharacter(text); if (!StringHelper.isXmlCharacterData(text) || first != null && Character.isWhitespace(first) || last != null && Character.isWhitespace(last)) { element.setAttribute("encoding", "base64"); final String encoded = new String(Base64.encodeBase64(text.getBytes())); element.setText(encoded); } else { element.setText(text); } return element; }
/** Append the supplied text to any existing text. */ public void addText(@NotNull String text) { addKeys(StringHelper.stringToKeys(text)); }
public Register(char name, @NotNull SelectionType type, @NotNull String text) { this.name = name; this.type = type; this.keys = StringHelper.stringToKeys(text); }
private static boolean shouldIgnoreCase(@NotNull String pattern, boolean noSmartCase) { boolean sc = !noSmartCase && Options.getInstance().isSet("smartcase"); boolean ic = Options.getInstance().isSet("ignorecase"); return ic && !(sc && StringHelper.containsUpperCase(pattern)); }
@Nullable private static String getSafeChildText(@NotNull Element element, @NotNull String name) { final Element child = element.getChild(name); return child != null ? StringHelper.getSafeXmlText(child) : null; }
@NotNull private static Element createElementWithText(@NotNull String name, @NotNull String text) { return StringHelper.setSafeXmlText(new Element(name), text); }