<commit_before>"use strict";

const defs = require('./defs.js');

const luaS_eqlngstr = function(a, b) {
    return a == b || (a.length == b.length && a.join() == b.join());
};

/* converts strings (arrays) to a consistent map key */
const luaS_hash = function(str) {
    return str.map(e => `${e}|`).join('');
};

/* variant that takes ownership of array */
const luaS_bless = function(L, str) {
    return str;
};

/* makes a copy */
const luaS_new = function(L, str) {
    return luaS_bless(L, str.slice(0));
};

/* takes a js string */
const luaS_newliteral = function(L, str) {
    return luaS_bless(L, defs.to_luastring(str));
};

module.exports.luaS_eqlngstr   = luaS_eqlngstr;
module.exports.luaS_hash       = luaS_hash;
module.exports.luaS_bless      = luaS_bless;<commit_msg>src/lstring.js: Freeze strings to catch accidental modification<commit_after>"use strict";

const defs = require('./defs.js');

const luaS_eqlngstr = function(a, b) {
    return a == b || (a.length == b.length && a.join() == b.join());
};

/* converts strings (arrays) to a consistent map key */
const luaS_hash = function(str) {
    return str.map(e => `${e}|`).join('');
};

/* variant that takes ownership of array */
const luaS_bless = function(L, str) {
    Object.freeze(str);
    return str;
};

/* makes a copy */
const luaS_new = function(L, str) {
    return luaS_bless(L, str.slice(0));
};

/* takes a js string */
const luaS_newliteral = function(L, str) {
    return luaS_bless(L, defs.to_luastring(str));
};

module.exports.luaS_eqlngstr   = luaS_eqlngstr;
module.exports.luaS_hash       = luaS_hash;
module.exports.luaS_bless      = luaS_bless;
{'fraction_non_alphanumeric': 0.16484184914841848, 'fraction_numerical': 0.0012165450121654502, 'mean_word_length': 3.7406340057636887, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '177209', 'n_tokens_mistral': 628, 'n_tokens_neox': 603, 'n_words': 144}