<commit_before>'use strict';

module.exports = function getUniqueColumnNames (cartocss) {
    var columnNames = [];

    var columnNamesFromVariables = getColumnNamesFromVariables(cartocss);
    var columnNamesFromExpressions = getColumnNamesFromExpresions(cartocss);
    var columnNamesFromRegex = getColumnNamesFromRegexs(cartocss);

    columnNames = columnNames.concat(columnNamesFromExpressions)
        .concat(columnNamesFromVariables)
        .concat(columnNamesFromRegex);

    return columnNames.filter(function (item, pos, self) {
        return self.indexOf(item) === pos;
    });
};

function getColumnNamesFromVariables(cartocss) {
    var matches, output = [];
    var variableRegex = /(?:\[) *([^"'=<>~]*?) *(?:\])/g;
    matches = variableRegex.exec(cartocss);

    while (matches) {
        if (isNaN(matches[1])) {
            output.push(matches[1]);
        }

        matches = variableRegex.exec(cartocss);
    }

    return output;
}

function getColumnNamesFromExpresions(cartocss) {
    var matches, output = [];
    var expressionRegex =
    /(?:\[) *([^"'\[\]]*?) *(?:(?:<=)|(?:>=)|(?:\!=)|(?:\=~)|(?:=)|(?:>)|(?:<)) *([^"'\[\]]*?) *(?:\])/g;
    matches = expressionRegex.exec(cartocss);

    while (matches) {
        if (isNaN(matches[1])) {
            output.push(matches[1]);
        }

        if (isNaN(matches[2])) {
            output.push(matches[2]);
        }

        matches = expressionRegex.exec(cartocss);
    }

    return output;
}

function getColumnNamesFromRegexs(cartocss) {
    var matches, output = [];
    var regexRegex = /(?:\[) *([^\[\]]*?) *(?:\=~) *([^\[\]]*?) *(?:\])/g;
    matches = regexRegex.exec(cartocss);

    while (matches) {
        if (isNaN(matches[1])) {
            output.push(matches[1]);
        }

        matches = regexRegex.exec(cartocss);
    }

    return output;
}<commit_msg>Refactored method to extract column names from cartocss<commit_after>'use strict';

module.exports = function getUniqueColumnNames (cartocss) {
    return getColumnNames(cartocss).filter(function (item, pos, self) {
        return self.indexOf(item) === pos;
    });
};

function getColumnNames (cartocss) {
    var columnNames = [];

    var regexs = [{
        regex: /(?:\[) *([^"'\[\]]*?) *(?:(?:<=)|(?:>=)|(?:\!=)|(?:\=~)|(?:=)|(?:>)|(?:<)) *([^"'\[\]]*?) *(?:\])/g,
        capturingGroups: 2
    }, {
        regex: /(?:\[) *([^"'=<>~]*?) *(?:\])/g,
        capturingGroups: 1
    }, {
        regex: /(?:\[) *([^\[\]]*?) *(?:\=~) *([^\[\]]*?) *(?:\])/g,
        capturingGroups: 1
    }];

    for (var i = 0; i < regexs.length; i++) {
        columnNames = columnNames.concat(getColumnNamesFromRegex(cartocss, regexs[i].regex, regexs[i].capturingGroups));
    }

    return columnNames;
}

function getColumnNamesFromRegex(cartocss, regex, capturingGroups) {
    var columnNames = [];
    var matches = regex.exec(cartocss);

    while (matches) {
        for (var i = 1; i <= capturingGroups; i++) {
            if (isNaN(matches[i])) {
                columnNames.push(matches[i]);
            }
        }

        matches = regex.exec(cartocss);
    }

    return columnNames;
}
{'fraction_non_alphanumeric': 0.21294827039035227, 'fraction_numerical': 0.004125674389082831, 'mean_word_length': 2.8485958485958487, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4723416', 'n_tokens_mistral': 1054, 'n_tokens_neox': 1002, 'n_words': 167}