Removed RemCharPos, wasn't used

It was only used for escaping before
This commit is contained in:
Norbi Peti 2017-06-08 23:36:37 +02:00
parent 3e1df267cf
commit bcd6d3f194
3 changed files with 8 additions and 45 deletions

View file

@ -1,7 +1,6 @@
package buttondevteam.chat.formatting; package buttondevteam.chat.formatting;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -25,12 +24,11 @@ public final class ChatFormatter {
private String openlink; private String openlink;
private Priority priority; private Priority priority;
private short removecharcount = 0; private short removecharcount = 0;
private short removecharpos = -1;
private boolean isrange; private boolean isrange;
public ChatFormatter(Pattern regex, boolean italic, boolean bold, boolean underlined, boolean strikethrough, public ChatFormatter(Pattern regex, boolean italic, boolean bold, boolean underlined, boolean strikethrough,
boolean obfuscated, Color color, Function<String, String> onmatch, String openlink, Priority priority, boolean obfuscated, Color color, Function<String, String> onmatch, String openlink, Priority priority,
short removecharcount, short removecharpos, boolean isrange) { short removecharcount, boolean isrange) {
super(); super();
this.regex = regex; this.regex = regex;
this.italic = italic; this.italic = italic;
@ -46,7 +44,6 @@ public final class ChatFormatter {
else else
this.priority = priority; this.priority = priority;
this.removecharcount = removecharcount; this.removecharcount = removecharcount;
this.removecharpos = removecharpos;
this.isrange = isrange; this.isrange = isrange;
} }
@ -66,8 +63,7 @@ public final class ChatFormatter {
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, formatter.removecharcount, formatter.removecharcount, formatter.isrange);
formatter.isrange);
sections.add(section); sections.add(section);
} }
} }
@ -141,7 +137,6 @@ public final class ChatFormatter {
firstSection.RemCharFromStart = sections.get(i).RemCharFromStart; firstSection.RemCharFromStart = sections.get(i).RemCharFromStart;
if (firstSection.RemCharFromEnd < sections.get(i).RemCharFromEnd) if (firstSection.RemCharFromEnd < sections.get(i).RemCharFromEnd)
firstSection.RemCharFromEnd = sections.get(i).RemCharFromEnd; firstSection.RemCharFromEnd = sections.get(i).RemCharFromEnd;
firstSection.RemCharPos.addAll(sections.get(i).RemCharPos);
DebugCommand.SendDebugMessage("To section " + firstSection); DebugCommand.SendDebugMessage("To section " + firstSection);
sections.remove(i); sections.remove(i);
found = true; found = true;
@ -156,8 +151,7 @@ public final class ChatFormatter {
origend2 = tmp; origend2 = tmp;
} }
FormattedSection section = new FormattedSection(firstSection.Formatters, sections.get(i).Start, origend, FormattedSection section = new FormattedSection(firstSection.Formatters, sections.get(i).Start, origend,
firstSection.Matches, sections.get(i).RemCharFromStart, firstSection.RemCharFromEnd, firstSection.Matches, sections.get(i).RemCharFromStart, firstSection.RemCharFromEnd, false);
Collections.emptyList(), false);
section.Formatters.addAll(sections.get(i).Formatters); section.Formatters.addAll(sections.get(i).Formatters);
section.Matches.addAll(sections.get(i).Matches); // TODO: Clean section.Matches.addAll(sections.get(i).Matches); // TODO: Clean
sections.add(i, section); sections.add(i, section);
@ -176,16 +170,6 @@ public final class ChatFormatter {
thirdFormattedSection.RemCharFromStart = 0; thirdFormattedSection.RemCharFromStart = 0;
thirdFormattedSection.Start = origend + 1; thirdFormattedSection.Start = origend + 1;
thirdFormattedSection.End = origend2; thirdFormattedSection.End = origend2;
for (int x = 0; x < firstSection.RemCharPos.size(); x++) {
if (firstSection.RemCharPos.get(x) > firstSection.End) {
if (firstSection.RemCharPos.get(x) > section.End)
thirdFormattedSection.RemCharPos.add(
firstSection.RemCharPos.get(x) - thirdFormattedSection.Start + firstSection.Start);
else
section.RemCharPos.add(firstSection.RemCharPos.get(x) - section.Start + firstSection.Start);
firstSection.RemCharPos.remove(x--);
}
}
DebugCommand.SendDebugMessage("To sections 1:" + firstSection + ""); DebugCommand.SendDebugMessage("To sections 1:" + firstSection + "");
DebugCommand.SendDebugMessage(" 2:" + section + ""); DebugCommand.SendDebugMessage(" 2:" + section + "");
DebugCommand.SendDebugMessage(" 3:" + thirdFormattedSection); DebugCommand.SendDebugMessage(" 3:" + thirdFormattedSection);
@ -220,9 +204,6 @@ public final class ChatFormatter {
String originaltext; String originaltext;
int start = section.Start + section.RemCharFromStart, end = section.End + 1 - section.RemCharFromEnd; // TODO: RemCharPos int start = section.Start + section.RemCharFromStart, end = section.End + 1 - section.RemCharFromEnd; // TODO: RemCharPos
StringBuilder textsb = new StringBuilder(str.substring(start, end)); StringBuilder textsb = new StringBuilder(str.substring(start, end));
for (int x = 0; x < section.RemCharPos.size(); x++)
if (section.RemCharPos.get(x) != -1)
textsb.deleteCharAt(section.RemCharPos.get(x));
originaltext = textsb.toString(); originaltext = textsb.toString();
DebugCommand.SendDebugMessage("Section text: " + originaltext); DebugCommand.SendDebugMessage("Section text: " + originaltext);
Color color = null; Color color = null;

View file

@ -17,12 +17,11 @@ public class ChatFormatterBuilder {
private String openlink; private String openlink;
private Priority priority; private Priority priority;
private short removecharcount = 0; private short removecharcount = 0;
private short removecharpos = -1;
private boolean range = false; private boolean range = false;
public ChatFormatter build() { public ChatFormatter build() {
return new ChatFormatter(regex, italic, bold, underlined, strikethrough, obfuscated, color, onmatch, openlink, return new ChatFormatter(regex, italic, bold, underlined, strikethrough, obfuscated, color, onmatch, openlink,
priority, removecharcount, removecharpos, range); priority, removecharcount, range);
} }
public Pattern getRegex() { public Pattern getRegex() {
@ -129,20 +128,6 @@ public class ChatFormatterBuilder {
return this; return this;
} }
public short getRemoveCharPos() {
return removecharpos;
}
/**
* Sets the position where a single character should be removed. Setting -1 will disable it.
*
* @return This instance
*/
public ChatFormatterBuilder setRemoveCharPos(short removecharpos) {
this.removecharpos = removecharpos;
return this;
}
public boolean isRange() { public boolean isRange() {
return range; return range;
} }

View file

@ -10,33 +10,30 @@ class FormattedSection {
ArrayList<String> Matches = new ArrayList<String>(); ArrayList<String> Matches = new ArrayList<String>();
short RemCharFromStart; short RemCharFromStart;
short RemCharFromEnd; short RemCharFromEnd;
ArrayList<Integer> RemCharPos = new ArrayList<Integer>();
/** /**
* Is it a 1-long section indicating a start or an end * Is it a 1-long section indicating a start or an end
*/ */
boolean IsRange; boolean IsRange;
FormattedSection(ChatFormatter formatter, int start, int end, ArrayList<String> matches, short remcharfromstart, FormattedSection(ChatFormatter formatter, int start, int end, ArrayList<String> matches, short remcharfromstart,
short remcharfromend, int remcharpos, boolean isrange) { short remcharfromend, boolean isrange) {
Start = start; Start = start;
End = end; End = end;
Formatters.add(formatter); Formatters.add(formatter);
Matches.addAll(matches); Matches.addAll(matches);
RemCharFromStart = remcharfromstart; RemCharFromStart = remcharfromstart;
RemCharFromEnd = remcharfromend; RemCharFromEnd = remcharfromend;
RemCharPos.add(remcharpos);
IsRange = isrange; IsRange = isrange;
} }
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, Collection<Integer> remcharpos, boolean isrange) { short remcharfromstart, short remcharfromend, boolean isrange) {
Start = start; Start = start;
End = end; End = end;
Formatters.addAll(formatters); Formatters.addAll(formatters);
Matches.addAll(matches); Matches.addAll(matches);
RemCharFromStart = remcharfromstart; RemCharFromStart = remcharfromstart;
RemCharFromEnd = remcharfromend; RemCharFromEnd = remcharfromend;
RemCharPos.addAll(remcharpos);
IsRange = isrange; IsRange = isrange;
} }
@ -44,7 +41,7 @@ class FormattedSection {
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(", RemChars: ") .append(Formatters.toString()).append(", matches: ").append(Matches.toString()).append(", RemChars: ")
.append(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(RemCharPos) .append(RemCharFromStart).append(", ").append(RemCharFromEnd).append(", ").append(IsRange).append(")")
.append(", ").append(IsRange).append(")").toString(); .toString();
} }
} }