Modify rule S6185: improve description
This commit is contained in:
parent
c4e4c11313
commit
c6acefb37f
@ -25,5 +25,5 @@
|
||||
"defaultQualityProfiles": [
|
||||
"Sonar way"
|
||||
],
|
||||
"quickfix": "unknown"
|
||||
"quickfix": "targeted"
|
||||
}
|
||||
|
@ -1,7 +1,7 @@
|
||||
``++std::format++``, introduced by {cpp}20, enables straightforward string construction out of values of various types.
|
||||
|
||||
|
||||
Before {cpp}20 one popular way to obtain the same result was the conversion of the values with ``++std::to_string++`` and piecewise string concatenation.
|
||||
Before {cpp}20, one popular way to obtain the same result was the conversion of the values with ``++std::to_string++`` and piecewise string concatenation.
|
||||
|
||||
|
||||
``++std::format++`` is strictly superior. It is more efficient because it constructs the string in-place instead of copying substrings one by one. It is also often shorter and easier to read because the format pattern is presented in a single piece and not scattered across the concatenation expression.
|
||||
@ -15,7 +15,7 @@ This rule reports string concatenation cases that can be replaced by ``++std::fo
|
||||
[source,cpp]
|
||||
----
|
||||
std::string greeting(int n) {
|
||||
return "Hello, player " + std::to_string(n) + ".";
|
||||
return "Hello, player " + std::to_string(n) + "."; // Noncompliant
|
||||
}
|
||||
----
|
||||
|
||||
@ -25,7 +25,7 @@ std::string greeting(int n) {
|
||||
[source,cpp]
|
||||
----
|
||||
std::string greeting(int n) {
|
||||
return std::format("Hello, player {}.", n);
|
||||
return std::format("Hello, player {}.", n); // Compliant
|
||||
}
|
||||
----
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user