<commit_before>#include "card.h"

#include <QDebug>

Card::Card()
{
}

void Card::setInfo(const pa_card_info *info)
{
    m_index = info->index;
    m_name = QString::fromUtf8(info->name);
    m_driver = QString::fromUtf8(info->driver);

    qDebug() << "processing card" << info->index << info->name;

    m_profiles.clear();
#warning more inconsistent api... profiels end with entry with name on null...
    for (auto *it = info->profiles; it->name != nullptr; ++it) {
        CardProfile profile;
        profile.setInfo(it);
        m_profiles.append(profile);
        if (info->active_profile == it) {
            qDebug() << "+++++++++++++++++ profile " << it->description << " appears the active one at index: "<< m_profiles.length() - 1;
            m_activeProfileIndex = m_profiles.length() - 1;
        }
    }

#warning there is no active port prop so it is possible that this is actually very worthless since we have sinks and sources
    m_ports.clear();
    for (auto **it = info->ports; *it != nullptr; ++it) {
        CardPort port;
        port.setInfo(*it);
        m_ports.append(port);
    }

    void *it = nullptr;
    while (const char *key = pa_proplist_iterate(info->proplist, &it)) {
        Q_ASSERT(key);
        const char *value = pa_proplist_gets(info->proplist, key);
        if (!value) {
            qDebug() << "property" << key << "not a string";
            continue;
        }
        Q_ASSERT(value);
        m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value));
    }
}<commit_msg>prevent crash when a card has no ports<commit_after>#include "card.h"

#include <QDebug>

Card::Card()
{
}

void Card::setInfo(const pa_card_info *info)
{
    m_index = info->index;
    m_name = QString::fromUtf8(info->name);
    m_driver = QString::fromUtf8(info->driver);

    qDebug() << "processing card" << info->index << info->name;

    m_profiles.clear();
#warning more inconsistent api... profiels end with entry with name on null...
    for (auto *it = info->profiles; it->name != nullptr; ++it) {
        CardProfile profile;
        profile.setInfo(it);
        m_profiles.append(profile);
        if (info->active_profile == it) {
            qDebug() << "+++++++++++++++++ profile " << it->description << " appears the active one at index: "<< m_profiles.length() - 1;
            m_activeProfileIndex = m_profiles.length() - 1;
        }
    }

#warning there is no active port prop so it is possible that this is actually very worthless since we have sinks and sources
    m_ports.clear();
    for (auto **it = info->ports; it && *it != nullptr; ++it) {
        CardPort port;
        port.setInfo(*it);
        m_ports.append(port);
    }

    void *it = nullptr;
    while (const char *key = pa_proplist_iterate(info->proplist, &it)) {
        Q_ASSERT(key);
        const char *value = pa_proplist_gets(info->proplist, key);
        if (!value) {
            qDebug() << "property" << key << "not a string";
            continue;
        }
        Q_ASSERT(value);
        m_properties.insert(QString::fromUtf8(key), QString::fromUtf8(value));
    }
}
{'fraction_non_alphanumeric': 0.15439047925377936, 'fraction_numerical': 0.0038597619813444837, 'mean_word_length': 2.7290167865707433, 'pattern_counts': {'":': 0, '<': 45, '<?xml version=': 0, '>': 29, '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': '1489713', 'n_tokens_mistral': 1000, 'n_tokens_neox': 968, 'n_words': 254}