Modify rule S6185: improve description

This commit is contained in:
abbas-sabra-sonarsource 2022-12-06 23:10:58 +01:00 committed by GitHub
parent c4e4c11313
commit c6acefb37f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 4 deletions

View File

@ -25,5 +25,5 @@
"defaultQualityProfiles": [
"Sonar way"
],
"quickfix": "unknown"
"quickfix": "targeted"
}

View File

@ -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
}
----