<commit_before>/*
 * The translation response struct.
 *
 * author: <NAME> <<EMAIL>>
 */

#include "translate_response.hxx"
#include "pool.h"
#include "strref-pool.h"
#include "strmap.h"
#include "widget-view.h"

#include <string.h>

void
TranslateResponse::Clear()
{
    memset(this, 0, sizeof(*this));
}

template<typename T>
static ConstBuffer<T>
Copy(pool *p, ConstBuffer<T> src)
{
    if (src.IsEmpty())
        return ConstBuffer<T>::Null();

    ConstBuffer<void> src_v = src.ToVoid();
    ConstBuffer<void> dest_v(p_memdup(p, src_v.data, src_v.size), src_v.size);
    return ConstBuffer<T>::FromVoid(dest_v);
}
<commit_msg>translate_response: handle null/empty difference in Copy()<commit_after>/*
 * The translation response struct.
 *
 * author: <NAME> <<EMAIL>>
 */

#include "translate_response.hxx"
#include "pool.h"
#include "strref-pool.h"
#include "strmap.h"
#include "widget-view.h"

#include <string.h>

void
TranslateResponse::Clear()
{
    memset(this, 0, sizeof(*this));
}

template<typename T>
static ConstBuffer<T>
Copy(pool *p, ConstBuffer<T> src)
{
    if (src.IsNull())
        return ConstBuffer<T>::Null();

    if (src.IsEmpty())
        return ConstBuffer<T>::FromVoid({"", 0});

    ConstBuffer<void> src_v = src.ToVoid();
    ConstBuffer<void> dest_v(p_memdup(p, src_v.data, src_v.size), src_v.size);
    return ConstBuffer<T>::FromVoid(dest_v);
}

{'fraction_non_alphanumeric': 0.17318840579710146, 'fraction_numerical': 0.002173913043478261, 'mean_word_length': 4.659836065573771, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '91183', 'n_tokens_mistral': 513, 'n_tokens_neox': 514, 'n_words': 104}