-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVSifyLuaTraceback.cpp
More file actions
118 lines (102 loc) · 2.52 KB
/
Copy pathVSifyLuaTraceback.cpp
File metadata and controls
118 lines (102 loc) · 2.52 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include "VSifyLuaTraceback.h"
using namespace std;
namespace
{
//-------------------------------------------------------------------------
bool ReadLine(size_t& begin, const string& text, string& line)
{
size_t i = begin;
while (i < text.size())
{
if (text[i] == '\n')
{
line = text.substr(begin, i + 1 - begin);
begin = i + 1;
return true;
}
++i;
}
if (begin == text.size())
{
return false;
}
else
{
line = text.substr(begin, text.size() - begin);
begin = text.size();
return true;
}
}
//-------------------------------------------------------------------------
string ConvertLine(const string& line, bool first, const string& pathPrefix)
{
bool candidate = (first || (!line.empty() && line[0] == '\t'));
if (!candidate) { return line; }
size_t firstColonPos = line.find(':');
if (firstColonPos == string::npos) { return line; }
size_t secondColonPos = line.find(':', firstColonPos + 1);
if (secondColonPos == string::npos) { return line; }
for (size_t i = firstColonPos + 1; i < secondColonPos; ++i)
{
if (!isdigit(line[i])) { return line; }
}
// Nested error position {
if (secondColonPos + 2 < line.size() &&
line[secondColonPos + 1] == ' ' &&
line[secondColonPos + 2] == '$')
{
string rest = line.substr(secondColonPos + 3);
string convertedRest = ConvertLine(rest, first, pathPrefix);
if (rest != convertedRest)
{
return convertedRest;
}
}
// Nested error position }
size_t begin = first ? 0 : 1;
string path = line.substr(begin, firstColonPos - begin);
if (path.substr(0, 9) == "[string \"" &&
path.substr(path.length() - 2) == "\"]")
{
path = path.substr(9, path.length() - 11);
}
if (path.substr(0, 2) == ".\\")
{
path = path.substr(2);
}
for (size_t i = 0; i < path.length(); ++i)
{
if (path[i] == '/') { path[i] = '\\'; }
}
string rv;
rv.reserve(line.size() + pathPrefix.size() + 5);
if (!first)
{
rv = "\t";
}
rv += pathPrefix;
rv += path;
rv += "(";
rv += line.substr(firstColonPos + 1, secondColonPos - firstColonPos - 1);
rv += ")";
rv += line.substr(secondColonPos);
return rv;
}
}
//-----------------------------------------------------------------------------
string VSifyLuaTraceback(
const string& traceback,
const string& pathPrefix)
{
string rv;
rv.reserve(traceback.size());
bool first = true;
size_t begin = 0;
string line;
while (ReadLine(begin, traceback, line))
{
rv += ConvertLine(line, first, pathPrefix);
first = false;
}
return rv;
}