luchunliang commented on code in PR #10753: URL: https://github.com/apache/inlong/pull/10753#discussion_r1704855432
########## inlong-sort/sort-formats/format-common/src/main/java/org/apache/inlong/sort/formats/util/StringUtils.java: ########## @@ -97,133 +97,135 @@ public static List<Map<String, String>> splitKv( int kvState = STATE_KEY; char lastCh = 0; - for (int i = 0; i < text.length(); ++i) { - char ch = text.charAt(i); - if (ch == kvDelimiter) { - switch (state) { - case STATE_KEY: - key = stringBuilder.toString(); - stringBuilder.setLength(0); - state = STATE_VALUE; - break; - case STATE_VALUE: - stringBuilder.append(ch); - break; - case STATE_ESCAPING: - stringBuilder.append(ch); - state = kvState; - break; - case STATE_QUOTING: - stringBuilder.append(ch); - break; - } - } else if (ch == entryDelimiter) { - switch (state) { - case STATE_KEY: - key = lastKey; - if (lastValue == null) { - value = ch + stringBuilder.toString(); - } else { - value = lastValue + ch + stringBuilder.toString(); - } - fields.put(key, value); - lastKey = key; - lastValue = value; - stringBuilder.setLength(0); - break; - case STATE_VALUE: - value = stringBuilder.toString(); - fields.put(key, value); - lastKey = key; - lastValue = value; - stringBuilder.setLength(0); - state = STATE_KEY; - break; - case STATE_ESCAPING: - stringBuilder.append(ch); - state = kvState; - break; - case STATE_QUOTING: - stringBuilder.append(ch); - break; - } - } else if (escapeChar != null && ch == escapeChar) { - switch (state) { - case STATE_KEY: - if (lastCh != 0) { - stringBuilder.append(lastCh); - } - kvState = state; - state = STATE_ESCAPING; - break; - case STATE_VALUE: - kvState = state; - state = STATE_ESCAPING; - break; - case STATE_ESCAPING: - stringBuilder.append(ch); - state = kvState; - break; - case STATE_QUOTING: - stringBuilder.append(ch); - break; - } - } else if (quoteChar != null && ch == quoteChar) { - switch (state) { - case STATE_KEY: - if (lastCh != 0) { - stringBuilder.append(lastCh); - } - kvState = state; - state = STATE_QUOTING; - break; - case STATE_VALUE: - kvState = state; - state = STATE_QUOTING; - break; - case STATE_ESCAPING: - stringBuilder.append(ch); - state = kvState; - break; - case STATE_QUOTING: - state = kvState; - break; - } - } else if (lineDelimiter != null && ch == lineDelimiter) { - switch (state) { - case STATE_KEY: - key = lastKey; - stringBuilder.append(lastValue).append(lastCh); - value = stringBuilder.toString(); - fields.put(key, value); - lastKey = null; - lastValue = null; - stringBuilder.setLength(0); - break; - case STATE_VALUE: - lastKey = null; - lastValue = null; - value = stringBuilder.toString(); - fields.put(key, value); - Map<String, String> copyFields = new HashMap<>(); - copyFields.putAll(fields); - lines.add(copyFields); - stringBuilder.setLength(0); - fields.clear(); - state = STATE_KEY; - break; - case STATE_ESCAPING: - stringBuilder.append(ch); - state = STATE_NORMAL; - break; - case STATE_QUOTING: - stringBuilder.append(ch); - break; + if (text != null) { Review Comment: If text == null, then it is better to return lines directly. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@inlong.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org