<commit_before>/*
 * grunt-gettext
 * https://github.com/arendjr/grunt-gettext
 *
 * Copyright (c) 2013 <NAME>, Speakap BV
 * Licensed under the MIT license.
 */

"use strict";

module.exports = function(grunt) {

    var _ = grunt.util._;

    function escapeString(string) {

        return '"' + string.replace(/"/g, '\\"') + '"';
    }

    var extractors = {
        handlebars: function(file, options) {
            var contents = grunt.file.read(file).replace("\n", " ");

            var fn = _.flatten([ options.functionName ]);

            var messages = {}, result;

            var extractStrings = function(quote, fn) {
                var regex = new RegExp("\\{\\{\\s*" + fn + "\\s+((?:" +
                    quote + "(?:[^" + quote + "\\\\]|\\\\.)+" + quote +
                    "\\s*)+)[^}]*\\s*\\}\\}", "g");
                var subRE = new RegExp(quote + "((?:[^" + quote + "\\\\]|\\\\.)+)" + quote, "g");
                var quoteRegex = new RegExp("\\\\" + quote, "g");
                // need to factorize
                while ((result = regex.exec(contents)) !== null) {
                    var strings = result[1],
                        singular = void 0;
                    while ((result = subRE.exec(strings)) !== null) {
                        var string = options.processMessage(result[1].replace(quoteRegex, quote));
                        // if singular form already defined add message as plural
                        if (singular !== void 0) {
                            messages[singular].plural = string;
                        // if not defined init message object
                        } else {
                            singular = string;
                            messages[string] = {
                                singular: singular,
                                message: ""
                            };
                        }
                    }
                }
            };

            _.each( fn, function( func ) {
                extractStrings("'", func );
                extractStrings('"', func );
            });

            return messages;
        },

        javascript: function(file, options) {
            var contents = grunt.file.read(file).replace("\n", " ")
                .replace(/"\s*\+\s*"/g, "")
                .replace(/'\s*\+\s*'/g, "");

            var fn = _.flatten([ options.functionName ]);<commit_msg>use type of to check if undefined<commit_after>/*
 * grunt-gettext
 * https://github.com/arendjr/grunt-gettext
 *
 * Copyright (c) 2013 <NAME>, Speakap BV
 * Licensed under the MIT license.
 */

"use strict";

module.exports = function(grunt) {

    var _ = grunt.util._;

    function escapeString(string) {

        return '"' + string.replace(/"/g, '\\"') + '"';
    }

    var extractors = {
        handlebars: function(file, options) {
            var contents = grunt.file.read(file).replace("\n", " ");

            var fn = _.flatten([ options.functionName ]);

            var messages = {}, result;

            var extractStrings = function(quote, fn) {
                var regex = new RegExp("\\{\\{\\s*" + fn + "\\s+((?:" +
                    quote + "(?:[^" + quote + "\\\\]|\\\\.)+" + quote +
                    "\\s*)+)[^}]*\\s*\\}\\}", "g");
                var subRE = new RegExp(quote + "((?:[^" + quote + "\\\\]|\\\\.)+)" + quote, "g");
                var quoteRegex = new RegExp("\\\\" + quote, "g");
                // need to factorize
                while ((result = regex.exec(contents)) !== null) {
                    var strings = result[1],
                        singular = void 0;
                    while ((result = subRE.exec(strings)) !== null) {
                        var string = options.processMessage(result[1].replace(quoteRegex, quote));
                        // if singular form already defined add message as plural
                        if (typeof singular !== 'undefined') {
                            messages[singular].plural = string;
                        // if not defined init message object
                        } else {
                            singular = string;
                            messages[string] = {
                                singular: singular,
                                message: ""
                            };
                        }
                    }
                }
            };

            _.each( fn, function( func ) {
                extractStrings("'", func );
                extractStrings('"', func );
            });

            return messages;
        },

        javascript: function(file, options) {
            var contents = grunt.file.read(file).replace("\n", " ")
                .replace(/"\s*\+\s*"/g, "")
                .replace(/'\s*\+\s*'/g, "");

            var fn = _.flatten([ options.functionName ]);
{'fraction_non_alphanumeric': 0.16296296296296298, 'fraction_numerical': 0.0030864197530864196, 'mean_word_length': 1.1847191011235956, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, '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': '7345895', 'n_tokens_mistral': 1318, 'n_tokens_neox': 1213, 'n_words': 282}