<commit_before>#include "string_table.hxx"

namespace spiegel { namespace dwarf {
using namespace std;

int
string_table_t::to_index(const char *name) const
{
    if (prefix_len_)
    {
	if (strncmp(name, prefix_, prefix_len_))
	    return -1;
	name += prefix_len_;
    }

    for (int i = 0 ; names_[i] ; i++)
    {
	if (!strcmp(names_[i], name))
	    return i;
    }
    return -1;
}

const char *
string_table_t::to_name(int i) const
{
    if (i < 0 || i >= (int)names_count_ || names_[i][0] == '\0')
	return "unknown";
    if (prefix_len_)
    {
	// TODO: use an estring
	static char buf[256];
	strncpy(buf, prefix_, sizeof(buf));
	strncat(buf, names_[i], sizeof(buf)-prefix_len_);
	return buf;
    }
    else
    {
	return names_[i];
    }
}

// close namespace
} }<commit_msg>string_table::to_name more useful for unknowns<commit_after>#include "string_table.hxx"

namespace spiegel { namespace dwarf {
using namespace std;

int
string_table_t::to_index(const char *name) const
{
    if (prefix_len_)
    {
	if (strncmp(name, prefix_, prefix_len_))
	    return -1;
	name += prefix_len_;
    }

    for (int i = 0 ; names_[i] ; i++)
    {
	if (!strcmp(names_[i], name))
	    return i;
    }
    return -1;
}

const char *
string_table_t::to_name(int i) const
{
    const char *name;
    if (i < 0 || i >= (int)names_count_ || names_[i][0] == '\0')
	name = 0;
    else
	name = names_[i];

    static char buf[256];
    if (prefix_len_)
    {
	if (name)
	    snprintf(buf, sizeof(buf), "%s%s", prefix_, name);
	else
	    snprintf(buf, sizeof(buf), "%s0x%x", prefix_, (unsigned)i);
	name = buf;
    }
    else if (!name)
    {
	snprintf(buf, sizeof(buf), "0x%x", (unsigned)i);
	name = buf;
    }
    return name;
}

// close namespace
} }
{'fraction_non_alphanumeric': 0.15862068965517243, 'fraction_numerical': 0.01206896551724138, 'mean_word_length': 3.058275058275058, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1071465', 'n_tokens_mistral': 690, 'n_tokens_neox': 669, 'n_words': 167}