Skip to content

Commit 22fb744

Browse files
committed
Some C++20 format functions.
1 parent cd43b5f commit 22fb744

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

Source/FreeImage/Plugin.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
#else
3535
#include <ctype.h>
3636
#endif // _WIN32
37+
#include <format>
3738

3839
#include <filesystem>
3940

@@ -787,9 +788,7 @@ namespace {
787788

788789
std::filesystem::path MakeRandomSuffix()
789790
{
790-
std::stringstream strs{};
791-
strs << ".fitmp" << std::hex << static_cast<uint32_t>(std::rand());
792-
return strs.str();
791+
return std::format(".fitmp{:x}", static_cast<uint32_t>(std::rand()));
793792
}
794793

795794

Source/Metadata/FIRational.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
// Use at your own risk!
2020
// ==========================================================
2121

22+
#include <format>
2223
#include "FreeImage.h"
2324
#include "Utilities.h"
2425
#include "FIRational.h"
@@ -164,11 +165,11 @@ FIBOOL FIRational::isInteger() {
164165

165166
/// Convert as "numerator/denominator"
166167
std::string FIRational::toString() {
167-
std::ostringstream s;
168+
std::string s;
168169
if (isInteger()) {
169-
s << intValue();
170+
s = std::to_string(intValue());
170171
} else {
171-
s << _numerator << "/" << _denominator;
172+
s = std::format("{}/{}", _numerator, _denominator);
172173
}
173-
return s.str();
174+
return s;
174175
}

0 commit comments

Comments
 (0)