<commit_before>'use strict';

/**
 * @ngdoc function
 * @name jsUtilsApp.controller:CommentWrapperCtrl
 * @description
 * # CommentWrapperCtrl
 * Controller of the jsUtilsApp
 */
angular.module('jsUtilsApp')
    .controller('CommentWrapperCtrl', [
        '$scope', commentWrapperCtrl
    ]);

function charChain(char, length) {
    var output = '';

    for (var i = 0; i < length; i++) {
        output += char;
    }

    return output;
}

function fillLine(line, availableLineCharsLength, options) {
    var output = '';

    var fillLength = availableLineCharsLength - line.length;

    var preStringLength = Math.round(fillLength / 2);
    var postStringLength = (fillLength - preStringLength);

    var preString = charChain(options.fillChar, preStringLength + (1 * options.borderAround));
    var postString = charChain(options.fillChar, postStringLength + (1 * options.borderAround));

    output += preString;

    if (options.additionalEmptySpacer) {
        output += ' ';
    }
    output += line;

    if (options.additionalEmptySpacer) {
        output += ' ';
    }
    output += postString;

    if (options.escapeStringEscapeChars) {
        output = output.replace(options.stringEscapeChar, '\\' + options.stringEscapeChar, 'g');
    }

    return output;
}

function wrapLineInChars(line, options) {
    var output = '';

    if (line) {
        var additionalCharsLength = (2 * options.fillChar.length * options.borderAround + 2 * options.additionalEmptySpacer);
        var availableLineCharsLength = options.lineLength - additionalCharsLength;

        if (line.length < availableLineCharsLength) {
            output = options.lineStart
                + options.stringEscapeChar
                + fillLine(line, availableLineCharsLength, options)
                + options.stringEscapeChar
                + options.lineEnd
                + options.endOfLineChar;
        } else {
            var tempLine;
            var carret = 0;

            while (carret < line.length) {
                tempLine = line.slice(carret, carret + availableLineCharsLength);

                output += options.lineStart
                    + options.stringEscapeChar
                    + fillLine(tempLine, availableLineCharsLength, options)
                    + options.stringEscapeChar
                    + options.lineEnd
                    + options.endOfLineChar;

                carret += availableLineCharsLength;
            }
        }
    }

    return output;
}

function generateEmptyLine(options) {
    var output = '';

    output += options.lineStart
        + options.stringEscapeChar
        + charChain(options.fillChar, options.lineLength)
        + options.stringEscapeChar
        + options.lineEnd
        + options.endOfLineChar;

    return output;
}

function generateLine(line, options) {
    var output = '';

    if (line) {
        output += wrapLineInChars(line, options);
    }

    return output;
}

function varLog(varName, options) {
    var output = '';

    if (varName && typeof varName === 'string') {
        output += options.lineStart
            + options.stringEscapeChar
            + options.fillChar;

        if (options.additionalEmptySpacer) {
            output += ' ';
        }

        output += varName + options.stringEscapeChar + ', ' + varName + options.lineEnd + options.endOfLineChar;
    }

    return output;
}

function generateComment(options) {
    var output = '';
    var lines = options.input.split('\n');

    if (options.borderAround) {
        output += generateEmptyLine(options);
    }

    for (var i = 0; i < lines.length; i++) {
        output += generateLine(lines[i].trim(), options);
    }

    if (options.varsToList) {
        var varsList = options.varsToList.split(options.varsToListSeparator);

        for (var i = 0; i < varsList.length; i++) {

            if (options.borderAround) {
                output += generateEmptyLine(options);<commit_msg> #3 String char escaping in variables logging<commit_after>'use strict';

/**
 * @ngdoc function
 * @name jsUtilsApp.controller:CommentWrapperCtrl
 * @description
 * # CommentWrapperCtrl
 * Controller of the jsUtilsApp
 */
angular.module('jsUtilsApp')
    .controller('CommentWrapperCtrl', [
        '$scope', commentWrapperCtrl
    ]);

function charChain(char, length) {
    var output = '';

    for (var i = 0; i < length; i++) {
        output += char;
    }

    return output;
}

function fillLine(line, availableLineCharsLength, options) {
    var output = '';

    var fillLength = availableLineCharsLength - line.length;

    var preStringLength = Math.round(fillLength / 2);
    var postStringLength = (fillLength - preStringLength);

    var preString = charChain(options.fillChar, preStringLength + (1 * options.borderAround));
    var postString = charChain(options.fillChar, postStringLength + (1 * options.borderAround));

    output += preString;

    if (options.additionalEmptySpacer) {
        output += ' ';
    }
    output += line;

    if (options.additionalEmptySpacer) {
        output += ' ';
    }
    output += postString;

    if (options.escapeStringEscapeChars) {
        output = output.replace(options.stringEscapeChar, '\\' + options.stringEscapeChar, 'g');
    }

    return output;
}

function wrapLineInChars(line, options) {
    var output = '';

    if (line) {
        var additionalCharsLength = (2 * options.fillChar.length * options.borderAround + 2 * options.additionalEmptySpacer);
        var availableLineCharsLength = options.lineLength - additionalCharsLength;

        if (line.length < availableLineCharsLength) {
            output = options.lineStart
                + options.stringEscapeChar
                + fillLine(line, availableLineCharsLength, options)
                + options.stringEscapeChar
                + options.lineEnd
                + options.endOfLineChar;
        } else {
            var tempLine;
            var carret = 0;

            while (carret < line.length) {
                tempLine = line.slice(carret, carret + availableLineCharsLength);

                output += options.lineStart
                    + options.stringEscapeChar
                    + fillLine(tempLine, availableLineCharsLength, options)
                    + options.stringEscapeChar
                    + options.lineEnd
                    + options.endOfLineChar;

                carret += availableLineCharsLength;
            }
        }
    }

    return output;
}

function generateEmptyLine(options) {
    var output = '';

    output += options.lineStart
        + options.stringEscapeChar
        + charChain(options.fillChar, options.lineLength)
        + options.stringEscapeChar
        + options.lineEnd
        + options.endOfLineChar;

    return output;
}

function generateLine(line, options) {
    var output = '';

    if (line) {
        output += wrapLineInChars(line, options);
    }

    return output;
}

function varLog(varName, options) {
    var output = '';

    if (varName && typeof varName === 'string') {
        var escapedVarName = varName;

        if (options.escapeStringEscapeChars) {
            escapedVarName = escapedVarName.replace(options.stringEscapeChar, '\\' + options.stringEscapeChar, 'g');
        }

        output += options.lineStart
            + options.stringEscapeChar
            + options.fillChar;

        if (options.additionalEmptySpacer) {
            output += ' ';
        }

        output += escapedVarName + options.stringEscapeChar + ', ' + varName + options.lineEnd + options.endOfLineChar;
    }

    return output;
}

function generateComment(options) {
    var output = '';
    var lines = options.input.split('\n');

    if (options.borderAround) {
        output += generateEmptyLine(options);
    }

    for (var i = 0; i < lines.length; i++) {
        output += generateLine(lines[i].trim(), options);
    }

    if (options.varsToList) {
        var varsList = options.varsToList.split(options.varsToListSeparator);

        for (var i = 0; i < varsList.length; i++) {

            if (options.borderAround) {
                output += generateEmptyLine(options);
{'fraction_non_alphanumeric': 0.1081014830248805, 'fraction_numerical': 0.0023287167545042284, 'mean_word_length': 2.29430763019782, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, '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': '6259676', 'n_tokens_mistral': 2332, 'n_tokens_neox': 2190, 'n_words': 467}