From: David ‘Bombe’ Roden Date: Tue, 27 Sep 2011 17:29:05 +0000 (+0200) Subject: Simplify length extraction. X-Git-Tag: 0.7.2^2~21 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=233d1dac0b3fd8835abf4fcddde8f126762c5188;p=Sone.git Simplify length extraction. --- diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index 42e4035..c5f7f6b 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -87,19 +87,7 @@ public class ParserFilter implements Filter { @Override public Object format(TemplateContext templateContext, Object data, Map parameters) { String text = String.valueOf(data); - int length = -1; - try { - length = Integer.parseInt(parameters.get("length")); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - if ((length == -1) && (parameters.get("length") != null)) { - try { - length = Integer.parseInt(String.valueOf(templateContext.get(parameters.get("length")))); - } catch (NumberFormatException nfe1) { - /* ignore. */ - } - } + int length = Numbers.safeParseInteger(parameters.get("length"), Numbers.safeParseInteger(templateContext.get(parameters.get("length")), -1)); String soneKey = parameters.get("sone"); if (soneKey == null) { soneKey = "sone";