Skip to content

Commit 5ebe59e

Browse files
committed
string_view conversions
1 parent 0d2d731 commit 5ebe59e

13 files changed

+34
-34
lines changed

src/canonmn_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ static std::ostream& printCsLensTypeByMetadata(std::ostream& os, const Value& va
3737
//! Special treatment pretty-print function for non-unique lens ids.
3838
static std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifData* metadata);
3939

40-
static float string_to_float(const std::string& str);
40+
static float string_to_float(std::string_view str);
4141

4242
//! ModelId, tag 0x0010
4343
constexpr TagDetails canonModelId[] = {
@@ -2902,7 +2902,7 @@ std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifDa
29022902
* @param str string to convert
29032903
* @return float value of string
29042904
*/
2905-
float string_to_float(std::string const& str) {
2905+
float string_to_float(std::string_view str) {
29062906
float val{};
29072907
std::stringstream ss;
29082908
std::locale c_locale("C");

src/makernote_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ const TiffMnRegistry TiffMnCreator::registry_[] = {
129129
{"-", IfdId::casio2Id, nullptr, newCasio2Mn2},
130130
};
131131

132-
bool TiffMnRegistry::operator==(const std::string& key) const {
132+
bool TiffMnRegistry::operator==(std::string_view key) const {
133133
if (!key.empty() && key.front() == '-')
134134
return false;
135135
return key.starts_with(make_);
@@ -139,7 +139,7 @@ bool TiffMnRegistry::operator==(IfdId key) const {
139139
return mnGroup_ == key;
140140
}
141141

142-
std::unique_ptr<TiffComponent> TiffMnCreator::create(uint16_t tag, IfdId group, const std::string& make,
142+
std::unique_ptr<TiffComponent> TiffMnCreator::create(uint16_t tag, IfdId group, std::string_view make,
143143
const byte* pData, size_t size, ByteOrder byteOrder) {
144144
if (auto tmr = Exiv2::find(registry_, make))
145145
return tmr->newMnFct_(tag, group, tmr->mnGroup_, pData, size, byteOrder);

src/makernote_int.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ struct TiffMnRegistry {
4343
same size. E.g., registry = "OLYMPUS",
4444
key = "OLYMPUS OPTICAL CO.,LTD" (found in the image) match.
4545
*/
46-
bool operator==(const std::string& key) const;
46+
bool operator==(std::string_view key) const;
4747

4848
//! Compare a TiffMnRegistry structure with a makernote group
4949
bool operator==(IfdId key) const;
@@ -71,7 +71,7 @@ class TiffMnCreator {
7171
is used to indicate this transfer here in order to reduce
7272
file dependencies.
7373
*/
74-
static std::unique_ptr<TiffComponent> create(uint16_t tag, IfdId group, const std::string& make, const byte* pData,
74+
static std::unique_ptr<TiffComponent> create(uint16_t tag, IfdId group, std::string_view make, const byte* pData,
7575
size_t size, ByteOrder byteOrder);
7676
/*!
7777
@brief Create the Makernote for a given group. This method is used

src/pngchunk_int.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -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;

src/pngchunk_int.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class PngChunk {
7070
@param metadata metadata buffer.
7171
@param type metadata type.
7272
*/
73-
static std::string makeMetadataChunk(const std::string& metadata, MetadataId type);
73+
static std::string makeMetadataChunk(std::string_view metadata, MetadataId type);
7474

7575
private:
7676
/*!
@@ -100,7 +100,7 @@ class PngChunk {
100100
101101
@return String containing the PNG chunk
102102
*/
103-
static std::string makeAsciiTxtChunk(const std::string& keyword, const std::string& text, bool compress);
103+
static std::string makeAsciiTxtChunk(std::string_view keyword, std::string_view text, bool compress);
104104

105105
/*!
106106
@brief Return a compressed or uncompressed (iTXt) PNG international text chunk
@@ -110,7 +110,7 @@ class PngChunk {
110110
@param text Text to be recorded in the PNG chunk.
111111
@param compress Flag indicating whether to compress the PNG chunk data.
112112
*/
113-
static std::string makeUtf8TxtChunk(const std::string& keyword, const std::string& text, bool compress);
113+
static std::string makeUtf8TxtChunk(std::string_view keyword, std::string_view text, bool compress);
114114

115115
/*!
116116
@brief Wrapper around zlib to uncompress a PNG chunk content.
@@ -120,7 +120,7 @@ class PngChunk {
120120
/*!
121121
@brief Wrapper around zlib to compress a PNG chunk content.
122122
*/
123-
static std::string zlibCompress(const std::string& text);
123+
static std::string zlibCompress(std::string_view text);
124124

125125
/*!
126126
@brief Decode from ImageMagick raw text profile which host encoded Exif/Iptc/Xmp metadata byte array.
@@ -131,7 +131,7 @@ class PngChunk {
131131
@brief Encode to ImageMagick raw text profile, which host encoded
132132
Exif/IPTC/XMP metadata byte arrays.
133133
*/
134-
static std::string writeRawProfile(const std::string& profileData, const char* profileType);
134+
static std::string writeRawProfile(std::string_view profileData, const char* profileType);
135135

136136
friend class Exiv2::PngImage;
137137

src/tags.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ constexpr SectionInfo sectionInfo[] = {
4444
} // namespace Exiv2
4545

4646
namespace Exiv2::Internal {
47-
bool TagVocabulary::operator==(const std::string& key) const {
47+
bool TagVocabulary::operator==(std::string_view key) const {
4848
return key.ends_with(voc_);
4949
}
5050

src/tags_int.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
// local declarations
2929
namespace {
3030
// Print version string from an intermediate string
31-
std::ostream& printVersion(std::ostream& os, const std::string& str) {
31+
std::ostream& printVersion(std::ostream& os, std::string_view str) {
3232
if (str.size() != 4) {
3333
return os << "(" << str << ")";
3434
}

src/tags_int.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ struct StringTagDetails {
4545
const char* label_; //!< Translation of the tag value
4646

4747
//! Comparison operator for use with the find template
48-
bool operator==(const std::string& key) const {
49-
return (key == val_);
48+
bool operator==(std::string_view key) const {
49+
return key == val_;
5050
}
5151
}; // struct TagDetails
5252

@@ -80,7 +80,7 @@ struct TagVocabulary {
8080
"http://ns.useplus.org/ldf/vocab/PR-NON" and return true if the vocabulary
8181
string matches the end of the key.
8282
*/
83-
bool operator==(const std::string& key) const;
83+
bool operator==(std::string_view key) const;
8484
}; // struct TagDetails
8585

8686
/*!

src/tiffcomposite_int.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ struct TiffMappingInfo {
366366

367367
//! Search key for TIFF mapping structures.
368368
struct TiffMappingInfo::Key {
369-
std::string m_; //!< Camera make
369+
std::string_view m_; //!< Camera make
370370
uint32_t e_; //!< Extended tag
371371
IfdId g_; //!< %Group
372372
};

src/tifffwd_int.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,11 @@ using EncoderFct = void (TiffEncoder::*)(TiffEntryBase*, const Exifdatum*);
6161
/*!
6262
@brief Type for a function pointer for a function to decode a TIFF component.
6363
*/
64-
using FindDecoderFct = DecoderFct (*)(const std::string& make, uint32_t extendedTag, IfdId group);
64+
using FindDecoderFct = DecoderFct (*)(std::string_view make, uint32_t extendedTag, IfdId group);
6565
/*!
6666
@brief Type for a function pointer for a function to encode a TIFF component.
6767
*/
68-
using FindEncoderFct = EncoderFct (*)(const std::string& make, uint32_t extendedTag, IfdId group);
68+
using FindEncoderFct = EncoderFct (*)(std::string_view make, uint32_t extendedTag, IfdId group);
6969
/*!
7070
@brief Type for a function pointer for a function to create a TIFF component.
7171
Use TiffComponent::UniquePtr, it is not used in this declaration only

0 commit comments

Comments
 (0)