mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Made stringToSeverity(ore robust && Refactored if->swittch
This commit is contained in:
parent
830d740359
commit
053689d25d
@ -33,6 +33,8 @@
|
||||
#include <boost/preprocessor/facilities/overload.hpp>
|
||||
|
||||
#include <string>
|
||||
#include <regex>
|
||||
#include <optional>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <memory>
|
||||
@ -242,9 +244,17 @@ public:
|
||||
return "Error";
|
||||
}
|
||||
|
||||
static std::optional<std::string> stringToSeverity(Severity _severity)
|
||||
static std::optional<Severity> stringToSeverity(std::string _severity)
|
||||
{
|
||||
return _severity ? std::optional<std::string>{"Error, Warning, Info"} : std::nullopt;
|
||||
_severity = tolower(_severity);
|
||||
|
||||
_severity = std::regex_replace(_severity, std::regex("^ +| +$|( ) +"), "$1");
|
||||
|
||||
_severity.erase(_severity.begin(), std::find_if(_severity.begin(), _severity.end(), std::bind1st(std::not_equal_to<char>(), ' ')));
|
||||
|
||||
_severity[0] = toupper(_severity[0]);
|
||||
|
||||
return std::make_optional<Severity>(_severity).has_value() ? std::optional<Severity>(_severity).value() : std::nullopt;
|
||||
}
|
||||
|
||||
static std::string formatErrorSeverityLowercase(Severity _severity)
|
||||
|
@ -55,6 +55,13 @@ std::string SourceReferenceFormatter::formatErrorInformation(Error const& _error
|
||||
);
|
||||
}
|
||||
|
||||
enum class Severity//have to define if used in switch
|
||||
{
|
||||
Error,
|
||||
Warning,
|
||||
Info
|
||||
};
|
||||
|
||||
AnsiColorized SourceReferenceFormatter::normalColored() const
|
||||
{
|
||||
return AnsiColorized(m_stream, m_colored, {WHITE});
|
||||
@ -181,17 +188,18 @@ void SourceReferenceFormatter::printExceptionInformation(SourceReferenceExtracto
|
||||
// exception header line
|
||||
if (_msg.errorId.has_value())
|
||||
{
|
||||
if (_msg.severity == "Error")
|
||||
errorColored() << " (" << _msg.errorId.value().error << ")";
|
||||
switch(stringToSeverity(_msg.severity))
|
||||
{
|
||||
case Severity::Error : errorColored() << " (" << _msg.errorId.value().error << ")";
|
||||
break;
|
||||
|
||||
else if (_msg.severity == "Warning")
|
||||
warningColored() << " (" << _msg.errorId.value().error << ")";
|
||||
case Severity::Warning : warningColored() << " (" << _msg.errorId.value().error << ")";
|
||||
break;
|
||||
|
||||
else if (_msg.severity == "Info")
|
||||
infoColored() << " (" << _msg.errorId.value().error << ")";
|
||||
case Severity::Info : infoColored() << " (" << _msg.errorId.value().error << ")";
|
||||
break;
|
||||
|
||||
else
|
||||
unknownColored() << " (" << _msg.errorId.value().error << ")";
|
||||
default : unknownColored() << " (" << _msg.errorId.value().error << ")";
|
||||
}
|
||||
|
||||
printSourceLocation(_msg.primary);
|
||||
|
Loading…
Reference in New Issue
Block a user