Skip to content

Commit 3b1a3ac

Browse files
committed
string_view conversions
Signed-off-by: Rosen Penev <[email protected]>
1 parent 1cddf5b commit 3b1a3ac

15 files changed

+40
-40
lines changed

src/canonmn_int.cpp

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

41-
static float string_to_float(const std::string& str);
41+
static float string_to_float(std::string_view str);
4242

4343
//! ModelId, tag 0x0010
4444
constexpr TagDetails canonModelId[] = {
@@ -2877,7 +2877,7 @@ std::ostream& printCsLensFFFF(std::ostream& os, const Value& value, const ExifDa
28772877
* @param str string to convert
28782878
* @return float value of string
28792879
*/
2880-
float string_to_float(std::string const& str) {
2880+
float string_to_float(std::string_view str) {
28812881
float val{};
28822882
std::stringstream ss;
28832883
std::locale c_locale("C");

src/futils.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,8 @@ size_t base64decode(const char* in, char* out, size_t out_size) {
207207

208208
Protocol fileProtocol(const std::string& path) {
209209
Protocol result = pFile;
210-
const struct {
211-
std::string name;
210+
constexpr struct {
211+
std::string_view name;
212212
Protocol prot;
213213
bool isUrl; // path.size() > name.size()
214214
} prots[] = {

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/olympusmn_int.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,7 +1355,7 @@ std::ostream& OlympusMakerNote::print0x0201(std::ostream& os, const Value& value
13551355

13561356
// 6 numbers: 0. Make, 1. Unknown, 2. Model, 3. Sub-model, 4-5. Unknown.
13571357
// Only the Make, Model and Sub-model are used to determine the lens model
1358-
static const struct {
1358+
static constexpr struct {
13591359
byte val[3];
13601360
const char* label;
13611361
} lensTypes[] = {
@@ -1509,7 +1509,7 @@ std::ostream& OlympusMakerNote::print0x0209(std::ostream& os, const Value& value
15091509
std::ostream& OlympusMakerNote::printEq0x0301(std::ostream& os, const Value& value, const ExifData*) {
15101510
// 6 numbers: 0. Make, 1. Unknown, 2. Model, 3. Sub-model, 4-5. Unknown.
15111511
// Only the Make and Model are used to determine the extender model
1512-
static const struct {
1512+
static constexpr struct {
15131513
byte val[2];
15141514
const char* label;
15151515
} extenderModels[] = {

src/pngchunk_int.cpp

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

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
@@ -45,7 +45,7 @@ constexpr SectionInfo sectionInfo[] = {
4545
} // namespace Exiv2
4646

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

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
/*!

0 commit comments

Comments
 (0)