diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-21 15:33:15 +0200 |
---|---|---|
committer | Simon Brandhof <simon.brandhof@sonarsource.com> | 2014-10-21 15:33:15 +0200 |
commit | cfa6a434a3743479ac38dc769ec1573f2a0ad8d2 (patch) | |
tree | ccc0eeac8debef5db2966ebcae4b0a7ff74b82f3 | |
parent | 15cea0177b7a94eb2eb9b9687e04da9e3832bef4 (diff) | |
download | sonarqube-cfa6a434a3743479ac38dc769ec1573f2a0ad8d2.tar.gz sonarqube-cfa6a434a3743479ac38dc769ec1573f2a0ad8d2.zip |
Refactor KeyValueFormat
-rw-r--r-- | sonar-plugin-api/src/main/java/org/sonar/api/utils/KeyValueFormat.java | 20 |
1 files 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++; |