@@ -311,7 +311,7 @@ void PngChunk::parseChunkContent(Image* pImage, const byte* key, size_t keySize,
311311
312312} // PngChunk::parseChunkContent
313313
314- std::string PngChunk::makeMetadataChunk (const std::string& metadata, MetadataId type) {
314+ std::string PngChunk::makeMetadataChunk (std::string_view metadata, MetadataId type) {
315315 std::string rawProfile;
316316
317317 switch (type) {
@@ -362,7 +362,7 @@ void PngChunk::zlibUncompress(const byte* compressedText, unsigned int compresse
362362 }
363363} // PngChunk::zlibUncompress
364364
365- std::string PngChunk::zlibCompress (const std::string& text) {
365+ std::string PngChunk::zlibCompress (std::string_view text) {
366366 auto compressedLen = static_cast <uLongf>(text.size () * 2 ); // just a starting point
367367 int zlibResult = Z_BUF_ERROR;
368368
@@ -396,7 +396,7 @@ std::string PngChunk::zlibCompress(const std::string& text) {
396396
397397} // PngChunk::zlibCompress
398398
399- std::string PngChunk::makeAsciiTxtChunk (const std::string& keyword, const std::string& text, bool compress) {
399+ std::string PngChunk::makeAsciiTxtChunk (std::string_view keyword, std::string_view text, bool compress) {
400400 // Chunk structure: length (4 bytes) + chunk type + chunk data + CRC (4 bytes)
401401 // Length is the size of the chunk data
402402 // CRC is calculated on chunk type + chunk data
@@ -408,7 +408,7 @@ std::string PngChunk::makeAsciiTxtChunk(const std::string& keyword, const std::s
408408 // Chunk data format : keyword + 0x00 + text
409409
410410 // Build chunk data, determine chunk type
411- std::string chunkData = keyword + ' \0 ' ;
411+ auto chunkData = std::string ( keyword) + ' \0 ' ;
412412 std::string chunkType;
413413 if (compress) {
414414 chunkData += ' \0 ' + zlibCompress (text);
@@ -432,7 +432,7 @@ std::string PngChunk::makeAsciiTxtChunk(const std::string& keyword, const std::s
432432
433433} // PngChunk::makeAsciiTxtChunk
434434
435- std::string PngChunk::makeUtf8TxtChunk (const std::string& keyword, const std::string& text, bool compress) {
435+ std::string PngChunk::makeUtf8TxtChunk (std::string_view keyword, std::string_view text, bool compress) {
436436 // Chunk structure: length (4 bytes) + chunk type + chunk data + CRC (4 bytes)
437437 // Length is the size of the chunk data
438438 // CRC is calculated on chunk type + chunk data
@@ -442,13 +442,13 @@ std::string PngChunk::makeUtf8TxtChunk(const std::string& keyword, const std::st
442442 // + translated keyword (null) + 0x00 + text (compressed or not)
443443
444444 // Build chunk data, determine chunk type
445- std::string chunkData = keyword;
445+ auto chunkData = std::string ( keyword) ;
446446 if (compress) {
447447 static const char flags[] = {0x00 , 0x01 , 0x00 , 0x00 , 0x00 };
448448 chunkData += std::string (flags, 5 ) + zlibCompress (text);
449449 } else {
450450 static const char flags[] = {0x00 , 0x00 , 0x00 , 0x00 , 0x00 };
451- chunkData += std::string (flags, 5 ) + text;
451+ chunkData += std::string (flags, 5 ) + text. data () ;
452452 }
453453 // Determine length of the chunk data
454454 byte length[4 ];
@@ -574,7 +574,7 @@ DataBuf PngChunk::readRawProfile(const DataBuf& text, bool iTXt) {
574574
575575} // PngChunk::readRawProfile
576576
577- std::string PngChunk::writeRawProfile (const std::string& profileData, const char * profileType) {
577+ std::string PngChunk::writeRawProfile (std::string_view profileData, const char * profileType) {
578578 static const byte hex[16 ] = {' 0' , ' 1' , ' 2' , ' 3' , ' 4' , ' 5' , ' 6' , ' 7' , ' 8' , ' 9' , ' a' , ' b' , ' c' , ' d' , ' e' , ' f' };
579579
580580 auto ss = stringFormat (" \n {}\n {:08}" , profileType, profileData.size ());
0 commit comments