public class BaseUtils extends Object
Important: Do not use outside of Soy code (treat as superpackage-private).
| Modifier and Type | Field and Description |
|---|---|
static String |
DOTTED_IDENT_RE
Regular expression for a dotted identifier.
|
static String |
IDENT_RE
Regular expression for an identifier.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
appendHexEscape(StringBuilder out,
int codePoint)
Appends the Unicode hex escape sequence for the given code point (backslash + 'u' + 4 hex
digits) to the given StringBuilder.
|
static String |
convertToUpperUnderscore(String ident)
Converts an identifier to upper-underscore format.
|
static void |
ensureDirsExistInPath(String path)
Ensures that the directories in the given path exist, creating them if necessary.
|
static String |
escapeToSoyString(String value,
boolean shouldEscapeToAscii,
QuoteStyle quoteStyle)
Builds a Soy string literal for this string value (including the surrounding single quotes).
|
static String |
extractPartAfterLastDot(String dottedIdent)
Gets the part after the last dot in a dotted identifier.
|
static boolean |
isDottedIdentifier(String s)
Determines whether the given string is a dotted identifier (e.g.
|
static boolean |
isIdentifier(String s)
Determines whether the given string is an identifier.
|
static boolean |
isIdentifierWithLeadingDot(String s)
Determines whether the given string is a dot followed by an identifier.
|
public static final String IDENT_RE
public static final String DOTTED_IDENT_RE
public static void ensureDirsExistInPath(String path)
Note: If the path does not end with the separator char (slash in Linux), then the name at the end is assumed to be the file name, so directories are only created down to its parent.
path - The path for which to ensure directories exist.public static boolean isIdentifier(String s)
An identifier must start with a letter or underscore and must only contain letters, digits,
and underscores (i.e. it must match the regular expression [A-Za-z_][A-Za-z_0-9]*).
s - The string to check.public static boolean isIdentifierWithLeadingDot(String s)
s - The string to check.public static boolean isDottedIdentifier(String s)
boo.foo0._goo). A
dotted identifier is not required to have dots (i.e. a simple identifier qualifies as a dotted
identifier).s - The string to check.boo.foo0._goo).public static String extractPartAfterLastDot(String dottedIdent)
Important: The input must be a dotted identifier. This is not checked.
public static String convertToUpperUnderscore(String ident)
[A-Za-z_][A-Za-z_0-9]*).ident - The identifier to convert.public static String escapeToSoyString(String value, boolean shouldEscapeToAscii, QuoteStyle quoteStyle)
Adapted from StringUtil.javaScriptEscape().
value - The string value to escape.shouldEscapeToAscii - Whether to escape non-ASCII characters as Unicode hex escapes
(backslash + 'u' + 4 hex digits).quoteStyle - whether or not to use double quotespublic static void appendHexEscape(StringBuilder out, int codePoint)
Note: May append 2 escape sequences (surrogate pair) in the case of a supplementary character (outside the Unicode BMP).
Adapted from StringUtil.appendHexJavaScriptRepresentation().
out - The StringBuilder to append to.codePoint - The Unicode code point whose hex escape sequence to append.