X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=inline;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Ftemplate%2FSubstringFilter.java;h=2a2e5269548ad63b209c33ff8952e9255442fa3e;hb=ecfd4c5a91d204ce4c001d19fa600cf42ac4cf43;hp=857017c5742f6fce9053bb13268c49548babef73;hpb=33f333b35a73d3d4a4e79f41e9dd7b342db87b1a;p=Sone.git
diff --git a/src/main/java/net/pterodactylus/sone/template/SubstringFilter.java b/src/main/java/net/pterodactylus/sone/template/SubstringFilter.java
index 857017c..2a2e526 100644
--- a/src/main/java/net/pterodactylus/sone/template/SubstringFilter.java
+++ b/src/main/java/net/pterodactylus/sone/template/SubstringFilter.java
@@ -1,5 +1,5 @@
/*
- * Sone - SubstringFilter.java - Copyright © 2010 David Roden
+ * Sone - SubstringFilter.java - Copyright © 2010â2020 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -28,8 +28,6 @@ import net.pterodactylus.util.template.TemplateContext;
* âstartâ and âlength.â âlengthâ is optional and defaults to âthe rest of the
* string.â âstartâ starts at {@code 0} and can be negative to denote starting
* at the end of the string.
- *
- * @author David âBombeâ Roden
*/
public class SubstringFilter implements Filter {
@@ -37,9 +35,9 @@ public class SubstringFilter implements Filter {
* {@inheritDoc}
*/
@Override
- public Object format(TemplateContext templateContext, Object data, Map parameters) {
- String startString = parameters.get("start");
- String lengthString = parameters.get("length");
+ public Object format(TemplateContext templateContext, Object data, Map parameters) {
+ String startString = String.valueOf(parameters.get("start"));
+ String lengthString = String.valueOf(parameters.get("length"));
int start = 0;
try {
start = Integer.parseInt(startString);
@@ -48,13 +46,7 @@ public class SubstringFilter implements Filter {
}
String dataString = String.valueOf(data);
int dataLength = dataString.length();
- if (lengthString == null) {
- if (start < 0) {
- return dataString.substring(dataLength + start);
- }
- return dataString.substring(start);
- }
- int length = Integer.MAX_VALUE;
+ int length = dataLength;
try {
length = Integer.parseInt(lengthString);
} catch (NumberFormatException nfe1) {