Commit e8730e5e authored by Julian Becker's avatar Julian Becker

BSON: Reworked `binary_reader::get_bson_cstr()`

parent 0a09db9c
...@@ -125,36 +125,27 @@ class binary_reader ...@@ -125,36 +125,27 @@ class binary_reader
private: 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 @return whether array creation completed
*/ */
bool get_bson_cstr(string_t& result) bool get_bson_cstr(string_t& result)
{ {
bool success = true; auto out = std::back_inserter(result);
generate_until(std::back_inserter(result), [&success](char c) while (true)
{
return c == 0x00 || !success;
}, [this, &success]
{ {
get(); get();
if (JSON_UNLIKELY(not unexpect_eof())) if (JSON_UNLIKELY(not unexpect_eof()))
{ {
success = false; return false;
} }
return static_cast<char>(current); if (current == 0x00)
}); {
return success; return true;
}
*out++ = static_cast<char>(current);
}
return true;
} }
bool parse_bson_entries(bool is_array) bool parse_bson_entries(bool is_array)
......
...@@ -6109,36 +6109,27 @@ class binary_reader ...@@ -6109,36 +6109,27 @@ class binary_reader
private: 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 @return whether array creation completed
*/ */
bool get_bson_cstr(string_t& result) bool get_bson_cstr(string_t& result)
{ {
bool success = true; auto out = std::back_inserter(result);
generate_until(std::back_inserter(result), [&success](char c) while (true)
{
return c == 0x00 || !success;
}, [this, &success]
{ {
get(); get();
if (JSON_UNLIKELY(not unexpect_eof())) if (JSON_UNLIKELY(not unexpect_eof()))
{ {
success = false; return false;
} }
return static_cast<char>(current); if (current == 0x00)
}); {
return success; return true;
}
*out++ = static_cast<char>(current);
}
return true;
} }
bool parse_bson_entries(bool is_array) bool parse_bson_entries(bool is_array)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment