From 3fe5e020d881a8ed980d83629bd7dd8aa2eb2e50 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Wed, 12 Mar 2014 11:35:45 -0700 Subject: [PATCH] Factor exception wrapped read() into nextChar(). --- .../com/samskivert/mustache/Mustache.java | 30 ++++++++----------- 1 file changed, 12 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/samskivert/mustache/Mustache.java b/src/main/java/com/samskivert/mustache/Mustache.java index 022ddb5..fd2baee 100644 --- a/src/main/java/com/samskivert/mustache/Mustache.java +++ b/src/main/java/com/samskivert/mustache/Mustache.java @@ -339,18 +339,9 @@ public class Mustache public Accumulator parse (Reader source) { this.source = source; - while (true) { - char c; - try { - int v = source.read(); - if (v == -1) { - break; - } - c = (char)v; - } catch (IOException e) { - throw new MustacheException(e); - } - + int v; + while ((v = nextChar()) != -1) { + char c = (char)v; if (c == '\n') { column = 0; line++; @@ -366,7 +357,6 @@ public class Mustache column++; skipNewline = false; } - parseChar(c); } @@ -453,11 +443,7 @@ public class Mustache if (delims.isStaches() && text.charAt(0) == delims.start1) { // we've only parsed }} at this point, so we have to slurp in another // character from the input stream and check it - int end3; - try { end3 = source.read(); } - catch (IOException e) { - throw new MustacheException(e); - } + int end3 = nextChar(); if (end3 != '}') { String got = (end3 == -1) ? "" : String.valueOf((char)end3); throw new MustacheParseException( @@ -480,6 +466,14 @@ public class Mustache break; } } + + protected int nextChar () { + try { + return source.read(); + } catch (IOException ioe) { + throw new MustacheException(ioe); + } + } } protected static class Delims {