<commit_before>#include "calc.h"
#include <stdexcept>

// Calculates the result of two numbers a and b and basic math operator.
int calc(int a, int b, char operator_symbol) {
	switch (operator_symbol) {
		case '*': return a*b;
		case '/':
			if (b == 0) throw std::domain_error{"division by zero"};
			return a/b;
		case '+': return a+b;
		case '-': return a-b;
		case '%': return a%b;
	}
	throw std::invalid_argument{"invalid operator"};
}

// Just like calc(int, int, char), but gets the numbers and operator
// from an input stream.
int calc(std::istream& input) {
	int a {0}, b {0};
	char operator_symbol { };
	input >> a >> operator_symbol >> b;
	return calc(a, b, operator_symbol);
}<commit_msg>include invalid operator in exception message<commit_after>#include "calc.h"
#include <stdexcept>
#include <string>

// Calculates the result of two numbers a and b and basic math operator.
int calc(int a, int b, char operator_symbol) {
	switch (operator_symbol) {
		case '*': return a*b;
		case '/':
			if (b == 0) throw std::domain_error{"division by zero"};
			return a/b;
		case '+': return a+b;
		case '-': return a-b;
		case '%': return a%b;
	}

	auto reason = std::string("invalid operator: ");
	reason.push_back(operator_symbol);
	throw std::invalid_argument{reason};
};

// Just like calc(int, int, char), but gets the numbers and operator
// from an input stream.
int calc(std::istream& input) {
	int a {0}, b {0};
	char operator_symbol { };
	input >> a >> operator_symbol >> b;
	return calc(a, b, operator_symbol);
}
{'fraction_non_alphanumeric': 0.15248691099476439, 'fraction_numerical': 0.003926701570680628, 'mean_word_length': 4.096666666666667, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 18, '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': '5477206', 'n_tokens_mistral': 544, 'n_tokens_neox': 512, 'n_words': 179}