debug/textbuf.cpp: Another obvious use for std::string_view

This commit is contained in:
AJR 2020-12-08 23:19:03 -05:00
parent c22cb17f32
commit 09d755e44e
3 changed files with 6 additions and 11 deletions

View File

@ -158,9 +158,9 @@ void debugger_console::execute_condump(int ref, const std::vector<std::string>&
return;
}
for (auto line_info : text_buffer_lines(*m_console_textbuf))
for (std::string_view line_info : text_buffer_lines(*m_console_textbuf))
{
fwrite(line_info.text, sizeof(char), line_info.length, f);
fwrite(line_info.data(), sizeof(char), line_info.length(), f);
fputc('\n', f);
}

View File

@ -305,7 +305,7 @@ const char *text_buffer_get_seqnum_line(text_buffer const &text, u32 seqnum)
Gets the line that the iterator currently points to.
-----------------------------------------------------------------------*/
text_buffer_line text_buffer_lines::text_buffer_line_iterator::operator*() const
std::string_view text_buffer_lines::text_buffer_line_iterator::operator*() const
{
char const *const line = &m_buffer.buffer[m_buffer.lineoffs[m_lineptr]];
@ -321,7 +321,7 @@ text_buffer_line text_buffer_lines::text_buffer_line_iterator::operator*() const
if (difference < 0)
difference += m_buffer.bufsize;
return text_buffer_line{ line, size_t(difference) };
return std::string_view{ line, size_t(difference) };
}
/*---------------------------------------------------------------------

View File

@ -12,6 +12,7 @@
#define MAME_EMU_DEBUG_TEXTBUF_H
#include <memory>
#include <string_view>
#include "emucore.h"
@ -22,12 +23,6 @@
struct text_buffer;
struct text_buffer_line
{
const char *text;
size_t length;
};
// helper class for iterating over the lines of a text_buffer
class text_buffer_lines
{
@ -49,7 +44,7 @@ public:
}
// technically this isn't a valid forward iterator, because operator * doesn't return a reference
text_buffer_line operator*() const;
std::string_view operator*() const;
text_buffer_line_iterator &operator++();
bool operator!=(const text_buffer_line_iterator& rhs)