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 |
computePartialSha1AsHexString(String strToHash,
int numBits)
Computes the SHA-1 hash value of the input string's UTF-8 representation and returns the first
numBits bits of the result as a hex value in string form.
|
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)
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 String |
formatParseExceptionDetails(String errorToken,
List<String> expectedTokens)
A helper method for formating javacc ParseExceptions.
|
static boolean |
isDottedIdentifier(String s)
Determines whether the given string is a dotted identifier (e.g.
|
static boolean |
isDottedOrDashedIdent(String s)
Determines whether the given string is a "dotted or dashed" identifier.
|
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)
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 isDottedOrDashedIdent(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 identifer to convert.public static String escapeToSoyString(String value, boolean shouldEscapeToAscii)
value - The string value to escape.shouldEscapeToAscii - Whether to escape non-ASCII characters as Unicode hex escapes
(backslash + 'u' + 4 hex digits).public static void appendHexEscape(StringBuilder out, int codePoint)
out - The StringBuilder to append to.codePoint - The Unicode code point whose hex escape sequence to append.public static String computePartialSha1AsHexString(String strToHash, int numBits)
strToHash - The string to compute SHA-1 of.numBits - The number of bits worth to return. Must be a positive number at most 160 and
divisible by 8 (since we process the result 8 bits at a time).public static String formatParseExceptionDetails(String errorToken, List<String> expectedTokens)
errorToken - The piece of text that we were unable to parse.expectedTokens - The set of formatted tokens that we were expecting next.