-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBdfError.cpp
More file actions
100 lines (76 loc) · 1.63 KB
/
Copy pathBdfError.cpp
File metadata and controls
100 lines (76 loc) · 1.63 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "BdfStringReader.hpp"
#include "BdfError.hpp"
#include <iostream>
#include <string>
#include <codecvt>
#include <locale>
using namespace Bdf;
const std::string ERRORS[5] = {
"Syntax error",
"End of file",
"Unescaped comment",
"Unescaped string",
"Number out of range",
};
BdfError::BdfError(const int code, BdfStringReader reader, int length)
{
type = code;
const wchar_t* start_of_line = reader.start;
int line = 0;
int at = 0;
if(reader.upto > reader.end - 2) {
reader.upto = reader.end - 2;
}
for(const wchar_t* i=reader.start;i<reader.upto;i++)
{
if(i[0] == '\n') {
start_of_line = i + 1;
line += 1;
at = 0;
continue;
}
at += 1;
}
int line_size = 0;
std::string spacer = "";
for(const wchar_t* i=start_of_line;i<reader.end;i++)
{
if(i[0] == '\n') {
break;
}
line_size += 1;
if(i == reader.end - 1) {
break;
}
if(i < reader.upto)
{
if(i[0] == '\t') {
spacer += "\t";
continue;
}
spacer += " ";
}
}
std::wstring_convert<std::codecvt_utf8<wchar_t>, wchar_t> cv;
error_short = ERRORS[code] + " " + std::to_string(line + 1) + ":" + std::to_string(at + 1);
message = error_short + "\n";
message += cv.to_bytes(std::wstring(start_of_line, line_size)) + "\n";
message += spacer;
for(int i=0;i<length;i++) {
message += "^";
}
}
BdfError::BdfError(const int code, BdfStringReader reader) : BdfError(code, reader, 1) {
}
std::string BdfError::getErrorShort() {
return error_short;
}
std::string BdfError::getError() {
return message;
}
int BdfError::getType() {
return type;
}
const char* BdfError::what() const throw() {
return message.c_str();
}