summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib
diff options
context:
space:
mode:
author AJR <ajrhacker@users.noreply.github.com>2020-12-21 23:07:45 -0500
committer AJR <ajrhacker@users.noreply.github.com>2020-12-21 23:07:50 -0500
commit2194589656582c0d78c1da1a2c5322053f56e573 (patch)
tree1110b35f1e83e4c911e29a6339cf8d77b1f9bc9b /src/lib
parent0a5d207e667075f4ea0618339d971c0f977d9ce1 (diff)
util/png: Update add_text to take std::string_view for arguments
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/util/png.cpp20
-rw-r--r--src/lib/util/png.h3
2 files changed, 11 insertions, 12 deletions
diff --git a/src/lib/util/png.cpp b/src/lib/util/png.cpp
index 50aeb28c5fe..9a9edecd8df 100644
--- a/src/lib/util/png.cpp
+++ b/src/lib/util/png.cpp
@@ -828,38 +828,36 @@ png_error png_info::expand_buffer_8bit()
add_text - add a text entry to the png_info
-------------------------------------------------*/
-png_error png_info::add_text(const char *keyword, const char *text)
+png_error png_info::add_text(std::string_view keyword, std::string_view text)
{
// apply rules to keyword
char32_t prev(0);
std::size_t cnt(0);
- char const *const kwend(keyword + std::strlen(keyword));
- for (char const *ptr = keyword; kwend > ptr; )
+ for (std::string_view kw = keyword; !kw.empty(); )
{
char32_t ch;
- int const len(uchar_from_utf8(&ch, ptr, kwend - ptr));
- if ((0 >= len) || (32 > ch) || (255 < ch) || ((126 < ch) && (161 > ch)) || (((32 == prev) || (keyword == ptr)) && (32 == ch)))
+ int const len(uchar_from_utf8(&ch, kw));
+ if ((0 >= len) || (32 > ch) || (255 < ch) || ((126 < ch) && (161 > ch)) || (((32 == prev) || (0 == cnt)) && (32 == ch)))
return png_error::UNSUPPORTED_FORMAT;
prev = ch;
++cnt;
- ptr += len;
+ kw.remove_prefix(len);
}
if ((32 == prev) || (1 > cnt) || (79 < cnt))
return png_error::UNSUPPORTED_FORMAT;
// apply rules to text
- char const *const textend(text + std::strlen(text));
- for (char const *ptr = text; textend > ptr; )
+ for (std::string_view tx = text; !tx.empty(); )
{
char32_t ch;
- int const len(uchar_from_utf8(&ch, ptr, textend - ptr));
+ int const len(uchar_from_utf8(&ch, tx));
if ((0 >= len) || (1 > ch) || (255 < ch))
return png_error::UNSUPPORTED_FORMAT;
- ptr += len;
+ tx.remove_prefix(len);
}
// allocate a new text element
- try { textlist.emplace_back(std::piecewise_construct, std::forward_as_tuple(keyword, kwend), std::forward_as_tuple(text, textend)); }
+ try { textlist.emplace_back(std::piecewise_construct, std::forward_as_tuple(keyword), std::forward_as_tuple(text)); }
catch (std::bad_alloc const &) { return png_error::OUT_OF_MEMORY; }
return png_error::NONE;
}
diff --git a/src/lib/util/png.h b/src/lib/util/png.h
index 784c92646e6..cc7a7204c16 100644
--- a/src/lib/util/png.h
+++ b/src/lib/util/png.h
@@ -21,6 +21,7 @@
#include <list>
#include <memory>
#include <string>
+#include <string_view>
#include <utility>
@@ -63,7 +64,7 @@ public:
png_error copy_to_bitmap(bitmap_argb32 &bitmap, bool &hasalpha);
png_error expand_buffer_8bit();
- png_error add_text(char const *keyword, char const *text);
+ png_error add_text(std::string_view keyword, std::string_view text);
void free_data();
void reset() { free_data(); operator=(png_info()); }