<commit_before>module.exports = PoFileEntry;

function PoFileEntry() {
    this.comments = [];
    this.fields = {};
    this.lastSeenKey = null;
}

PoFileEntry.prototype.hasNoFieldsYet = function () {
    return (null == this.lastSeenKey);
};

PoFileEntry.prototype.hasNoFieldWithKey = function (key) {
    return (undefined == this.fields[key]);
};

PoFileEntry.prototype.isAcceptingComment = function () {
    return this.hasNoFieldsYet();
};

PoFileEntry.prototype.isAcceptingKey = function (key) {
    return (
        this.hasNoFieldsYet()
        ||
        (
            this.hasFieldWithStrings(this.lastSeenKey)
            &&
            this.hasNoFieldWithKey(key)
        )
    );
};

PoFileEntry.prototype.isAcceptingString = function () {
    return (null != this.lastSeenKey) && (this.fields[this.lastSeenKey]);
};

PoFileEntry.prototype.acceptToken = function (token) {
    switch (token.type) {
        case 'comment':
            return this.acceptComment(token.value);
        case 'key':
            return this.acceptKey(token.value);
        case 'string':
            return this.acceptString({value: token.value, quote: token.quote});
    }
    return false;
};

PoFileEntry.prototype.acceptComment = function (comment) {
    if (this.isAcceptingComment()) {
        this.comments.push(comment);
        return true;
    }
    return false;
};

PoFileEntry.prototype.acceptKey = function (key) {
    if (this.isAcceptingKey(key)) {
        this.fields[key] = {key: key, strings: []};
        this.lastSeenKey = key;
        return true;
    }
    return false;
};

PoFileEntry.prototype.acceptString = function (string) {
    if (this.isAcceptingString()) {
        this.fields[this.lastSeenKey].strings.push(string);
        return true;
    }
    return false;
};

PoFileEntry.prototype.isValid = function (nplurals) {
    nplurals = nplurals ? nplurals : 1;
    return this.isValidSingular() || this.isValidPlural(nplurals);
};

PoFileEntry.prototype.isValidSingular = function () {
    if (! this.hasFieldWithStrings('msgid')) return false;
    if (! this.hasFieldWithStrings('msgstr')) return false;
    return true;
};

PoFileEntry.prototype.isValidPlural = function (nplurals) {
    nplurals = nplurals ? nplurals : 1;
    if (! this.hasFieldWithStrings('msgid')) return false;
    if (! this.hasFieldWithStrings('msgid_plural')) return false;
    for (var i = 0; i < nplurals; i++) {
        if (! this.hasFieldWithStrings('msgstr[' + i + ']')) return false;
    }
    return true;
};

PoFileEntry.prototype.hasFieldWithStrings = function (key) {
    return (this.fields[key]) && (0 < this.fields[key].strings.length);
};

PoFileEntry.prototype.getSimpleData = function () {
    return {}; // TODO implement
};

PoFileEntry.prototype.getDetailedData = function () {
    return []; // TODO implement
};

PoFileEntry.prototype.getNativeData = function () {
    return {comments: this.comments, fields: this.fields};
};

// static "class" functions

PoFileEntry.formatNativeData = function (data) {
    var output = '';
    var potentialFields = ['msgctxt', 'msgid', 'msgid_plural', 'msgstr'];
    for (var i = 0; i < data.comments.length; i++) {<commit_msg>extend API of PoFileEntry<commit_after>module.exports = PoFileEntry;

function PoFileEntry() {
    this.comments = [];
    this.fields = {};
    this.lastSeenKey = null;
}

PoFileEntry.prototype.hasNoFieldsYet = function () {
    return (null == this.lastSeenKey);
};

PoFileEntry.prototype.hasNoFieldWithKey = function (key) {
    return (undefined == this.fields[key]);
};

PoFileEntry.prototype.isAcceptingComment = function () {
    return this.hasNoFieldsYet();
};

PoFileEntry.prototype.isAcceptingKey = function (key) {
    return (
        this.hasNoFieldsYet()
        ||
        (
            this.hasFieldWithStrings(this.lastSeenKey)
            &&
            this.hasNoFieldWithKey(key)
        )
    );
};

PoFileEntry.prototype.isAcceptingString = function () {
    return (null != this.lastSeenKey) && (this.fields[this.lastSeenKey]);
};

PoFileEntry.prototype.acceptToken = function (token) {
    switch (token.type) {
        case 'comment':
            return this.acceptComment(token.value);
        case 'key':
            return this.acceptKey(token.value);
        case 'string':
            return this.acceptString({value: token.value, quote: token.quote});
    }
    return false;
};

PoFileEntry.prototype.acceptComment = function (comment) {
    if (this.isAcceptingComment()) {
        this.comments.push(comment);
        return true;
    }
    return false;
};

PoFileEntry.prototype.acceptKey = function (key) {
    if (this.isAcceptingKey(key)) {
        this.fields[key] = {key: key, strings: []};
        this.lastSeenKey = key;
        return true;
    }
    return false;
};

PoFileEntry.prototype.acceptString = function (string) {
    if (this.isAcceptingString()) {
        this.fields[this.lastSeenKey].strings.push(string);
        return true;
    }
    return false;
};

PoFileEntry.prototype.isValid = function (nplurals) {
    nplurals = nplurals ? nplurals : 1;
    return this.isValidSingular() || this.isValidPlural(nplurals);
};

PoFileEntry.prototype.isValidSingular = function () {
    if (! this.hasFieldWithStrings('msgid')) return false;
    if (! this.hasFieldWithStrings('msgstr')) return false;
    return true;
};

PoFileEntry.prototype.isValidPlural = function (nplurals) {
    nplurals = nplurals ? nplurals : 1;
    if (! this.hasFieldWithStrings('msgid')) return false;
    if (! this.hasFieldWithStrings('msgid_plural')) return false;
    for (var i = 0; i < nplurals; i++) {
        if (! this.hasFieldWithStrings('msgstr[' + i + ']')) return false;
    }
    return true;
};

PoFileEntry.prototype.hasFieldWithStrings = function (key) {
    return (this.fields[key]) && (0 < this.fields[key].strings.length);
};

PoFileEntry.prototype.getSimpleData = function () {
    return {}; // TODO implement
};

PoFileEntry.prototype.getDetailedData = function () {
    return []; // TODO implement
};

PoFileEntry.prototype.getNativeData = function () {
    return {comments: this.comments, fields: this.fields};
};

PoFileEntry.prototype.getFieldValue = function (fieldname) {
  return this.hasFieldWithStrings(fieldname) ? this.fields[fieldname].strings.join('') : null;
};

// static "class" functions

PoFileEntry.formatNativeData = function (data) {
    var output = '';
    var potentialFields = ['msgctxt', 'msgid', 'msgid_plural', 'msgstr'];
    for (var i = 0; i < data.comments.length; i++) {
{'fraction_non_alphanumeric': 0.14004276114844227, 'fraction_numerical': 0.0015271838729383018, 'mean_word_length': 3.238834951456311, 'pattern_counts': {'":': 0, '<': 9, '<?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': '5732068', 'n_tokens_mistral': 2055, 'n_tokens_neox': 2036, 'n_words': 388}