package ru.bitel.bgbilling.modules.voice.dyn.mediator.md;

import java.util.ArrayList;
import java.util.List;

public class ParseCsvLine
{

    public static void main( String[] args )
    {
        String line = "\"2\"\"\",,\"4,5\",\"33\""; 
        List<String> data = new ArrayList<>();
        int index = 0;
        String value = "";
        String[] tokens = line.split( "," );
        while ( index < tokens.length )
        {
            value += tokens[index++];
            if ( value.replaceAll( "[^\"]", "" ).length() % 2 == 1 )
            {
                value += ",";
            }
            else
            {
                data.add( value.replaceAll( "^\"", "" ).replaceAll( "\"$", "" ).replaceAll( "\"\"", "\"" ) );
                value = "";
            }
        }
        
        data.forEach( a -> System.out.println( a ) );
    }
}
