forked from ElektraInitiative/libelektra
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkconfig_parser_exception.cpp
More file actions
56 lines (50 loc) · 1.48 KB
/
kconfig_parser_exception.cpp
File metadata and controls
56 lines (50 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "kconfig_parser_exception.hpp"
#include "base.hpp"
#include "file_utility.hpp"
#include <sstream>
namespace kconfig
{
KConfigParserException::KConfigParserException (FileUtility const & fileUtility, std::string const & errorMessage)
{
message = generateErrorMessage (fileUtility.getFilename (), fileUtility.getCurrentLineNumber (), errorMessage);
}
KConfigParserException KConfigParserException::expect (FileUtility & fileUtility, char expected)
{
return expect (fileUtility, describeCharacter (expected));
}
KConfigParserException KConfigParserException::expect (FileUtility & fileUtility, std::string const & expectedValue)
{
std::string foundValue{ describeCharacter (fileUtility.peekNextChar ()) };
return { fileUtility, "Expected " + expectedValue + " character, found " + foundValue };
}
std::string KConfigParserException::generateErrorMessage (std::string const & filename, int lineNumber, std::string const & message)
{
std::stringstream errorMessage;
errorMessage << "Error while parsing " << filename;
if (lineNumber != 0)
{
errorMessage << " at line " << lineNumber;
}
errorMessage << ": ";
errorMessage << message;
return errorMessage.str ();
}
std::string KConfigParserException::describeCharacter (char c)
{
if (c == character_newline || c == character_carriage_return)
{
return "new line";
}
else
{
std::string ret{ "`" };
ret.push_back (c);
ret.push_back ('`');
return ret;
}
}
std::string KConfigParserException::getMessage () const
{
return message;
}
}