hive/html/js/basic.js
// can be overriden in the second argument.
can be overriden in the second argument.
can be overriden in the second argument .
function CSVToArray( strData, strDelimiter )
{
    strDelimiter = (strDelimiter || ",");
    var objPattern = new RegExp(
            (
                    "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" +
                    "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" +
                    "([^\"\\" + strDelimiter + "\\r\\n]*))"
            ),
            "gi"
            );
    var arrData = [[]];
    var arrMatches = null;
    while (arrMatches = objPattern.exec( strData )){
            var strMatchedDelimiter = arrMatches[ 1 ];
            if (
                    strMatchedDelimiter.length &&
                    (strMatchedDelimiter != strDelimiter)
                    ){
                    arrData.push( [] );
            }
            var strMatchedValue=0;
            if (arrMatches[ 2 ]){
                    strMatchedValue = arrMatches[ 2 ].replace(
                            new RegExp( "\"\"", "g" ),
                            "\""
                            );
            } else {
                    strMatchedValue = arrMatches[ 3 ];
            }
            arrData[ arrData.length - 1 ].push( strMatchedValue );
    }
    return( arrData );
}
function CSVToArray ( strData , strDelimiter ) { strDelimiter = ( strDelimiter || "," ) ; var objPattern = new RegExp ( ( "(\\" + strDelimiter + "|\\r?\\n|\\r|^)" + "(?:\"([^\"]*(?:\"\"[^\"]*)*)\"|" + "([^\"\\" + strDelimiter + "\\r\\n]*))" ) , "gi" ) ; var arrData = [ [ ] ] ; var arrMatches = null ; while ( arrMatches = objPattern . exec ( strData ) ) { var strMatchedDelimiter = arrMatches [ 1 ] ; if ( strMatchedDelimiter . length && ( strMatchedDelimiter != strDelimiter ) ) { arrData . push ( [ ] ) ; } var strMatchedValue = 0 ; if ( arrMatches [ 2 ] ) { strMatchedValue = arrMatches [ 2 ] . replace ( new RegExp ( "\"\"" , "g" ) , "\"" ) ; } else { strMatchedValue = arrMatches [ 3 ] ; } arrData [ arrData . length - 1 ] . push ( strMatchedValue ) ; } return ( arrData ) ; }
can be overriden in the second argument.
can be overriden in the second argument .
// Check to see if the delimiter is defined. If not, // then default to comma. // Create a regular expression to parse the CSV values. // Delimiters. // Quoted fields. // Standard fields. // Create an array to hold our data. Give the array // a default empty first row. // Create an array to hold our individual pattern // matching groups. // Keep looping over the regular expression matches // until we can no longer find a match. // Get the delimiter that was found. // Check to see if the given delimiter has a length // (is not the start of string) and if it matches // field delimiter. If id does not, then we know // that this delimiter is a row delimiter. // Since we have reached a new row of data, // add an empty row to our data array. // Now that we have our delimiter out of the way, // let's check to see which kind of value we // captured (quoted or unquoted). // We found a quoted value. When we capture // this value, unescape any double quotes. // We found a non-quoted value. // Now that we have our value string, let's add // it to the data array. // Return the parsed data.