Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private static Iterator<String> parseCSVLine(String input) {
- boolean literal = true;
- boolean checkSpeech = true;
- boolean inSpeech = false;
- boolean checkDel = true;
- char c;
- String temp = "";
- ArrayList<String> values = new ArrayList<String>();
- for (int i = 0; i < input.length(); i++) {
- c = input.charAt(i);
- if (checkDel && c == ',') {
- values.add(temp.trim());
- temp = "";
- checkSpeech = true;
- continue;
- }
- if (checkSpeech && c == ' ') {
- continue;
- }
- if (literal) {
- if (c == '\\') {
- literal = false;
- } else if (c == '"') {
- if (checkSpeech) {
- inSpeech = true;
- checkDel = false;
- } else if (inSpeech) {
- inSpeech = false;
- checkDel = true;
- } else {
- temp += c;
- }
- } else {
- temp += c;
- }
- } else {
- temp += c;
- literal = true;
- }
- checkSpeech = false;
- }
- values.add(temp.trim());
- return values.iterator();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement