本文整理汇总了Java中com.google.re2j.Matcher.appendTail方法的典型用法代码示例。如果您正苦于以下问题:Java Matcher.appendTail方法的具体用法?Java Matcher.appendTail怎么用?Java Matcher.appendTail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.re2j.Matcher
的用法示例。
在下文中一共展示了Matcher.appendTail方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: run
import com.google.re2j.Matcher; //导入方法依赖的package包/类
private Set<FileState> run(Iterable<FileState> files, Console console) throws IOException, ValidationException {
Set<FileState> modifiedFiles = new HashSet<>();
// TODO(malcon): Remove reconstructing pattern once RE2J doesn't synchronize on matching.
Pattern batchPattern = Pattern.compile(pattern.pattern(), pattern.flags());
for (FileState file : files) {
if (Files.isSymbolicLink(file.getPath())) {
continue;
}
String content = new String(Files.readAllBytes(file.getPath()), UTF_8);
Matcher matcher = batchPattern.matcher(content);
StringBuffer sb = new StringBuffer();
boolean modified = false;
while (matcher.find()) {
List<String> users = Splitter.on(",").splitToList(matcher.group(2));
List<String> mappedUsers = mapUsers(users, matcher.group(0), file.getPath(), console);
modified |= !users.equals(mappedUsers);
String result = matcher.group(1);
if (!mappedUsers.isEmpty()) {
result += "(" + Joiner.on(",").join(mappedUsers) + ")";
}
matcher.appendReplacement(sb, result);
}
matcher.appendTail(sb);
if (modified) {
modifiedFiles.add(file);
Files.write(file.getPath(), sb.toString().getBytes(UTF_8));
}
}
return modifiedFiles;
}
示例2: build
import com.google.re2j.Matcher; //导入方法依赖的package包/类
/**
* Returns the freshly substituted SQL code.
*
* @throws IllegalArgumentException if any substitution variable is not found in the template,
* or if there are any variable-like strings (%something%) left after substitution.
*/
public String build() {
StringBuffer result = new StringBuffer(template.length());
Set<String> found = new HashSet<>();
Matcher matcher = SEARCH_PATTERN.matcher(template);
while (matcher.find()) {
String wholeMatch = matcher.group(0);
String leftQuote = matcher.group(1);
String key = matcher.group(2);
String rightQuote = matcher.group(3);
String value = substitutions.get(key);
checkArgumentNotNull(value, "%%s% found in template but no substitution specified", key);
checkArgument(leftQuote.equals(rightQuote), "Quote mismatch: %s", wholeMatch);
matcher.appendReplacement(result, String.format("%s%s%s", leftQuote, value, rightQuote));
found.add(key);
}
matcher.appendTail(result);
Set<String> remaining = difference(substitutions.keySet(), found);
checkArgument(remaining.isEmpty(),
"Not found in template: %s", Joiner.on(", ").join(remaining));
return result.toString();
}
示例3: replaceLine
import com.google.re2j.Matcher; //导入方法依赖的package包/类
private String replaceLine(String line) {
if (patternsToIgnore != null) {
for (Pattern patternToIgnore : patternsToIgnore) {
if (patternToIgnore.matches(line)) {
return line;
}
}
}
Matcher matcher = before.matcher(line);
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
for (Collection<Integer> groupIndexes : repeatedGroups.asMap().values()) {
// Check that all the references of the repeated group match the same string
Iterator<Integer> iterator = groupIndexes.iterator();
String value = matcher.group(iterator.next());
while (iterator.hasNext()) {
if (!value.equals(matcher.group(iterator.next()))) {
return line;
}
}
}
String replaceTemplate;
if (callback != null) {
ImmutableMap.Builder<Integer, String> groupValues =
ImmutableMap.builder();
for (int i = 0; i <= matcher.groupCount(); i++) {
groupValues.put(i, matcher.group(i));
}
replaceTemplate = callback.alter(groupValues.build(), afterReplaceTemplate);
} else {
replaceTemplate = afterReplaceTemplate;
}
matcher.appendReplacement(sb, replaceTemplate);
if (firstOnly) {
break;
}
}
matcher.appendTail(sb);
return sb.toString();
}