1
mirror of https://github.com/CarmJos/EasyConfiguration.git synced 2026-06-04 18:48:20 +08:00

fix: Try to ignore errors when applying replacer

This commit is contained in:
2025-10-09 02:58:21 +08:00
parent fdb6d81bf0
commit d6fa7710dc
2 changed files with 9 additions and 3 deletions
@@ -39,7 +39,8 @@ public abstract class ContentInserter<RECEIVER> implements Comparable<ContentIns
@NotNull Insertable<RECEIVER, ?> insertions) { @NotNull Insertable<RECEIVER, ?> insertions) {
Matcher matcher = matcher(line); Matcher matcher = matcher(line);
if (!matcher.matches()) return null; if (!matcher.matches()) return null;
if (!insertions.inserting(extractID(matcher))) return Collections.emptyList(); String id = extractID(matcher);
if (id == null || !insertions.inserting(id)) return Collections.emptyList();
return get(receiver, matcher, insertions); return get(receiver, matcher, insertions);
} }
@@ -47,8 +47,13 @@ public abstract class ContentReplacer<RECEIVER> implements Comparable<ContentRep
Matcher matcher = matcher(text); Matcher matcher = matcher(text);
StringBuffer sb = new StringBuffer(); StringBuffer sb = new StringBuffer();
while (matcher.find()) { while (matcher.find()) {
try {
String replaced = get(receiver, matcher); String replaced = get(receiver, matcher);
matcher.appendReplacement(sb, replaced == null ? "" : replaced); matcher.appendReplacement(sb, replaced == null ? "" : replaced);
} catch (Exception ex) {
// Do nothing if exception occurred.
ex.printStackTrace(); // for debug
}
} }
matcher.appendTail(sb); matcher.appendTail(sb);
return sb.toString(); return sb.toString();