Skip to content

Commit 0b16a31

Browse files
committed
use std::format for version
1 parent 4957e05 commit 0b16a31

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

src/version_weaver.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33
#include <algorithm>
44
#include <cctype>
55
#include <charconv>
6+
#include <format>
67
#include <regex>
7-
#include <sstream>
8+
89
namespace version_weaver {
910
bool validate(std::string_view version) { return parse(version).has_value(); }
1011

@@ -116,17 +117,12 @@ std::optional<std::string> incrementVersion(std::string_view version) {
116117
// If there is a pre-release part, return the version in pre-release format
117118
// (for example “1.2.3-beta.0”)
118119
if (!preRelease.empty()) {
119-
std::ostringstream oss;
120-
oss << major << "." << minor << "." << patch << "-"
121-
<< std::string(preRelease) << ".0";
122-
return oss.str();
120+
return std::format("{}.{}.{}-{}.0", major, minor, patch, std::string(preRelease));
123121
}
124122

125123
// if there is no pre-release, increment patch and return the result.
126124
patch++;
127-
std::ostringstream oss;
128-
oss << major << "." << minor << "." << patch;
129-
return oss.str();
125+
return std::format("{}.{}.{}", major, minor, patch);
130126
}
131127

132128
std::optional<std::string> decrementVersion(const std::string_view version) {
@@ -222,8 +218,6 @@ std::string computeTildeUpperBound(const std::string_view &version) {
222218
if (!coercedOpt) return "";
223219

224220
std::vector<std::string> parts;
225-
std::istringstream iss(*coercedOpt);
226-
std::string token;
227221

228222
size_t pos = 0;
229223
size_t dot_pos;

0 commit comments

Comments
 (0)