@@ -182,7 +182,7 @@ static InfluxQLQueryResult readInfluxQLResult(
182182
183183 private static int indexOfUnescapedChar (@ Nonnull final String str , final char ch ) {
184184 char [] chars = str .toCharArray ();
185- for (int i = 0 ; i < chars .length ; i ++) {
185+ for (int i = 1 ; i < chars .length ; i ++) { // ignore first value
186186 if (chars [i ] == ch && chars [i - 1 ] != '\\' ) {
187187 return i ;
188188 }
@@ -195,36 +195,35 @@ private static int indexOfUnescapedChar(@Nonnull final String str, final char ch
195195 expression. So parsing begins based on the verb ('=') not on the assumed expression termination
196196 character (','). The Left and right values of the split based on ('=') are collected and checked for
197197 the correct statement terminator (an unescaped ','). Any value on the left of an unescaped ',' is a
198- value. Any value on the right is a key. These are placed in their respective ordered lists and then
199- recombined into the tags HashMap.
198+ value. Any value on the right is a key.
200199 */
201200 private static Map <String , String > parseTags (@ Nonnull final String value ) {
202201 final Map <String , String > tags = new HashMap <>();
203- final List <String > keys = new ArrayList <>();
204- final List <String > values = new ArrayList <>();
205202 if (!value .isEmpty ()) {
206203 String [] chunks = value .split ("=" );
204+ String currentKey = "" ;
205+ String currentValue = "" ;
206+ String nextKey = "" ;
207207 for (int i = 0 ; i < chunks .length ; i ++) {
208208 if (i == 0 ) { // first element will be a key on its own.
209- keys . add ( chunks [i ]) ;
209+ nextKey = chunks [i ];
210210 } else if (i == chunks .length - 1 ) { // the last element will be a value on its own.
211- values . add ( chunks [i ]) ;
211+ currentValue = chunks [i ];
212212 } else { // check for legitimate keys and values
213213 int commaIndex = indexOfUnescapedChar (chunks [i ], ',' );
214214 if (commaIndex != -1 ) {
215- String v = chunks [i ].substring (0 , commaIndex );
216- String k = chunks [i ].substring (commaIndex + 1 );
217- keys .add (k );
218- values .add (v );
215+ currentValue = chunks [i ].substring (0 , commaIndex );
216+ nextKey = chunks [i ].substring (commaIndex + 1 );
219217 }
220218 }
221- }
222- for (int i = 0 ; i < keys .size (); i ++) {
223- // be sure to surround any values containing escapes with double quotes
224- tags .put (
225- keys .get (i ).contains ("\\ " ) ? "\" " + keys .get (i ) + "\" " : keys .get (i ),
226- values .get (i ).contains ("\\ " ) ? "\" " + values .get (i ) + "\" " : values .get (i )
227- );
219+ if (i > 0 ) {
220+ // be sure to surround keys and values containing escapes with double quotes
221+ tags .put (
222+ currentKey .contains ("\\ " ) ? "\" " + currentKey + "\" " : currentKey ,
223+ currentValue .contains ("\\ " ) ? "\" " + currentValue + "\" " : currentValue
224+ );
225+ }
226+ currentKey = nextKey ;
228227 }
229228 }
230229
0 commit comments