Use string_view where appropriate for parser, add some additional constructors for ease of use
This commit is contained in:
parent
4d1901534f
commit
10fa97e6b8
|
|
@ -1033,7 +1033,7 @@ static void DecompileEntity(
|
|||
continue;
|
||||
} else if (modelNum > 0 && keyValue.first == "origin") {
|
||||
auto &value = keyValue.second;
|
||||
parser_t parser(value.data(), value.data() + value.size());
|
||||
parser_t parser(value);
|
||||
qvec3d vec;
|
||||
parser.parse_token();
|
||||
vec[0] = stof(parser.token);
|
||||
|
|
|
|||
|
|
@ -117,7 +117,7 @@ keyvalues_t::iterator entdict_t::end()
|
|||
std::vector<entdict_t> EntData_Parse(const std::string &entdata)
|
||||
{
|
||||
std::vector<entdict_t> result;
|
||||
parser_t parser(entdata.data(), entdata.data() + entdata.size());
|
||||
parser_t parser(entdata);
|
||||
|
||||
/* go through all the entities */
|
||||
while (1) {
|
||||
|
|
|
|||
|
|
@ -47,7 +47,15 @@ struct parser_t
|
|||
uint32_t linenum = 1;
|
||||
std::string token;
|
||||
|
||||
parser_t(const char *data, const char *in_end) : pos(data), end(in_end) { }
|
||||
// base constructor; accept raw start & length
|
||||
parser_t(const void *start, size_t length) : pos(reinterpret_cast<const char *>(start)), end(reinterpret_cast<const char *>(start) + length) { }
|
||||
|
||||
// pull from string_view; note that the string view must live for the entire
|
||||
// duration of the parser's life time
|
||||
parser_t(const std::string_view &view) : parser_t(&view.front(), view.size()) { }
|
||||
|
||||
// pull from C string; made explicit because this is error-prone
|
||||
explicit parser_t(const char *str) : parser_t(str, strlen(str)) { }
|
||||
|
||||
bool parse_token(parseflags flags = PARSE_NORMAL);
|
||||
|
||||
|
|
|
|||
|
|
@ -1404,7 +1404,7 @@ bool ParseLightsFile(const std::filesystem::path &fname)
|
|||
while (!f.eof()) {
|
||||
std::getline(f, buf);
|
||||
|
||||
parser_t parser(buf.data(), buf.data() + buf.size());
|
||||
parser_t parser(buf);
|
||||
|
||||
if (!parser.parse_token())
|
||||
continue;
|
||||
|
|
|
|||
|
|
@ -1847,8 +1847,7 @@ mapentity_t LoadExternalMap(const char *filename)
|
|||
FError("Couldn't load external map file \"{}.\"\n", filename);
|
||||
}
|
||||
|
||||
const char *begin = reinterpret_cast<const char *>(file->data());
|
||||
parser_t parser(begin, begin + file->size());
|
||||
parser_t parser(file->data(), file->size());
|
||||
|
||||
// parse the worldspawn
|
||||
if (!ParseEntity(parser, &dest)) {
|
||||
|
|
@ -1896,8 +1895,7 @@ void LoadMapFile(void)
|
|||
return;
|
||||
}
|
||||
|
||||
const char *begin = reinterpret_cast<const char *>(file->data());
|
||||
parser_t parser(begin, begin + file->size());
|
||||
parser_t parser(file->data(), file->size());
|
||||
|
||||
for (int i = 0;; i++) {
|
||||
mapentity_t &entity = map.entities.emplace_back();
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ static mapentity_t LoadMap(const char *map)
|
|||
options.target_version = &bspver_q1;
|
||||
options.target_game = options.target_version->game;
|
||||
|
||||
parser_t parser(map, map + strlen(map));
|
||||
parser_t parser(map);
|
||||
|
||||
mapentity_t worldspawn;
|
||||
// FIXME: adds the brush to the global map...
|
||||
|
|
|
|||
Loading…
Reference in New Issue