From cfa6a434a3743479ac38dc769ec1573f2a0ad8d2 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Tue, 21 Oct 2014 15:33:15 +0200 Subject: [PATCH] Refactor KeyValueFormat --- .../org/sonar/api/utils/KeyValueFormat.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java index a9914eee1ed..c2a619e2108 100644 --- a/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java +++ b/sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java @@ -71,6 +71,13 @@ public final class KeyValueFormat { // only static methods } + private static class FieldParserContext { + private final StringBuilder result = new StringBuilder(); + private boolean escaped = false; + private char firstChar; + private char previous = (char) -1; + } + static class FieldParser { private static final char DOUBLE_QUOTE = '"'; private final String csv; @@ -90,19 +97,12 @@ public final class KeyValueFormat { return next(';'); } - private class Context { - private StringBuilder result = new StringBuilder(); - private boolean escaped = false; - private char firstChar; - private char previous = (char) -1; - } - @CheckForNull private String next(char separator) { if (position >= csv.length()) { return null; } - Context context = new Context(); + FieldParserContext context = new FieldParserContext(); context.firstChar = csv.charAt(position); // check if value is escaped by analyzing first character checkEscaped(context); @@ -114,7 +114,7 @@ public final class KeyValueFormat { return context.result.toString(); } - private boolean advance(char separator, Context context) { + private boolean advance(char separator, FieldParserContext context) { boolean end = false; char c = csv.charAt(position); if (c == separator && !context.escaped) { @@ -139,7 +139,7 @@ public final class KeyValueFormat { return end; } - private void checkEscaped(Context context) { + private void checkEscaped(FieldParserContext context) { if (context.firstChar == DOUBLE_QUOTE) { context.escaped = true; position++; -- 2.39.5