Commit be25a432 by 段启岩

动态删除行为换行

parent 393baa72
...@@ -23,9 +23,13 @@ public class TopicUtils { ...@@ -23,9 +23,13 @@ public class TopicUtils {
private static final Pattern delayPattern = Pattern.compile("(delay\\((\\d+)\\);)$"); private static final Pattern delayPattern = Pattern.compile("(delay\\((\\d+)\\);)$");
private static final Pattern tailLFPattern = Pattern.compile("(\n+)$");
public static String encodeTopic(String str) { public static String encodeTopic(String str) {
Assert.hasText(str, "str must not be empty"); Assert.hasText(str, "str must not be empty");
str = str.replaceAll(tailLFPattern.pattern(), "");
Matcher matcher = topicPattern.matcher(str); Matcher matcher = topicPattern.matcher(str);
StringBuffer buffer = new StringBuffer(); StringBuffer buffer = new StringBuffer();
...@@ -66,6 +70,7 @@ public class TopicUtils { ...@@ -66,6 +70,7 @@ public class TopicUtils {
} }
public static Integer getDelay(String str) { public static Integer getDelay(String str) {
str = str.replaceAll(tailLFPattern.pattern(), "");
Matcher matcher = delayPattern.matcher(str); Matcher matcher = delayPattern.matcher(str);
if (matcher.find()) { if (matcher.find()) {
return Integer.valueOf(matcher.group(2)); return Integer.valueOf(matcher.group(2));
...@@ -76,7 +81,7 @@ public class TopicUtils { ...@@ -76,7 +81,7 @@ public class TopicUtils {
public static void main(String[] args) { public static void main(String[] args) {
// System.out.println(TopicUtils.parseTopics("#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######")); // System.out.println(TopicUtils.parseTopics("#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######"));
System.out.println(TopicUtils.encodeTopic("#哈哈哈#今#哈哈delay(5);哈#天你吃饭了吗#吃了#######哈哈#a#bdelay(5);")); System.out.println(TopicUtils.encodeTopic("\n\n#哈哈哈#今#哈哈delay(5);哈#天你吃饭了吗#吃了#######哈哈#a#bdelay(5);\n\n"));
System.out.println(TopicUtils.getDelay("#哈哈哈#今#哈哈delay(5);哈#天你吃饭了吗#吃了#######哈哈#a#bdelay(5);")); System.out.println(TopicUtils.getDelay("#哈哈哈#今#哈哈delay(5);哈#天你吃饭了吗#吃了#######哈哈#a#bdelay(5);"));
// System.out.println(TopicUtils.clearLockedTopics("#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######哈哈#a#b", List.of("哈哈哈"))); // System.out.println(TopicUtils.clearLockedTopics("#哈哈哈#今#哈哈哈#天你吃饭了吗#吃了#######哈哈#a#b", List.of("哈哈哈")));
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment