BSON: Reworked `binary_reader::get_bson_cstr()`

pull/1254/head
Julian Becker 2018-09-29 11:50:01 +02:00
parent 0a09db9cc2
commit e8730e5e82
2 changed files with 22 additions and 40 deletions

View File

@ -125,36 +125,27 @@ class binary_reader
private:
template<class OutputIt, class UnaryPredicate, class Gen>
OutputIt generate_until(OutputIt&& d_first, UnaryPredicate&& pred, Gen&& gen)
{
for (auto x = gen(); !pred(x); x = gen())
{
*d_first++ = x;
}
return d_first;
}
/*!
@return whether array creation completed
*/
bool get_bson_cstr(string_t& result)
{
bool success = true;
generate_until(std::back_inserter(result), [&success](char c)
{
return c == 0x00 || !success;
}, [this, &success]
auto out = std::back_inserter(result);
while (true)
{
get();
if (JSON_UNLIKELY(not unexpect_eof()))
{
success = false;
return false;
}
return static_cast<char>(current);
});
return success;
if (current == 0x00)
{
return true;
}
*out++ = static_cast<char>(current);
}
return true;
}
bool parse_bson_entries(bool is_array)

View File

@ -6109,36 +6109,27 @@ class binary_reader
private:
template<class OutputIt, class UnaryPredicate, class Gen>
OutputIt generate_until(OutputIt&& d_first, UnaryPredicate&& pred, Gen&& gen)
{
for (auto x = gen(); !pred(x); x = gen())
{
*d_first++ = x;
}
return d_first;
}
/*!
@return whether array creation completed
*/
bool get_bson_cstr(string_t& result)
{
bool success = true;
generate_until(std::back_inserter(result), [&success](char c)
{
return c == 0x00 || !success;
}, [this, &success]
auto out = std::back_inserter(result);
while (true)
{
get();
if (JSON_UNLIKELY(not unexpect_eof()))
{
success = false;
return false;
}
return static_cast<char>(current);
});
return success;
if (current == 0x00)
{
return true;
}
*out++ = static_cast<char>(current);
}
return true;
}
bool parse_bson_entries(bool is_array)