本文整理汇总了Java中java.util.regex.Matcher.appendTail方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.appendTail方法的具体用法?Java Matcher.appendTail怎么用?Java Matcher.appendTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.util.regex.Matcher
的用法示例。
在下文中一共展示了Matcher.appendTail方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkTags
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String checkTags(String s) {
Matcher m = P_TAGS.matcher(s);
final StringBuffer buf = new StringBuffer();
while (m.find()) {
String replaceStr = m.group(1);
replaceStr = processTag(replaceStr);
m.appendReplacement(buf, Matcher.quoteReplacement(replaceStr));
}
m.appendTail(buf);
s = buf.toString();
// these get tallied in processTag
// (remember to reset before subsequent calls to filter method)
for (String key : vTagCounts.keySet()) {
for (int ii = 0; ii < vTagCounts.get(key); ii++) {
s += "</" + key + ">";
}
}
return s;
}
示例2: map
import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String map(String entry) {
for (Map.Entry<Pattern, String> replacement : replacements.entrySet()) {
Matcher matcher = replacement.getKey().matcher(entry);
String value = replacement.getValue();
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, value);
}
matcher.appendTail(sb);
if (sb.length() > 0) {
entry = sb.toString();
}
}
return entry;
}
示例3: replaceParameter
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 替换url中参数的值。
*/
public static String replaceParameter(String query, String key, String value) {
if (query == null || query.length() == 0) {
return key + "=" + value;
}
if (query.indexOf(key + "=") == -1) {
return query + "&" + key + "=" + value;
}
Pattern pattern = REPLACE_PARAMETER_PATTERNS.get(key);
if (pattern == null) {
pattern = Pattern.compile(key.replaceAll("([^(_0-9A-Za-z)])", "\\\\$0") + "=[^&]+");
}
Matcher matcher = pattern.matcher(query);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, (key + "=" + value).replace("$", "\\$"));
}
matcher.appendTail(sb);
return sb.toString();
}
示例4: resolveLinks
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String resolveLinks(RichTextElement element) {
if (element.links == null) {
return element.getValue();
}
Matcher matcher = linkPattern.matcher(element.getValue());
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
Link link = element.links.get(matcher.group("id"));
String url = "";
if (link != null && contentLinkUrlResolver != null) {
url = contentLinkUrlResolver.resolveLinkUrl(link);
} else if (brokenLinkUrlResolver != null){
url = brokenLinkUrlResolver.resolveBrokenLinkUrl();
}
matcher.appendReplacement(buffer, resolveMatch(matcher.group(0), url));
}
matcher.appendTail(buffer);
return buffer.toString();
}
示例5: readWithReplace
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Reads a string from the given file, replacing instances of $(path) with the contents of the file at that path.
* Must be cycle-free to terminate.
* $(path) entries in referenced files are handled recursively,
* the path always being relative to the referencing file.
* @param path the path of the root file
* @return a string where all occurrences of $(...) have been replaced recursively
* @throws IOException if any one file could not be read
*/
public static String readWithReplace(String path) throws IOException {
String text = readString(path);
Matcher m = pattern.matcher(text);
StringBuffer result = new StringBuffer();
File file = new File(path).getAbsoluteFile();
String subPath = "";
while(m.find()){
try {
subPath = file.getParent() + "/" + m.group(1);
m.appendReplacement(result, readWithReplace(subPath));
} catch(NullPointerException e){
e.printStackTrace();
Log.log(Log.Level.ERROR, "Could not insert file " + subPath + " into " + path);
}
}
m.appendTail(result);
return result.toString();
}
示例6: replaceParameter
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 替换url中参数的值。
*/
public static String replaceParameter(String query, String key, String value) {
if (query == null || query.length() == 0) {
return key + "=" + value;
}
if (query.indexOf(key + "=") == -1) {
return query + "&" + key + "=" + value;
}
Pattern pattern = REPLACE_PARAMETER_PATTERNS.get(key);
if (pattern == null) {
pattern = Pattern.compile(key.replaceAll("([^(_0-9A-Za-z)])", "\\\\$0") + "=[^&]+");
}
Matcher matcher = pattern.matcher(query);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, (key + "=" + value).replace("$", "\\$"));
}
matcher.appendTail(sb);
return sb.toString();
}
示例7: interpolate
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 执行interpolation(变量插入)。
*
* @param expression 含有变量的表达式字符串。表达式中的变量名也可以用<code>{}</code>括起来。
* @param params 变量集。变量名可以包含<code>.</code>、<code>_</code>字符。
* @return 完成interpolation后的字符串。 如:<code><pre>xxx${name}zzz -> xxxjerryzzz</pre></code>(其中变量name="jerry")
* @throws IllegalStateException 表达式字符串中使用到的变量 在变量集中没有
*/
// FIMXE 抛出IllegalStateException异常,是否合适?!
public static String interpolate(String expression, Map<String, String> params) {
if (expression == null || expression.length() == 0) {
throw new IllegalArgumentException("glob pattern is empty!");
}
if (expression.indexOf('$') < 0) {
return expression;
}
Matcher matcher = VARIABLE_PATTERN.matcher(expression);
StringBuffer sb = new StringBuffer();
while (matcher.find()) { // 逐个匹配
String key = matcher.group(1);
String value = params == null ? null: params.get(key);
if (value == null) {
value = "";
}
matcher.appendReplacement(sb, value);
}
matcher.appendTail(sb);
return sb.toString();
}
示例8: escapeString
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* Escape string suitable for display in a tree
* @param string the raw string
* @return the escaped string
*/
public static String escapeString(final String string) {
final Matcher match = CTRL_CHR.matcher(string);
final StringBuffer sb = new StringBuffer();
while (match.find()) {
int cp = match.group().codePointAt(0);
match.appendReplacement(sb, String.format("\\\\%02X", cp));
}
match.appendTail(sb);
return sb.toString();
}
示例9: format
import java.util.regex.Matcher; //导入方法依赖的package包/类
@Override
public String format(String str, Object... args) throws IllegalFormatException
{
final int RULE_BEGIN_INDEX = 1;
// Apply rule pattern to input string to
// find inline matches
Matcher matcher = RULE_PATTERN.matcher(str);
// Formatted string buffer
StringBuffer formatBuffer = new StringBuffer();
// Find all inline rules within the input string
for (int i = 0; matcher.find() && i < args.length; ++i)
{
// Remove $ from the matched rule string
String rule = matcher.group().substring(RULE_BEGIN_INDEX);
Object arg = args[i];
// Format the specified rule according to given specifications
String replacement = FORMAT_SPEC.applyRule(rule, arg);
// Ensure replacement string is converted into literal
// string (ensure \ and $ characters are treated correctly)
matcher.appendReplacement(formatBuffer, Matcher.quoteReplacement(replacement));
}
matcher.appendTail(formatBuffer);
return formatBuffer.toString();
}
示例10: removeQuotes
import java.util.regex.Matcher; //导入方法依赖的package包/类
public static String removeQuotes(String input) {
Pattern compile = Pattern.compile("\"([A-Z_0-9]+)\"", Pattern.DOTALL);
StringBuffer sb = new StringBuffer(input.length());
Matcher matcher = compile.matcher(input);
while (matcher.find()) {
matcher.appendReplacement(sb, matcher.group(1));
}
matcher.appendTail(sb);
return sb.toString();
}
示例11: escapeComments
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String escapeComments(final String s) {
final Matcher m = P_COMMENTS.matcher(s);
final StringBuffer buf = new StringBuffer();
if (m.find()) {
final String match = m.group(1); //(.*?)
m.appendReplacement(buf, Matcher.quoteReplacement("<!--" + htmlSpecialChars(match) + "-->"));
}
m.appendTail(buf);
return buf.toString();
}
示例12: getEmotion
import java.util.regex.Matcher; //导入方法依赖的package包/类
private String getEmotion(String var1) {
Pattern var2 = Pattern.compile("\\[/u([0-9A-Fa-f]+)\\]");
Matcher var3 = var2.matcher(var1);
StringBuffer var4 = new StringBuffer();
while (var3.find()) {
int var5 = Integer.parseInt(var3.group(1), 16);
var3.appendReplacement(var4, String.valueOf(Character.toChars(var5)));
}
var3.appendTail(var4);
return var4.toString();
}
示例13: cleanTextForSearchingQuery
import java.util.regex.Matcher; //导入方法依赖的package包/类
@NonNull
public static String cleanTextForSearchingQuery(String s) {
Matcher matcher = SPACE_REPLACED_PATTERN.matcher(s);
String space_replaced = matcher.replaceAll(" ");
Matcher matcher1 = REMOVE_PATTERN.matcher(space_replaced);
String removed = matcher1.replaceAll("");
Matcher matcher2 = REMOVE_REPEATED_SPACES.matcher(removed);
String removed_duplicat_spaces = matcher2.replaceAll(" ");
Matcher equivlanceMatcher = equvilancePattern.matcher(removed_duplicat_spaces);
StringBuffer sb = new StringBuffer();
while (equivlanceMatcher.find()) {
switch (equivlanceMatcher.group(0)) {
case DOTLESS_YEH_STR:
equivlanceMatcher.appendReplacement(sb, YEH_STR);
break;
case ALEF_MADDA_str:
case ALEF_HAMZA_ABOVE_str:
case ALEF_HAMZA_BELOW_STR:
equivlanceMatcher.appendReplacement(sb, ALEF_str);
break;
case TEH_MARBUTA_STR:
equivlanceMatcher.appendReplacement(sb, HEH_STR);
}
}
equivlanceMatcher.appendTail(sb);
return handleTatweela(sb.toString());
}
示例14: humpToLine2
import java.util.regex.Matcher; //导入方法依赖的package包/类
/**
* 驼峰转下划线,效率比上面高
* @param str
* @return
*/
public static String humpToLine2(String str) {
Matcher matcher = humpPattern.matcher(str);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
matcher.appendReplacement(sb, "_" + matcher.group(0).toLowerCase());
}
matcher.appendTail(sb);
return sb.toString();
}
示例15: appendTail
import java.util.regex.Matcher; //导入方法依赖的package包/类
public static void appendTail(Matcher matcher, Node node) {
StringBuffer buffer = new StringBuffer();
matcher.appendTail(buffer);
if (buffer.length() != 0)
node.before(new TextNode(buffer.toString(), node.baseUri()));
node.remove();
}