Getting closer. Also added toString methods.
This commit is contained in:
parent
5442b41528
commit
12963b58cb
2 changed files with 50 additions and 27 deletions
Binary file not shown.
|
@ -78,6 +78,7 @@ public final class ChatFormatter {
|
||||||
while (matcher.find()) {
|
while (matcher.find()) {
|
||||||
System.out.println("Found match from " + matcher.start()
|
System.out.println("Found match from " + matcher.start()
|
||||||
+ " to " + (matcher.end() - 1));
|
+ " to " + (matcher.end() - 1));
|
||||||
|
System.out.println("With formatter:" + formatter);
|
||||||
ArrayList<String> groups = new ArrayList<String>();
|
ArrayList<String> groups = new ArrayList<String>();
|
||||||
for (int i = 0; i < matcher.groupCount(); i++)
|
for (int i = 0; i < matcher.groupCount(); i++)
|
||||||
groups.add(matcher.group(i + 1));
|
groups.add(matcher.group(i + 1));
|
||||||
|
@ -101,15 +102,18 @@ public final class ChatFormatter {
|
||||||
if (sections.size() < 2)
|
if (sections.size() < 2)
|
||||||
break;
|
break;
|
||||||
System.out.println("i: " + i);
|
System.out.println("i: " + i);
|
||||||
if (sections.get(i - 1).End >= sections.get(i).Start) {
|
if (sections.get(i - 1).End > sections.get(i).Start
|
||||||
System.out.println("Combining sections ("
|
&& sections.get(i - 1).Start < sections.get(i).End) {
|
||||||
+ sections.get(i - 1).Start + " - "
|
System.out.println("Combining sections " + sections.get(i - 1)
|
||||||
+ sections.get(i - 1).End + ") and ("
|
+ " and " + sections.get(i));
|
||||||
+ sections.get(i).Start + " - " + sections.get(i).End
|
|
||||||
+ ")");
|
|
||||||
int origend = sections.get(i - 1).End;
|
int origend = sections.get(i - 1).End;
|
||||||
sections.get(i - 1).End = sections.get(i).Start - 1;
|
sections.get(i - 1).End = sections.get(i).Start - 1;
|
||||||
|
int origend2 = sections.get(i).End;
|
||||||
|
if (origend2 < origend) {
|
||||||
|
int tmp = origend; // TODO: This is BAD
|
||||||
|
origend = origend2; // The third part always gets the
|
||||||
|
origend2 = tmp; // properties of the second one
|
||||||
|
}
|
||||||
FormattedSection section = sections.get(i - 1).Formatters
|
FormattedSection section = sections.get(i - 1).Formatters
|
||||||
.get(0).new FormattedSection(
|
.get(0).new FormattedSection(
|
||||||
sections.get(i - 1).Formatters, sections.get(i).Start,
|
sections.get(i - 1).Formatters, sections.get(i).Start,
|
||||||
|
@ -119,20 +123,28 @@ public final class ChatFormatter {
|
||||||
sections.add(i, section);
|
sections.add(i, section);
|
||||||
nextindex++;
|
nextindex++;
|
||||||
sections.get(i + 1).Start = origend + 1;
|
sections.get(i + 1).Start = origend + 1;
|
||||||
System.out.println("To sections 1:("
|
sections.get(i + 1).End = origend2;
|
||||||
+ sections.get(i - 1).Start + " - "
|
System.out.println("To sections 1:" + sections.get(i - 1) + "");
|
||||||
+ sections.get(i - 1).End + ")");
|
System.out.println(" 2:" + section + "");
|
||||||
System.out.println(" 2:(" + section.Start + " - "
|
System.out.println(" 3:" + sections.get(i + 1));
|
||||||
+ section.End + ")");
|
|
||||||
System.out.println(" 3:(" + sections.get(i + 1).Start + " - "
|
|
||||||
+ sections.get(i + 1).End + ")");
|
|
||||||
found = true;
|
found = true;
|
||||||
}
|
}
|
||||||
if (sections.get(i - 1).Start == sections.get(i).Start
|
if (sections.get(i - 1).Start == sections.get(i).Start
|
||||||
&& sections.get(i - 1).End == sections.get(i).End) {
|
&& sections.get(i - 1).End == sections.get(i).End) {
|
||||||
|
System.out.println("Combining sections " + sections.get(i - 1)
|
||||||
|
+ " and " + sections.get(i));
|
||||||
sections.get(i - 1).Formatters
|
sections.get(i - 1).Formatters
|
||||||
.addAll(sections.get(i).Formatters);
|
.addAll(sections.get(i).Formatters);
|
||||||
sections.get(i - 1).Matches.addAll(sections.get(i).Matches);
|
sections.get(i - 1).Matches.addAll(sections.get(i).Matches);
|
||||||
|
System.out.println("To section " + sections.get(i - 1));
|
||||||
|
sections.remove(i);
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
if (i < sections.size()
|
||||||
|
&& sections.get(i).End < sections.get(i).Start) {
|
||||||
|
System.out.println("Removing section: " + sections.get(i));
|
||||||
|
sections.remove(i);
|
||||||
|
found = true;
|
||||||
}
|
}
|
||||||
i = nextindex - 1;
|
i = nextindex - 1;
|
||||||
i++;
|
i++;
|
||||||
|
@ -140,25 +152,23 @@ public final class ChatFormatter {
|
||||||
if (found) {
|
if (found) {
|
||||||
i = 1;
|
i = 1;
|
||||||
found = false;
|
found = false;
|
||||||
|
sections.sort((s1, s2) -> {
|
||||||
|
if (s1.Start == s2.Start)
|
||||||
|
return Integer.compare(s1.End, s2.End);
|
||||||
|
else
|
||||||
|
return Integer.compare(s1.Start, s2.Start);
|
||||||
|
});
|
||||||
} else
|
} else
|
||||||
cont = false;
|
cont = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
StringBuilder finalstring = new StringBuilder();
|
StringBuilder finalstring = new StringBuilder();
|
||||||
for (int i = 0; i < sections.size(); i++) {
|
for (int i = 0; i < sections.size(); i++) {
|
||||||
if (sections.get(i).End < sections.get(i).Start) {
|
|
||||||
System.out.println("Removing section: " + sections.get(i).Start
|
|
||||||
+ " - " + sections.get(i).End);
|
|
||||||
sections.remove(i);
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
FormattedSection section = sections.get(i);
|
FormattedSection section = sections.get(i);
|
||||||
System.out.println("Applying section: " + section.Start + " - "
|
System.out.println("Applying section: " + section);
|
||||||
+ section.End);
|
|
||||||
String originaltext = str.substring(section.Start, section.End + 1);
|
String originaltext = str.substring(section.Start, section.End + 1);
|
||||||
System.out.println("Originaltext: " + originaltext);
|
System.out.println("Originaltext: " + originaltext);
|
||||||
finalstring.append(",{\"text\":\""); //TODO: Bool replace
|
finalstring.append(",{\"text\":\""); // TODO: Bool replace
|
||||||
finalstring.append(originaltext);
|
finalstring.append(originaltext);
|
||||||
finalstring.append("\"");
|
finalstring.append("\"");
|
||||||
Color color = null;
|
Color color = null;
|
||||||
|
@ -166,9 +176,7 @@ public final class ChatFormatter {
|
||||||
String openlink = null;
|
String openlink = null;
|
||||||
Priority priority = null;
|
Priority priority = null;
|
||||||
for (ChatFormatter formatter : section.Formatters) {
|
for (ChatFormatter formatter : section.Formatters) {
|
||||||
System.out.println("Applying formatter: Color: "
|
System.out.println("Applying formatter: " + formatter);
|
||||||
+ formatter.color + " Format: " + formatter.format
|
|
||||||
+ " Openlink: " + formatter.openlink);
|
|
||||||
if (formatter.onmatch == null
|
if (formatter.onmatch == null
|
||||||
|| formatter.onmatch.test(originaltext)) {
|
|| formatter.onmatch.test(originaltext)) {
|
||||||
if (priority == null
|
if (priority == null
|
||||||
|
@ -208,6 +216,13 @@ public final class ChatFormatter {
|
||||||
return finalstring.toString(); // TODO
|
return finalstring.toString(); // TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new StringBuilder("F(").append(color).append(", ")
|
||||||
|
.append(format).append(", ").append(openlink).append(", ")
|
||||||
|
.append(priority).append(")").toString();
|
||||||
|
}
|
||||||
|
|
||||||
public enum Format { // TODO: Flag?
|
public enum Format { // TODO: Flag?
|
||||||
Bold("bold"), Underlined("underlined"), Italic("italic"), Strikethrough(
|
Bold("bold"), Underlined("underlined"), Italic("italic"), Strikethrough(
|
||||||
"strikethrough"), Obfuscated("obfuscated");
|
"strikethrough"), Obfuscated("obfuscated");
|
||||||
|
@ -275,5 +290,13 @@ public final class ChatFormatter {
|
||||||
Formatters.addAll(formatters);
|
Formatters.addAll(formatters);
|
||||||
Matches.addAll(matches);
|
Matches.addAll(matches);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return new StringBuilder("Section(").append(Start).append(", ")
|
||||||
|
.append(End).append(", formatters: ")
|
||||||
|
.append(Formatters.toString()).append(", matches: ")
|
||||||
|
.append(Matches.toString()).append(")").toString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue