<commit_before>
/*!
 * EJS
 * Copyright(c) 2010 <NAME> <<EMAIL>>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var sys = require('sys'),
    utils = require('./utils'),
    filters = require('./filters');

/**
 * Library version.
 */

exports.version = '0.2.0';

/**
 * Intermediate js cache.
 * 
 * @type Object
 */

var cache = {};

/**
 * Clear intermediate js cache.
 *
 * @api public
 */

exports.clearCache = function(){
    cache = {};
};

/**
 * Parse the given `str` of ejs, returning the function body.
 *
 * @param {String} str
 * @return {String}
 * @api public
 */

var parse = exports.parse = function(str, options){
    var options = options || {},
        open = options.open || exports.open || '<%',
        close = options.close || exports.close || '%>';

    var buf = [
        "var buf = []",
        "\nwith (locals) {",
        "\n  buf.push('"
    ];

    for (var i = 0, len = str.length; i < len; ++i) {
        if (str.slice(i, open.length + i) == open) {
            i += open.length
        
            var prefix, postfix;
            switch (str[i]) {
                case '=':
                    prefix = "', escape(";
                    postfix = "), '";
                    ++i;
                    break;
                case '-':
                    prefix = "', ";
                    postfix = ", '";
                    ++i;
                    break;
                case ':':
                    break;
                default:
                    prefix = "'); ";
                    postfix = "; buf.push('";
            }
        
            var start = i;
            var end = str.indexOf(close, i);
            buf.push(prefix, str.slice(i, end), postfix);
            i += end - start + close.length - 1;

        } else if (str[i] == "\\") {
            buf.push("\\\\");
        } else if (str[i] == "'") {
            buf.push("\\'");
        } else if (str[i] == "\r") {
            buf.push(" ");
        } else if (str[i] == "\n") {
            buf.push("\\n");
        } else {
            buf.push(str[i]);
        }
    }
    buf.push("');\n}\nreturn buf.join('');")
    return buf.join('')
};

/**<commit_msg>Misc refactoring<commit_after>
/*!
 * EJS
 * Copyright(c) 2010 <NAME> <<EMAIL>>
 * MIT Licensed
 */

/**
 * Module dependencies.
 */

var sys = require('sys'),
    utils = require('./utils'),
    filters = require('./filters');

/**
 * Library version.
 */

exports.version = '0.2.0';

/**
 * Intermediate js cache.
 * 
 * @type Object
 */

var cache = {};

/**
 * Clear intermediate js cache.
 *
 * @api public
 */

exports.clearCache = function(){
    cache = {};
};

/**
 * Parse the given `str` of ejs, returning the function body.
 *
 * @param {String} str
 * @return {String}
 * @api public
 */

var parse = exports.parse = function(str, options){
    var options = options || {},
        open = options.open || exports.open || '<%',
        close = options.close || exports.close || '%>';

    var buf = [
        "var buf = []",
        "\nwith (locals) {",
        "\n  buf.push('"
    ];

    for (var i = 0, len = str.length; i < len; ++i) {
        if (str.slice(i, open.length + i) == open) {
            i += open.length
        
            var prefix, postfix;
            switch (str[i]) {
                case '=':
                    prefix = "', escape(";
                    postfix = "), '";
                    ++i;
                    break;
                case '-':
                    prefix = "', ";
                    postfix = ", '";
                    ++i;
                    break;
                case ':':
                    break;
                default:
                    prefix = "'); ";
                    postfix = "; buf.push('";
            }
        
            if (prefix) {
                var start = i;
                var end = str.indexOf(close, i);
                buf.push(prefix, str.slice(i, end), postfix);
                i += end - start + close.length - 1;
            }

        } else if (str[i] == "\\") {
            buf.push("\\\\");
        } else if (str[i] == "'") {
            buf.push("\\'");
        } else if (str[i] == "\r") {
            buf.push(" ");
        } else if (str[i] == "\n") {
            buf.push("\\n");
        } else {
            buf.push(str[i]);
        }
    }
    buf.push("');\n}\nreturn buf.join('');")
    return buf.join('')
};

/**
{'fraction_non_alphanumeric': 0.1888159384197419, 'fraction_numerical': 0.004075164138555581, 'mean_word_length': 1.2335692618806875, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 11, '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': '4365909', 'n_tokens_mistral': 1373, 'n_tokens_neox': 1312, 'n_words': 311}