@@ -310,7 +310,7 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize,
310310
311311} // PngChunk::parseChunkContent
312312
313- std::string PngChunk::makeMetadataChunk (const std::string& metadata, MetadataId type) {
313+ std::string PngChunk::makeMetadataChunk (std::string_view metadata, MetadataId type) {
314314 std::string rawProfile;
315315
316316 switch (type) {
@@ -361,7 +361,7 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse
361361 }
362362} // PngChunk::zlibUncompress
363363
364- std::string PngChunk::zlibCompress (const std::string& text) {
364+ std::string PngChunk::zlibCompress (std::string_view text) {
365365 auto compressedLen = static_cast <uLongf>(text.size () * 2 ); // just a starting point
366366 int zlibResult = Z_BUF_ERROR;
367367
@@ -395,7 +395,7 @@ std::string PngChunk::zlibCompress(const std::string& text) {
395395
396396} // PngChunk::zlibCompress
397397
398- std::string PngChunk::makeAsciiTxtChunk (const std::string& keyword, const std::string& text, bool compress) {
398+ std::string PngChunk::makeAsciiTxtChunk (std::string_view keyword, std::string_view text, bool compress) {
399399 // Chunk structure: length (4 bytes) + chunk type + chunk data + CRC (4 bytes)
400400 // Length is the size of the chunk data
401401 // CRC is calculated on chunk type + chunk data
@@ -407,7 +407,7 @@ std::string PngChunk::makeAsciiTxtChunk(const std::string& keyword, const std::s
407407 // Chunk data format : keyword + 0x00 + text
408408
409409 // Build chunk data, determine chunk type
410- std::string chunkData = keyword + ' \0 ' ;
410+ auto chunkData = std::string ( keyword) + ' \0 ' ;
411411 std::string chunkType;
412412 if (compress) {
413413 chunkData += ' \0 ' + zlibCompress (text);
@@ -431,7 +431,7 @@ std::string PngChunk::makeAsciiTxtChunk(const std::string& keyword, const std::s
431431
432432} // PngChunk::makeAsciiTxtChunk
433433
434- std::string PngChunk::makeUtf8TxtChunk (const std::string& keyword, const std::string& text, bool compress) {
434+ std::string PngChunk::makeUtf8TxtChunk (std::string_view keyword, std::string_view text, bool compress) {
435435 // Chunk structure: length (4 bytes) + chunk type + chunk data + CRC (4 bytes)
436436 // Length is the size of the chunk data
437437 // CRC is calculated on chunk type + chunk data
@@ -441,13 +441,13 @@ std::string PngChunk::makeUtf8TxtChunk(const std::string& keyword, const std::st
441441 // + translated keyword (null) + 0x00 + text (compressed or not)
442442
443443 // Build chunk data, determine chunk type
444- std::string chunkData = keyword;
444+ auto chunkData = std::string ( keyword) ;
445445 if (compress) {
446446 static const char flags[] = {0x00 , 0x01 , 0x00 , 0x00 , 0x00 };
447447 chunkData += std::string (flags, 5 ) + zlibCompress (text);
448448 } else {
449449 static const char flags[] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
450- chunkData += std::string (flags, 5 ) + text;
450+ chunkData += std::string (flags, 5 ) + text. data () ;
451451 }
452452 // Determine length of the chunk data
453453 byte length[4 ];
@@ -573,7 +573,7 @@ DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) {
573573
574574} // PngChunk::readRawProfile
575575
576- std::string PngChunk::writeRawProfile (const std::string& profileData, const char * profileType) {
576+ std::string PngChunk::writeRawProfile (std::string_view profileData, const char * profileType) {
577577 static const byte hex[16 ] = {' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' a' , ' b' , ' c' , ' d' , ' e' , ' f' };
578578
579579 std::ostringstream oss;
0 commit comments