<commit_before>//
// PROJECT:         Aspia Remote Desktop
// FILE:            ui/system_info/report_creator.cc
// LICENSE:         Mozilla Public License Version 2.0
// PROGRAMMERS:     <NAME> (<EMAIL>)
//

#include "base/logging.h"
#include "ui/system_info/report_creator_proxy.h"

namespace aspia {

ReportCreator::ReportCreator(CategoryList* list, Output* output, RequestCallback request_callback)
    : request_callback_(std::move(request_callback)),
      list_(list),
      output_(output)
{
    DCHECK(request_callback_);
    DCHECK(list_);
    DCHECK(output_);

    proxy_.reset(new ReportCreatorProxy(this));
}

ReportCreator::~ReportCreator()
{
    proxy_->WillDestroyCurrentReportCreator();
    proxy_ = nullptr;
}

void ReportCreator::Start(StateChangeCallback state_change_callback,
                          TerminateCallback terminate_callback)
{
    state_change_callback_ = std::move(state_change_callback);
    terminate_callback_ = std::move(terminate_callback);
    ProcessNextItem();
}

void ReportCreator::ProcessNextItem()
{
    if (iterator_stack_.empty())
    {
        iterator_stack_.emplace(list_, list_->begin());
        output_->StartDocument();
    }

    CategoryList* list = iterator_stack_.top().first;
    CategoryList::iterator& iterator = iterator_stack_.top().second;

    if (iterator == list->end())
    {
        iterator_stack_.pop();

        if (iterator_stack_.empty())
        {
            output_->EndDocument();
            terminate_callback_();
            return;
        }

        output_->EndTableGroup();
    }
    else
    {
        Category* category = iterator->get();
        DCHECK(category);

        if (category->type() == Category::Type::INFO_LIST ||
            category->type() == Category::Type::INFO_PARAM_VALUE)
        {
            CategoryInfo* category_info = category->category_info();

            if (category_info->IsChecked())
            {
                state_change_callback_(category_info->Name(), State::REQUEST);
                request_callback_(category_info->Guid(), proxy_);
                return;
            }
        }
        else
        {
            DCHECK(category->type() == Category::Type::GROUP);

            CategoryGroup* category_group = category->category_group();

            if (HasCheckedItems(category_group))
            {
                output_->StartTableGroup(category_group->Name());

                iterator_stack_.emplace(category_group->mutable_child_list(),
                                        category_group->mutable_child_list()->begin());
            }
        }

        ++iterator;
    }

    ProcessNextItem();
}

// static
bool ReportCreator::HasCheckedItems(CategoryGroup* parent_group)
{
    const CategoryList& child_list = parent_group->child_list();

    for (CategoryList::const_iterator iter = child_list.cbegin();
         iter != child_list.end();
         ++iter)
    {
        Category* category = iter->get();

        if (category->type() == Category::Type::INFO_LIST ||
            category->type() == Category::Type::INFO_PARAM_VALUE)
        {
            if (category->category_info()->IsChecked())
                return true;
        }
        else
        {
            DCHECK(category->type() == Category::Type::GROUP);

            if (HasCheckedItems(category->category_group()))
                return true;
        }
    }

    return false;
}

void ReportCreator::Parse(const std::string& data)
{
    CategoryList::iterator& iterator = iterator_stack_.top().second;

    Category* category = iterator->get();
    DCHECK(category);

    CategoryInfo* category_info = category->category_info();

    state_change_callback_(category_info->Name(), State::OUTPUT);

    {
        Table table = Table::Create(output_, category);
        category_info->Parse(table, data);
        category_info->SetChecked(false);
    }

    ++iterator;

    ProcessNextItem();
}

} // namespace aspia<commit_msg>- Added checking for an empty string.<commit_after>//
// PROJECT:         Aspia Remote Desktop
// FILE:            ui/system_info/report_creator.cc
// LICENSE:         Mozilla Public License Version 2.0
// PROGRAMMERS:     <NAME> (<EMAIL>)
//

#include "base/logging.h"
#include "ui/system_info/report_creator_proxy.h"

namespace aspia {

ReportCreator::ReportCreator(CategoryList* list, Output* output, RequestCallback request_callback)
    : request_callback_(std::move(request_callback)),
      list_(list),
      output_(output)
{
    DCHECK(request_callback_);
    DCHECK(list_);
    DCHECK(output_);

    proxy_.reset(new ReportCreatorProxy(this));
}

ReportCreator::~ReportCreator()
{
    proxy_->WillDestroyCurrentReportCreator();
    proxy_ = nullptr;
}

void ReportCreator::Start(StateChangeCallback state_change_callback,
                          TerminateCallback terminate_callback)
{
    state_change_callback_ = std::move(state_change_callback);
    terminate_callback_ = std::move(terminate_callback);
    ProcessNextItem();
}

void ReportCreator::ProcessNextItem()
{
    if (iterator_stack_.empty())
    {
        iterator_stack_.emplace(list_, list_->begin());
        output_->StartDocument();
    }

    CategoryList* list = iterator_stack_.top().first;
    CategoryList::iterator& iterator = iterator_stack_.top().second;

    if (iterator == list->end())
    {
        iterator_stack_.pop();

        if (iterator_stack_.empty())
        {
            output_->EndDocument();
            terminate_callback_();
            return;
        }

        output_->EndTableGroup();
    }
    else
    {
        Category* category = iterator->get();
        DCHECK(category);

        if (category->type() == Category::Type::INFO_LIST ||
            category->type() == Category::Type::INFO_PARAM_VALUE)
        {
            CategoryInfo* category_info = category->category_info();

            if (category_info->IsChecked())
            {
                state_change_callback_(category_info->Name(), State::REQUEST);
                request_callback_(category_info->Guid(), proxy_);
                return;
            }
        }
        else
        {
            DCHECK(category->type() == Category::Type::GROUP);

            CategoryGroup* category_group = category->category_group();

            if (HasCheckedItems(category_group))
            {
                output_->StartTableGroup(category_group->Name());

                iterator_stack_.emplace(category_group->mutable_child_list(),
                                        category_group->mutable_child_list()->begin());
            }
        }

        ++iterator;
    }

    ProcessNextItem();
}

// static
bool ReportCreator::HasCheckedItems(CategoryGroup* parent_group)
{
    const CategoryList& child_list = parent_group->child_list();

    for (CategoryList::const_iterator iter = child_list.cbegin();
         iter != child_list.end();
         ++iter)
    {
        Category* category = iter->get();

        if (category->type() == Category::Type::INFO_LIST ||
            category->type() == Category::Type::INFO_PARAM_VALUE)
        {
            if (category->category_info()->IsChecked())
                return true;
        }
        else
        {
            DCHECK(category->type() == Category::Type::GROUP);

            if (HasCheckedItems(category->category_group()))
                return true;
        }
    }

    return false;
}

void ReportCreator::Parse(const std::string& data)
{
    CategoryList::iterator& iterator = iterator_stack_.top().second;

    Category* category = iterator->get();
    DCHECK(category);

    CategoryInfo* category_info = category->category_info();

    state_change_callback_(category_info->Name(), State::OUTPUT);

    {
        Table table = Table::Create(output_, category);

        if (!data.empty())
            category_info->Parse(table, data);

        category_info->SetChecked(false);
    }

    ++iterator;

    ProcessNextItem();
}

} // namespace aspia
{'fraction_non_alphanumeric': 0.1273709332998367, 'fraction_numerical': 0.0005024494410249969, 'mean_word_length': 2.4617391304347827, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5903909', 'n_tokens_mistral': 2172, 'n_tokens_neox': 2119, 'n_words': 345}