<commit_before>#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

#include "Tools/Exception/exception.hpp"
#include "Tools/general_utils.h"

#include "AList.hpp"

using namespace aff3ct::tools;

Sparse_matrix AList
::read(std::istream &stream)
{
	// save the init pos of the stream
	auto init_pos = stream.tellg();

	try
	{
		return AList::read_format1(stream);
	}
	catch (std::exception const&)
	{
		try
		{
			stream.clear();
			stream.seekg(init_pos);
			return AList::read_format2(stream);
		}
		catch (std::exception const&)
		{
			try
			{
				stream.clear();
				stream.seekg(init_pos);
				return AList::read_format3(stream);
			}
			catch (std::exception const&)
			{
				std::stringstream message;
				message << "The given stream does not refer to a AList format file.";
				throw runtime_error(__FILE__, __LINE__, __func__, message.str());
			}
		}
	}
}

void AList
::write(const Sparse_matrix &matrix, std::ostream &stream)
{
	stream << matrix.get_n_rows()          << " " << matrix.get_n_cols()          << std::endl << std::endl;
	stream << matrix.get_rows_max_degree() << " " << matrix.get_cols_max_degree() << std::endl << std::endl;

	for (const auto &r : matrix.get_row_to_cols())
		stream << r.size() << " ";
	stream << std::endl << std::endl;

	for (const auto &c : matrix.get_col_to_rows())
		stream << c.size() << " ";
	stream << std::endl << std::endl;

	for (const auto &r : matrix.get_row_to_cols())
	{
		unsigned i;
		for (i = 0; i < r.size(); i++)
			stream << (r[i] +1) << " ";
		for (; i < matrix.get_rows_max_degree(); i++)
			stream << 0 << " ";
		stream << std::endl;
	}
	stream << std::endl;
<commit_msg>Return the exception messages when the Alist format is not respected.<commit_after>#include <string>
#include <sstream>
#include <vector>
#include <algorithm>

#include "Tools/Exception/exception.hpp"
#include "Tools/general_utils.h"

#include "AList.hpp"

using namespace aff3ct::tools;

Sparse_matrix AList
::read(std::istream &stream)
{
	// save the init pos of the stream
	auto init_pos = stream.tellg();

	try
	{
		return AList::read_format1(stream);
	}
	catch (std::exception const& e1)
	{
		auto save = exception::no_backtrace;
		exception::no_backtrace = true;

		std::stringstream message;
		message << "The given stream does not refer to a AList format file: ";
		message << std::endl << e1.what();
		exception::no_backtrace = save;

		try
		{
			stream.clear();
			stream.seekg(init_pos);
			return AList::read_format2(stream);
		}
		catch (std::exception const& e2)
		{
			auto save = exception::no_backtrace;
			exception::no_backtrace = true;
			message << std::endl << e2.what();
			exception::no_backtrace = save;

			try
			{
				stream.clear();
				stream.seekg(init_pos);
				return AList::read_format3(stream);
			}
			catch (std::exception const& e3)
			{
				auto save = exception::no_backtrace;
				exception::no_backtrace = true;
				message << std::endl << e3.what();
				exception::no_backtrace = save;

				throw runtime_error(__FILE__, __LINE__, __func__, message.str());
			}
		}
	}
}

void AList
::write(const Sparse_matrix &matrix, std::ostream &stream)
{
	stream << matrix.get_n_rows()          << " " << matrix.get_n_cols()          << std::endl << std::endl;
	stream << matrix.get_rows_max_degree() << " " << matrix.get_cols_max_degree() << std::endl << std::endl;

	for (const auto &r : matrix.get_row_to_cols())
		stream << r.size() << " ";
	stream << std::endl << std::endl;

	for (const auto &c : matrix.get_col_to_rows())
		stream << c.size() << " ";
	stream << std::endl << std::endl;

	for (const auto &r : matrix.get_row_to_cols())
	{
		unsigned i;
		for (i = 0; i < r.size(); i++)
			stream << (r[i] +1) << " ";
		for (; i < matrix.get_rows_max_degree(); i++)
			stream << 0 << " ";
		stream << std::endl;
	}
	stream << std::endl;

{'fraction_non_alphanumeric': 0.17014069828035436, 'fraction_numerical': 0.005211047420531527, 'mean_word_length': 3.780821917808219, 'pattern_counts': {'":': 0, '<': 127, '<?xml version=': 0, '>': 11, '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': '2630456', 'n_tokens_mistral': 1506, 'n_tokens_neox': 1359, 'n_words': 313}