Hopefully about to fix #46

This commit is contained in:
Norbi Peti 2016-09-25 21:54:22 +02:00
parent 85a1defb6a
commit 9e1b1152c1
2 changed files with 32 additions and 27 deletions

View file

@ -45,7 +45,8 @@ public final class ChatFormatter {
groups.add(matcher.group(i + 1)); groups.add(matcher.group(i + 1));
if (groups.size() > 0) if (groups.size() > 0)
DebugCommand.SendDebugMessage("First group: " + groups.get(0)); DebugCommand.SendDebugMessage("First group: " + groups.get(0));
FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups); FormattedSection section = new FormattedSection(formatter, matcher.start(), matcher.end() - 1, groups,
formatter.removecharcount, formatter.removecharcount, formatter.removecharpos);
sections.add(section); sections.add(section);
} }
} }
@ -74,9 +75,10 @@ public final class ChatFormatter {
origend2 = tmp; origend2 = tmp;
} }
FormattedSection section = new FormattedSection(sections.get(i - 1).Formatters, sections.get(i).Start, FormattedSection section = new FormattedSection(sections.get(i - 1).Formatters, sections.get(i).Start,
origend, sections.get(i - 1).Matches); origend, sections.get(i - 1).Matches, sections.get(i - 1).RemCharFromStart,
section.Formatters.addAll(sections.get(i).Formatters); // TODO: Process remove positions here sections.get(i - 1).RemCharFromEnd, sections.get(i - 1).RemCharPos); // TODO: RemCharPos
section.Matches.addAll(sections.get(i).Matches); section.Formatters.addAll(sections.get(i).Formatters); // TODO: Add remove counts to every part, then check if they have duplicates
section.Matches.addAll(sections.get(i).Matches); // TODO: Clean
sections.add(i, section); sections.add(i, section);
nextindex++; nextindex++;
FormattedSection thirdFormattedSection = sections.get(i + 1); FormattedSection thirdFormattedSection = sections.get(i + 1);
@ -85,6 +87,7 @@ public final class ChatFormatter {
thirdFormattedSection.Formatters.addAll(sections.get(i - 1).Formatters); thirdFormattedSection.Formatters.addAll(sections.get(i - 1).Formatters);
thirdFormattedSection.Matches.clear(); thirdFormattedSection.Matches.clear();
thirdFormattedSection.Matches.addAll(sections.get(i - 1).Matches); thirdFormattedSection.Matches.addAll(sections.get(i - 1).Matches);
thirdFormattedSection.RemCharFromEnd = sections.get(i - 1).RemCharFromEnd;
} }
thirdFormattedSection.Start = origend + 1; thirdFormattedSection.Start = origend + 1;
thirdFormattedSection.End = origend2; thirdFormattedSection.End = origend2;
@ -99,6 +102,10 @@ public final class ChatFormatter {
sections.get(i - 1).Matches.addAll(sections.get(i).Matches); sections.get(i - 1).Matches.addAll(sections.get(i).Matches);
DebugCommand.SendDebugMessage("To section " + sections.get(i - 1)); DebugCommand.SendDebugMessage("To section " + sections.get(i - 1));
sections.remove(i); sections.remove(i);
if (sections.get(i - 1).RemCharFromStart < sections.get(i).RemCharFromStart)
sections.get(i - 1).RemCharFromStart = sections.get(i).RemCharFromStart;
if (sections.get(i - 1).RemCharFromEnd < sections.get(i).RemCharFromEnd)
sections.get(i - 1).RemCharFromEnd = sections.get(i).RemCharFromEnd;
found = true; found = true;
} }
for (int j = i - 1; j <= i + 1; j++) { for (int j = i - 1; j <= i + 1; j++) {
@ -124,26 +131,11 @@ public final class ChatFormatter {
cont = false; cont = false;
} }
} }
int nextremcharpospos = 0;
for (int i = 0; i < sections.size(); i++) { for (int i = 0; i < sections.size(); i++) {
FormattedSection section = sections.get(i); FormattedSection section = sections.get(i);
DebugCommand.SendDebugMessage("Applying section: " + section); DebugCommand.SendDebugMessage("Applying section: " + section);
int nextremcharpos = -1;
if (removecharpositions.size() > nextremcharpospos)
nextremcharpos = removecharpositions.get(nextremcharpospos);
String originaltext; String originaltext;
int start = section.Start, end = section.End + 1; int start = section.Start - section.RemCharFromStart, end = section.End + 1 - section.RemCharFromEnd; // TODO: RemCharPos
DebugCommand.SendDebugMessage("Next remove char pos: " + nextremcharpos);
if (nextremcharpos == section.Start) {
start++;
nextremcharpospos++;
if (removecharpositions.size() > nextremcharpospos)
nextremcharpos = removecharpositions.get(nextremcharpospos); // TODO: Section.RemoveCharCountStart/End
}
if (nextremcharpos == section.End) {
end--;
nextremcharpospos++;
}
originaltext = str.substring(start, end); originaltext = str.substring(start, end);
DebugCommand.SendDebugMessage("Originaltext: " + originaltext); DebugCommand.SendDebugMessage("Originaltext: " + originaltext);
Color color = null; Color color = null;

View file

@ -4,28 +4,41 @@ import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
class FormattedSection { class FormattedSection {
public int Start; int Start;
public int End; int End;
public ArrayList<ChatFormatter> Formatters = new ArrayList<ChatFormatter>(); ArrayList<ChatFormatter> Formatters = new ArrayList<ChatFormatter>();
public ArrayList<String> Matches = new ArrayList<String>(); ArrayList<String> Matches = new ArrayList<String>();
short RemCharFromStart;
short RemCharFromEnd;
int RemCharPos;
public FormattedSection(ChatFormatter formatter, int start, int end, ArrayList<String> matches) { FormattedSection(ChatFormatter formatter, int start, int end, ArrayList<String> matches, short remcharfromstart,
short remcharfromend, int remcharpos) {
Start = start; Start = start;
End = end; End = end;
Formatters.add(formatter); Formatters.add(formatter);
Matches.addAll(matches); Matches.addAll(matches);
RemCharFromStart = remcharfromstart;
RemCharFromEnd = remcharfromend;
RemCharPos = remcharpos;
} }
public FormattedSection(Collection<ChatFormatter> formatters, int start, int end, ArrayList<String> matches) { FormattedSection(Collection<ChatFormatter> formatters, int start, int end, ArrayList<String> matches,
short remcharfromstart, short remcharfromend, int remcharpos) {
Start = start; Start = start;
End = end; End = end;
Formatters.addAll(formatters); Formatters.addAll(formatters);
Matches.addAll(matches); Matches.addAll(matches);
RemCharFromStart = remcharfromstart;
RemCharFromEnd = remcharfromend;
RemCharPos = remcharpos;
} }
@Override @Override
public String toString() { public String toString() {
return new StringBuilder("Section(").append(Start).append(", ").append(End).append(", formatters: ") return new StringBuilder("Section(").append(Start).append(", ").append(End).append(", formatters: ")
.append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append(")").toString(); .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append("RemChars: ")
.append(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(RemCharPos)
.append(")").toString();
} }
} }