<commit_before>/* <x0/Severity.cpp>
 *
 * This file is part of the x0 web server project and is released under LGPL-3.
 * http://www.xzero.io/
 *
 * (c) 2009-2012 <NAME> <<EMAIL>>
 */

#include <x0/Severity.h>
#include <x0/strutils.h>

namespace x0 {

Severity::Severity(const std::string& name)
{
	if (name == "error")
		value_ = error;
	else if (name == "warning" || name == "warn" || name.empty()) // <- default: warn
		value_ = warning;
	else if (name == "notice")
		value_ = notice;
	else if (name == "info")
		value_ = info;
	else if (name == "debug")
		value_ = debug;
	else
		throw std::runtime_error(fstringbuilder::format("Invalid Severity '%s'", name.c_str()));
}

const char *Severity::c_str() const
{
	switch (value_) {
		case error: return "error";
		case warning: return "warning";
		case notice: return "notice";
		case info: return "info";
		case debug1: return "debug:1";
		case debug2: return "debug:2";
		case debug3: return "debug:3";
		case debug4: return "debug:4";
		case debug5: return "debug:5";
		case debug6: return "debug:6";
		default: return "UNKNOWN";
	}
}

} // namespace x0<commit_msg>[base] Severity: adapted to changes in API<commit_after>/* <x0/Severity.cpp>
 *
 * This file is part of the x0 web server project and is released under LGPL-3.
 * http://www.xzero.io/
 *
 * (c) 2009-2012 <NAME> <<EMAIL>>
 */

#include <x0/Severity.h>
#include <x0/strutils.h>
#include <map>

namespace x0 {

Severity::Severity(const std::string& value)
{
	std::map<std::string, Severity> map = {
		{ "err", Severity::error },
		{ "error", Severity::error },
		{ "", Severity::warn }, // empty string defaults to warning-level
		{ "warn", Severity::warn },
		{ "warning", Severity::warn },
		{ "notice", Severity::notice },
		{ "info", Severity::info },
		{ "debug", Severity::debug },
		{ "debug1", Severity::debug1 },
		{ "debug2", Severity::debug2 },
		{ "debug3", Severity::debug3 },
		{ "debug4", Severity::debug4 },
		{ "debug5", Severity::debug5 },
		{ "debug6", Severity::debug6 },
	};

	auto i = map.find(value);
	if (i != map.end()) {
		value_ = i->second;
	} else {
		value_ = std::max(std::min(9, atoi(value.c_str())), 0);
		// throw std::runtime_error(fstringbuilder::format("Invalid Severity '%s'", value.c_str()));
	}
}

const char *Severity::c_str() const
{
	switch (value_) {
		case error: return "error";
		case warning: return "warning";
		case notice: return "notice";
		case info: return "info";
		case debug1: return "debug:1";
		case debug2: return "debug:2";
		case debug3: return "debug:3";
		case debug4: return "debug:4";
		case debug5: return "debug:5";
		case debug6: return "debug:6";
		default: return "UNKNOWN";
	}
}

} // namespace x0
{'fraction_non_alphanumeric': 0.1851024208566108, 'fraction_numerical': 0.02532588454376164, 'mean_word_length': 4.058380414312618, 'pattern_counts': {'":': 0, '<': 18, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5285903', 'n_tokens_mistral': 1048, 'n_tokens_neox': 988, 'n_words': 264}