summaryrefslogtreecommitdiffstats
path: root/src/lib/util/corefile.cpp
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2021-01-01 12:18:29 -0500
committer AJR <ajrhacker@users.noreply.github.com>2021-01-01 12:22:17 -0500
commitaa29519528cb3dbdbfac56819bea670ed8c56c5d (patch)
treebdaff6e127ed377a4fc84d3e8ee1b7a99f503d0b /src/lib/util/corefile.cpp
parent21fd9835451a5a7d7655964bfb7adb1ba9b8540f (diff)
Further additions of std::string_view
- corefile.cpp, fileio.cpp: Change puts to take a std::string_view parameter - rendlay.cpp: Use std::string_view instead of bare pointers in various functions - vecstream.h: Add std::string_view conversion operator to obtain output buffer without needing to make it a C string with explicit null termination - xmlfile.cpp: Add get_attribute_string_ptr method that distinguishes between empty strings and absent attributes without falling back to C strings
Diffstat (limited to 'src/lib/util/corefile.cpp')
-rw-r--r--src/lib/util/corefile.cpp16
1 files changed, 7 insertions, 9 deletions
diff --git a/src/lib/util/corefile.cpp b/src/lib/util/corefile.cpp
index 2de0d7c378d..fe0747c66a8 100644
--- a/src/lib/util/corefile.cpp
+++ b/src/lib/util/corefile.cpp
@@ -158,7 +158,7 @@ public:
virtual const void *buffer() override { return m_file.buffer(); }
virtual std::uint32_t write(const void *buffer, std::uint32_t length) override { return m_file.write(buffer, length); }
- virtual int puts(const char *s) override { return m_file.puts(s); }
+ virtual int puts(std::string_view s) override { return m_file.puts(s); }
virtual int vprintf(util::format_argument_pack<std::ostream> const &args) override { return m_file.vprintf(args); }
virtual osd_file::error truncate(std::uint64_t offset) override { return m_file.truncate(offset); }
@@ -185,7 +185,7 @@ public:
virtual int getc() override;
virtual int ungetc(int c) override;
virtual char *gets(char *s, int n) override;
- virtual int puts(char const *s) override;
+ virtual int puts(std::string_view s) override;
virtual int vprintf(util::format_argument_pack<std::ostream> const &args) override;
protected:
@@ -542,7 +542,7 @@ char *core_text_file::gets(char *s, int n)
puts - write a line to a text file
-------------------------------------------------*/
-int core_text_file::puts(char const *s)
+int core_text_file::puts(std::string_view s)
{
char convbuf[1024];
char *pconvbuf = convbuf;
@@ -557,9 +557,9 @@ int core_text_file::puts(char const *s)
}
// convert '\n' to platform dependant line endings
- while (*s != '\0')
+ for (char ch : s)
{
- if (*s == '\n')
+ if (ch == '\n')
{
if (CRLF == 1) // CR only
*pconvbuf++ = 13;
@@ -572,8 +572,7 @@ int core_text_file::puts(char const *s)
}
}
else
- *pconvbuf++ = *s;
- s++;
+ *pconvbuf++ = ch;
// if we overflow, break into chunks
if (pconvbuf >= convbuf + ARRAY_LENGTH(convbuf) - 10)
@@ -601,8 +600,7 @@ int core_text_file::vprintf(util::format_argument_pack<std::ostream> const &args
m_printf_buffer.reserve(1024);
m_printf_buffer.seekp(0, ovectorstream::beg);
util::stream_format<std::ostream, std::ostream>(m_printf_buffer, args);
- m_printf_buffer.put('\0');
- return puts(&m_printf_buffer.vec()[0]);
+ return puts(std::string_view(m_printf_buffer));
}