Various constants and helper utilities.
| 10 | * Various constants and helper utilities. |
| 11 | */ |
| 12 | abstract class Utils { |
| 13 | |
| 14 | static final int[] EMPTY_INTS = {}; |
| 15 | |
| 16 | // Returns true iff |c| is an ASCII letter or decimal digit. |
| 17 | static boolean isalnum(int c) { |
| 18 | return ('0' <= c && c <= '9') || ('A' <= c && c <= 'Z') || ('a' <= c && c <= 'z'); |
| 19 | } |
| 20 | |
| 21 | // If |c| is an ASCII hex digit, returns its value, otherwise -1. |
| 22 | static int unhex(int c) { |
| 23 | if ('0' <= c && c <= '9') { |
| 24 | return c - '0'; |
| 25 | } |
| 26 | if ('a' <= c && c <= 'f') { |
| 27 | return c - 'a' + 10; |
| 28 | } |
| 29 | if ('A' <= c && c <= 'F') { |
| 30 | return c - 'A' + 10; |
| 31 | } |
| 32 | return -1; |
| 33 | } |
| 34 | |
| 35 | private static final String METACHARACTERS = "\\.+*?()|[]{}^$"; |
| 36 | |
| 37 | // Appends a RE2 literal to |out| for rune |rune|, |
| 38 | // with regexp metacharacters escaped. |
| 39 | static void escapeRune(StringBuilder out, int rune) { |
| 40 | if (Unicode.isPrint(rune)) { |
| 41 | if (METACHARACTERS.indexOf((char) rune) >= 0) { |
| 42 | out.append('\\'); |
| 43 | } |
| 44 | out.appendCodePoint(rune); |
| 45 | return; |
| 46 | } |
| 47 | |
| 48 | switch (rune) { |
| 49 | case '"': |
| 50 | out.append("\\\""); |
| 51 | break; |
| 52 | case '\\': |
| 53 | out.append("\\\\"); |
| 54 | break; |
| 55 | case '\t': |
| 56 | out.append("\\t"); |
| 57 | break; |
| 58 | case '\n': |
| 59 | out.append("\\n"); |
| 60 | break; |
| 61 | case '\r': |
| 62 | out.append("\\r"); |
| 63 | break; |
| 64 | case '\b': |
| 65 | out.append("\\b"); |
| 66 | break; |
| 67 | case '\f': |
| 68 | out.append("\\f"); |
| 69 | break; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…