本文整理匯總了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();
}