14void ReplaceAll(std::string& in_out, std::string_view search, std::string_view substitute)
16 if (search.empty())
return;
17 auto pos{in_out.find(search)};
18 if (pos == std::string::npos)
return;
22 result.reserve(in_out.size());
23 std::string::size_type start{0};
24 for (; pos != std::string::npos; pos = in_out.find(search, start)) {
25 result.append(in_out, start, pos - start).append(substitute);
26 start = pos + search.size();
28 result.append(in_out, start);
33 : m_str{str}, m_max_line_length{max_line_length}, m_it{str.begin()} {}
41 const auto line_start =
m_it;
44 const bool new_line{*
m_it ==
'\n'};
49 std::string_view line{line_start,
m_it - 1};
50 if (!line.empty() && line.back() ==
'\r')
51 line.remove_suffix(1);
60 throw std::runtime_error(
"max_line_length exceeded by LineReader");
73 if (len == 0)
return {};
74 if (
Remaining() < len)
throw std::runtime_error(
"Not enough data in buffer");
75 std::string_view
out(std::to_address(
m_it), len);
87 return std::distance(
m_str.begin(),
m_it);
const size_t m_max_line_length
size_t Consumed() const
Returns number of bytes already read from buffer.
std::optional< std::string_view > ReadLine() LIFETIMEBOUND
Returns a string from current iterator position up to (but not including) next and advances iterator...
size_t Remaining() const
Returns remaining size of bytes in buffer.
const std::string_view m_str
LineReader(std::string_view str LIFETIMEBOUND, size_t max_line_length)
std::string_view ReadLength(size_t len) LIFETIMEBOUND
Returns string from current iterator position of specified length if possible and advances iterator o...
std::string_view::iterator m_it
void ReplaceAll(std::string &in_out, std::string_view search, std::string_view substitute)
Replace every non-overlapping occurrence of search with substitute, treating both literally; the repl...