'use strict';

module.exports = function (line) {

    var data = [""];
    var lastCommaIndice = -1;
    var startQuotationMark = false;
    for (var i=0; i<line.length; i++)
    {
        if (line[i]==',')
        {
            if(startQuotationMark == false)
            {
                data.push("");
            }
            else{
                data[data.length-1] += line[i];
            }
            lastCommaIndice = i;
        }
        else if (line[i]=='"')
        {
            if (lastCommaIndice != -1 && lastCommaIndice == i-1)
            {
                startQuotationMark = true;
            }
            else if (startQuotationMark == true && (i==line.length-1 || line[i+1]==','))
            {
                startQuotationMark = false;
            }
            else{
                data[data.length-1] += line[i];
            }
        }
        else{
            data[data.length-1] += line[i];
        }
    }
    return data;
};
