fix/clean up compileblockstr
parent
be71d3a4b9
commit
3905ff0e9d
|
@ -466,38 +466,42 @@ static bool compileblockstr(cs_gen_state &gs, char const *str, char const *send)
|
||||||
gs.code.reserve(gs.code.size() + (send - str) / sizeof(uint32_t) + 1);
|
gs.code.reserve(gs.code.size() + (send - str) / sizeof(uint32_t) + 1);
|
||||||
char *buf = new char[((send - str) / sizeof(uint32_t) + 1) * sizeof(uint32_t)];
|
char *buf = new char[((send - str) / sizeof(uint32_t) + 1) * sizeof(uint32_t)];
|
||||||
int len = 0;
|
int len = 0;
|
||||||
for (auto it = str; it != send; ++it) {
|
while (str < send) {
|
||||||
char const *p = it;
|
|
||||||
std::string_view chrs{"\r/\"@]"};
|
std::string_view chrs{"\r/\"@]"};
|
||||||
it = std::find_first_of(it, send, chrs.begin(), chrs.end());
|
char const *orig = str;
|
||||||
memcpy(&buf[len], p, std::size_t(it - p));
|
str = std::find_first_of(str, send, chrs.begin(), chrs.end());
|
||||||
len += (it - p);
|
memcpy(&buf[len], orig, str - orig);
|
||||||
if (it == send) {
|
len += (str - orig);
|
||||||
|
if (str == send) {
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
switch (*it) {
|
switch (*str) {
|
||||||
case '\r':
|
case '\r':
|
||||||
++it;
|
++str;
|
||||||
break;
|
break;
|
||||||
case '\"': {
|
case '\"': {
|
||||||
char const *start = it;
|
char const *start = str;
|
||||||
it = util::parse_string(
|
str = util::parse_string(
|
||||||
gs.cs, std::string_view{it, std::size_t(send - it)}
|
gs.cs, std::string_view{str, send}
|
||||||
);
|
);
|
||||||
memcpy(&buf[len], start, std::size_t(it - start));
|
memcpy(&buf[len], start, std::size_t(str - start));
|
||||||
len += (it - start);
|
len += (str - start);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case '/':
|
case '/':
|
||||||
if (((it + 1) != send) && it[1] == '/') {
|
if (((str + 1) != send) && str[1] == '/') {
|
||||||
it = std::find(it, send, '\n');
|
str = std::find(str, send, '\n');
|
||||||
} else {
|
} else {
|
||||||
buf[len++] = *it++;
|
buf[len++] = *str++;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case '@':
|
case '@':
|
||||||
case ']':
|
case ']':
|
||||||
buf[len++] = *it++;
|
if (str < send) {
|
||||||
|
buf[len++] = *str++;
|
||||||
|
} else {
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue