public final class Escaper extends Object
Modifier and Type | Class and Description |
---|---|
static class |
Escaper.Quoter
The quoting style to use when escaping.
|
Modifier and Type | Field and Description |
---|---|
static java.util.function.Function<String,String> |
ARGFILE_ESCAPER
Escaper for argfiles for clang and gcc.
|
static java.util.function.Function<String,String> |
BASH_ESCAPER
Bash quoting
Function which can be passed to Iterables.transform() . |
static java.util.function.Function<String,String> |
CREATE_PROCESS_ESCAPER
CreateProcess (Windows) quoting
Function which can be
passed to Iterables.transform() . |
static java.util.function.Function<String,String> |
SHELL_ESCAPER
Platform-aware shell quoting
Function which can be
passed to Iterables.transform()
TODO(sdwilsh): get proper cmd.EXE escaping implemented on Windows |
Modifier and Type | Method and Description |
---|---|
static int |
decodeNumericEscape(StringBuilder out,
String escaped,
int pos,
int maxCodeLength,
int base)
Call
decodeNumericEscape(StringBuilder, String, int, int, int, int) to parse at most
one escaped character; i.e. |
static int |
decodeNumericEscape(StringBuilder out,
String escaped,
int pos,
int maxCodeLength,
int base,
int maxCodes)
Decode a numeric escape as explained in this page:
http://en.cppreference.com/w/cpp/language/escape .
|
static String |
escape(Escaper.Quoter quoter,
com.google.common.base.CharMatcher matcher,
String str)
Escapes the special characters identified the
CharMatcher , using single quotes. |
static String |
escapeAsBashString(Path path) |
static String |
escapeAsBashString(String str)
Quotes a string to be passed to Bash, if necessary.
|
static String |
escapeAsMakefileValueString(String str) |
static String |
escapeAsPythonString(String str) |
static String |
escapeAsShellString(String str)
Quotes a string to be passed to the shell, if necessary.
|
static String |
escapePathForCIncludeString(Path path)
Escapes forward slashes in a Path as a String that is safe to consume with other tools (such as
gcc).
|
static java.util.function.Function<String,String> |
escaper(Escaper.Quoter quoter,
com.google.common.base.CharMatcher matcher) |
static String |
escapeWithQuotesAsMakefileValueString(String str) |
static java.util.function.Function<String,String> |
javacEscaper() |
static String |
unescapeLineMarkerPath(String escaped)
Unescape a path string obtained from preprocessor output, as in:
https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html .
|
public static final java.util.function.Function<String,String> BASH_ESCAPER
Function
which can be passed to Iterables.transform()
.public static final java.util.function.Function<String,String> CREATE_PROCESS_ESCAPER
Function
which can be
passed to Iterables.transform()
.public static final java.util.function.Function<String,String> SHELL_ESCAPER
Function
which can be
passed to Iterables.transform()
TODO(sdwilsh): get proper cmd.EXE escaping implemented on Windowspublic static final java.util.function.Function<String,String> ARGFILE_ESCAPER
Based on the following docs in the gcc manual:
@file Read command-line options from file. The options read are inserted in place of the original @file option. If file does not exist, or cannot be read, then the option will be treated literally, and not removed.
Options in file are separated by whitespace. A whitespace character may be included in an option by surrounding the entire option in either single or double quotes. Any character (including a backslash) may be included by prefixing the character to be included with a backslash. The file may itself contain additional @file options; any such options will be processed recursively.
public static String escape(Escaper.Quoter quoter, com.google.common.base.CharMatcher matcher, String str)
CharMatcher
, using single quotes.matcher
- identifies characters to be escapedstr
- string to quotepublic static java.util.function.Function<String,String> escaper(Escaper.Quoter quoter, com.google.common.base.CharMatcher matcher)
public static java.util.function.Function<String,String> javacEscaper()
public static String escapeAsShellString(String str)
str
- string to escapepublic static String escapeAsBashString(String str)
str
- string to quotepublic static String escapeAsPythonString(String str)
public static String escapeAsMakefileValueString(String str)
public static String escapeWithQuotesAsMakefileValueString(String str)
public static String escapePathForCIncludeString(Path path)
Path.toString()
.path
- the Path to escapepublic static String unescapeLineMarkerPath(String escaped)
public static int decodeNumericEscape(StringBuilder out, String escaped, int pos, int maxCodeLength, int base, int maxCodes)
out
- receives decoded charactersescaped
- the string containing the escape sequencepos
- starting index of escape (but after the backslash)base
- number base, e.g. 8 for octal, or 16 for hex or unicode.maxCodes
- maximum number of sequences of escape numbers to decode. This is mainly to
support unicode escape sequences which might represent one or two characters.pos
argument.public static int decodeNumericEscape(StringBuilder out, String escaped, int pos, int maxCodeLength, int base)
decodeNumericEscape(StringBuilder, String, int, int, int, int)
to parse at most
one escaped character; i.e. calls that method with maxCodes = 1
.