1 // -*- mode: c++; tab-width: 4; indent-tabs-mode: t; eval: (progn (c-set-style "stroustrup") (c-set-offset 'innamespace 0)); -*-
2 // vi:set ts=4 sts=4 sw=4 noet :
3 //
4 // Copyright 2010-2020 wkhtmltopdf authors
5 //
6 // This file is part of wkhtmltopdf.
7 //
8 // wkhtmltopdf is free software: you can redistribute it and/or modify
9 // it under the terms of the GNU Lesser General Public License as published by
10 // the Free Software Foundation, either version 3 of the License, or
11 // (at your option) any later version.
12 //
13 // wkhtmltopdf is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 // GNU General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public License
19 // along with wkhtmltopdf.  If not, see <http://www.gnu.org/licenses/>.
20 
21 #include "logging.hh"
22 #include <QMap>
23 #include <QString>
24 #include <dllbegin.inc>
25 namespace wkhtmltopdf {
26 namespace settings {
27 
28 // Centralized name-to-enum value mapping
logLevelMap()29 QMap<QString, LogLevel> logLevelMap() {
30 	QMap<QString, LogLevel> res;
31 	res["none"] = None;
32 	res["error"] = Error;
33 	res["warn"] = Warn;
34 	res["info"] = Info;
35 	return res;
36 }
37 
38 QMap<QString, LogLevel> logLevels = logLevelMap();
39 
strToLogLevel(const char * s,bool * ok)40 LogLevel strToLogLevel(const char * s, bool * ok) {
41 	for (QMap<QString, LogLevel>::const_iterator i = logLevels.begin(); i != logLevels.end(); ++i) {
42 		if (i.key().compare(s, Qt::CaseInsensitive) != 0) continue;
43 		if (ok) *ok = true;
44 		return i.value();
45 	}
46 	if (ok) *ok = false;
47 	return Info;
48 }
49 
logLevelToStr(const LogLevel & l,bool * ok)50 QString logLevelToStr(const LogLevel & l, bool * ok) {
51 	for (QMap<QString, LogLevel>::const_iterator i = logLevels.begin(); i != logLevels.end(); ++i) {
52 		if (i.value() != l) continue;
53 		if (ok) *ok = true;
54 		return i.key();
55 	}
56 	if (ok) *ok = false;
57 	return QString();
58 }
59 
60 }
61 }
62 #include <dllend.inc>
63