本文整理匯總了Java中java.util.regex.Matcher.quoteReplacement方法的典型用法代碼示例。如果您正苦於以下問題:Java Matcher.quoteReplacement方法的具體用法?Java Matcher.quoteReplacement怎麽用?Java Matcher.quoteReplacement使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.quoteReplacement方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: executeMacro
import java.util.regex.Matcher; //導入方法依賴的package包/類
public String executeMacro(TeXParser tp, String[] args) {
String code = macrocode.get(args[0]);
String rep;
int nbargs = args.length - 11;
int dec = 0;
if (args[nbargs + 1] != null) {
dec = 1;
rep = Matcher.quoteReplacement(args[nbargs + 1]);
code = code.replaceAll("#1", rep);
} else if (macroreplacement.get(args[0]) != null) {
dec = 1;
rep = Matcher.quoteReplacement(macroreplacement.get(args[0]));
code = code.replaceAll("#1", rep);
}
for (int i = 1; i <= nbargs; i++) {
rep = Matcher.quoteReplacement(args[i]);
code = code.replaceAll("#" + (i + dec), rep);
}
return code;
}
示例2: pattern
import java.util.regex.Matcher; //導入方法依賴的package包/類
/** Return a representation of the pattern used by this instance for formatting and
* parsing. The format is similar to, but not the same as the format recognized by the
* {@link Builder#pattern} and {@link Builder#localizedPattern} methods. The pattern
* returned by this method is localized, any currency signs expressed are literally, and
* optional fractional decimal places are shown grouped in parentheses. */
public String pattern() { synchronized(numberFormat) {
StringBuilder groups = new StringBuilder();
for (int group : decimalGroups) {
groups.append("(").append(Strings.repeat("#", group)).append(")");
}
DecimalFormatSymbols s = numberFormat.getDecimalFormatSymbols();
String digit = String.valueOf(s.getDigit());
String exp = s.getExponentSeparator();
String groupSep = String.valueOf(s.getGroupingSeparator());
String moneySep = String.valueOf(s.getMonetaryDecimalSeparator());
String zero = String.valueOf(s.getZeroDigit());
String boundary = String.valueOf(s.getPatternSeparator());
String minus = String.valueOf(s.getMinusSign());
String decSep = String.valueOf(s.getDecimalSeparator());
String prefixAndNumber = "(^|" + boundary+ ")" +
"([^" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep) + "']*('[^']*')?)*" +
"[" + Matcher.quoteReplacement(digit + zero + groupSep + decSep + moneySep + exp) + "]+";
return numberFormat.toLocalizedPattern().
replaceAll(prefixAndNumber, "$0" + groups.toString()).
replaceAll("¤¤", Matcher.quoteReplacement(coinCode())).
replaceAll("¤", Matcher.quoteReplacement(coinSymbol()));
}}
示例3: expandUriComponent
import java.util.regex.Matcher; //導入方法依賴的package包/類
static String expandUriComponent(String source, UriTemplateVariables uriVariables) {
if (source == null) {
return null;
}
if (source.indexOf('{') == -1) {
return source;
}
Matcher matcher = NAMES_PATTERN.matcher(source);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String match = matcher.group(1);
String variableName = getVariableName(match);
Object variableValue = uriVariables.getValue(variableName);
if (UriTemplateVariables.SKIP_VALUE.equals(variableValue)) {
continue;
}
String variableValueString = getVariableValueAsString(variableValue);
String replacement = Matcher.quoteReplacement(variableValueString);
matcher.appendReplacement(sb, replacement);
}
matcher.appendTail(sb);
return sb.toString();
}
示例4: run
import java.util.regex.Matcher; //導入方法依賴的package包/類
public boolean run() {
String filter = arguments.getFilter();
if (filter == null) {
System.err.println("Please check your filter!");
return false;
}
String replacement = Matcher.quoteReplacement(File.separator);
String searchString = Pattern.quote(".");
filterAsPath = filter.replaceAll(searchString, replacement);
File projectFolder = getProjectFolder();
if (projectFolder.exists()) {
traverseSmaliCode(projectFolder);
return true;
} else if (isInstantRunEnabled()) {
System.err.println("Enabled Instant Run feature detected. We cannot decompile it. Please, disable Instant Run and rebuild your app.");
Messages.showInfoMessage(Strings.ERROR_INSTANT_RUN_ENABLED, Strings.TITLE_ERROR_INSTANT_RUN_ENABLED);
} else {
System.err.println("Smali folder cannot be absent!");
}
return false;
}
示例5: replaceAll
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static Integer replaceAll(Object orig_value_obj, Object repl_obj, Object ere_obj, StringBuffer sb, String convfmt) {
String orig_value = toAwkString(orig_value_obj, convfmt);
String repl = toAwkString(repl_obj, convfmt);
String ere = toAwkString(ere_obj, convfmt);
// remove special meaning for backslash and dollar signs
repl = Matcher.quoteReplacement(repl);
sb.setLength(0);
Pattern p = Pattern.compile(ere);
Matcher m = p.matcher(orig_value);
int cnt = 0;
while (m.find()) {
++cnt;
m.appendReplacement(sb, repl);
}
m.appendTail(sb);
return Integer.valueOf(cnt);
}
示例6: inject
import java.util.regex.Matcher; //導入方法依賴的package包/類
static public String inject(Matcher matcher, String injection) {
if (matcher.find()) {
injection = Matcher.quoteReplacement(injection);
StringBuffer sb = new StringBuffer();
String sub = matcher.group();
int id = matcher.start(1) - matcher.start();
String sub_start = sub.substring(0, id);
String sub_end = sub.substring(id, sub.length());
sub = sub_start + injection + sub_end;
matcher.appendReplacement(sb, sub);
matcher.appendTail(sb);
return sb.toString();
}
return null;
}
示例7: replaceFirst
import java.util.regex.Matcher; //導入方法依賴的package包/類
public static Integer replaceFirst(Object orig_value_obj, Object repl_obj, Object ere_obj, StringBuffer sb, String convfmt) {
String orig_value = toAwkString(orig_value_obj, convfmt);
String repl = toAwkString(repl_obj, convfmt);
String ere = toAwkString(ere_obj, convfmt);
// remove special meaning for backslash and dollar signs
repl = Matcher.quoteReplacement(repl);
sb.setLength(0);
sb.append(orig_value.replaceFirst(ere, repl));
if (sb.toString().equals(orig_value)) {
return ZERO;
} else {
return ONE;
}
}
示例8: shortenClassNames
import java.util.regex.Matcher; //導入方法依賴的package包/類
static String shortenClassNames(String s) {
Matcher m = Pattern.compile("<(.*?): (.*?)>").matcher(s);
if (m.find()) {
String className = m.group(1);
String shortenedClassName = shorten(className);
String replacement = '<' + shortenedClassName + ": " + m.group(2) + '>';
String escapedReplacement = Matcher.quoteReplacement(replacement);
s = m.replaceAll(escapedReplacement);
}
return s;
}
示例9: toSQL
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Returns a {@code String} with a SQL with parameters replaced with values.
*
* @since 1.1.0
* @return a {@code String} with a SQL.
*/
public String toSQL()
{
String sql = build();
for (Entry<String, Object> entry : parametersMap.entrySet())
{
String param = Matcher.quoteReplacement(entry.getKey());
sql = sql.replaceAll(":" + param + "(?=[\\s\\)])", valueToSQLString(entry.getValue()));
}
return sql;
}
示例10: relativePath
import java.util.regex.Matcher; //導入方法依賴的package包/類
private static String relativePath(Path filePath, Path modulesFolder) {
String folderString = Matcher.quoteReplacement(modulesFolder.toString() + File.separator);
return filePath.toString().replaceFirst(folderString, "").replaceFirst(".json", "")
.replace("\\", "/");
}
示例11: substitute
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* Given a static config map, substitute occurrences of ${TWISTER2_*} variables
* in the provided path string
*
* @param config a static map config object of key value pairs
* @param pathString string representing a path including ${TWISTER2_*} variables
* @return String string that represents the modified path
*/
public static String substitute(Config config, String pathString,
Map<String, ConfigEntry> substitutes) {
// trim the leading and trailing spaces
String trimmedPath = pathString.trim();
if (isURL(trimmedPath)) {
return substituteURL(config, trimmedPath, substitutes);
}
// get platform independent file separator
String fileSeparator = Matcher.quoteReplacement(File.separator);
// split the trimmed path into a list of components
List<String> fixedList = Arrays.asList(trimmedPath.split(fileSeparator));
List<String> list = new LinkedList<>(fixedList);
// substitute various variables
for (int i = 0; i < list.size(); i++) {
String elem = list.get(i);
if ("${HOME}".equals(elem) || "~".equals(elem)) {
list.set(i, System.getProperty("user.home"));
} else if ("${JAVA_HOME}".equals(elem)) {
String javaPath = System.getenv("JAVA_HOME");
if (javaPath != null) {
list.set(i, javaPath);
}
} else if (isToken(elem)) {
Matcher m = TOKEN_PATTERN.matcher(elem);
if (m.matches()) {
String token = m.group(1);
try {
ConfigEntry entry = substitutes.get(token);
if (entry == null) {
LOG.warning("We cannot find the substitution entry for token: " + token);
continue;
}
String value = config.getStringValue(entry.getKey());
if (value == null) {
throw new IllegalArgumentException(String.format("Config value %s contains "
+ "substitution token %s but the corresponding config setting %s not found",
pathString, elem, entry.getKey()));
}
list.set(i, value);
} catch (IllegalArgumentException e) {
LOG.warning(String.format("Config value %s contains substitution token %s which is "
+ "not defined in the Key enum, which is required for token substitution",
pathString, elem));
}
}
}
}
return combinePaths(list);
}
示例12: getEscapedClientCode
import java.util.regex.Matcher; //導入方法依賴的package包/類
/**
* @return the escaped class client Id formatted to be displayed on a HTML.
*/
public String getEscapedClientCode()
{
return Matcher.quoteReplacement(getClientCode());
}
示例13: renderDiffModule
import java.util.regex.Matcher; //導入方法依賴的package包/類
private String renderDiffModule(String bodyTemplate, Env env, ReleaseHistoryBO releaseHistory) {
String appId = releaseHistory.getAppId();
String namespaceName = releaseHistory.getNamespaceName();
AppNamespace appNamespace = appNamespaceService.findByAppIdAndName(appId, namespaceName);
if (appNamespace == null) {
appNamespace = appNamespaceService.findPublicAppNamespace(namespaceName);
}
//don't show diff content if namespace's format is file
if (appNamespace == null ||
!appNamespace.getFormat().equals(ConfigFileFormat.Properties.getValue())) {
return bodyTemplate.replaceAll(EMAIL_CONTENT_DIFF_MODULE, "<br><h4>變更內容請點擊鏈接到Apollo上查看</h4>");
}
ReleaseCompareResult result = getReleaseCompareResult(env, releaseHistory);
if (!result.hasContent()) {
return bodyTemplate.replaceAll(EMAIL_CONTENT_DIFF_MODULE, "<br><h4>無配置變更</h4>");
}
List<Change> changes = result.getChanges();
StringBuilder changesHtmlBuilder = new StringBuilder();
for (Change change : changes) {
String key = change.getEntity().getFirstEntity().getKey();
String oldValue = change.getEntity().getFirstEntity().getValue();
String newValue = change.getEntity().getSecondEntity().getValue();
newValue = newValue == null ? "" : newValue;
changesHtmlBuilder.append("<tr>");
changesHtmlBuilder.append("<td width=\"10%\">").append(change.getType().toString()).append("</td>");
changesHtmlBuilder.append("<td width=\"20%\">").append(cutOffString(key)).append("</td>");
changesHtmlBuilder.append("<td width=\"35%\">").append(cutOffString(oldValue)).append("</td>");
changesHtmlBuilder.append("<td width=\"35%\">").append(cutOffString(newValue)).append("</td>");
changesHtmlBuilder.append("</tr>");
}
String diffContent = Matcher.quoteReplacement(changesHtmlBuilder.toString());
String diffModuleTemplate = getDiffModuleTemplate();
String diffModuleRenderResult = diffModuleTemplate.replaceAll(EMAIL_CONTENT_FIELD_DIFF_CONTENT, diffContent);
return bodyTemplate.replaceAll(EMAIL_CONTENT_DIFF_MODULE, diffModuleRenderResult);
}
示例14: MCSubTitle
import java.util.regex.Matcher; //導入方法依賴的package包/類
public MCSubTitle(Localizer localizer, String message) {
super(localizer, Matcher.quoteReplacement(message));
}
示例15: interpolateParameter
import java.util.regex.Matcher; //導入方法依賴的package包/類
private String interpolateParameter(final Locale locale, final String message, final Parameter parameter) {
String replaceRegex = this.getInterpolationReplaceRegex(parameter.getName());
String formattedValue = Matcher.quoteReplacement(parameter.getFormattedValue(locale));
return message.replaceAll(replaceRegex, formattedValue);
}