Skip to content

Commit 301467a

Browse files
Declared severityFromString function
1 parent 4f224cc commit 301467a

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

liblangutil/Exceptions.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ Error::Error(
7272
*this << util::errinfo_comment(_description);
7373
}
7474

75-
static std::optional<Severity> severityFromString(std::string _severity)
75+
static optional<Severity> severityFromString(string _severity)
7676
{
7777
boost::algorithm::to_lower(_severity);
7878

7979
_severity = boost::algorithm::trim_copy(_severity);
8080

81-
_severity[0] = toupper(_severity[0]);
81+
if (_severity == formatErrorSeverityLowercase(Severity::Error)) { return Severity::Error; }
8282

83-
return std::make_optional<std::string>(_severity).has_value() ? std::optional<std::string>(_severity) : std::nullopt;
83+
else if (_severity == formatErrorSeverityLowercase(Severity::Warning)) { return Severity::Warning; }
84+
85+
else if (_severity == formatErrorSeverityLowercase(Severity::Info)) { return Severity::Info; }
86+
87+
else return std::make_optional<Severity>(_severity).has_value() ? std::optional<Severity>(_severity) : std::nullopt;
8488
}

liblangutil/Exceptions.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ class Error: virtual public util::Exception
152152
return nullptr;
153153
}
154154

155+
static std::optional<Severity> severityFromString(std::string _severity);
156+
155157
static Severity errorSeverity(Type _type)
156158
{
157159
if (_type == Type::Info)

0 commit comments

Comments
 (0)