Skip to content

Commit

Permalink
Deploying to gh-pages from @ b46c381 🚀
Browse files Browse the repository at this point in the history
  • Loading branch information
marco-antognini-sonarsource committed Mar 27, 2024
1 parent 7a78118 commit ac570a3
Show file tree
Hide file tree
Showing 17 changed files with 575 additions and 117 deletions.
46 changes: 45 additions & 1 deletion rules/S6185/cfamily-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<p><code>std::format</code> 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.</p>
</div>
<div class="paragraph">
<p>This rule reports string concatenation cases that can be replaced by <code>std::format</code> and gain in speed and readability.</p>
<p>This rule reports string concatenation cases that can be replaced by <code>std::format</code> to improve performance and readability.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
Expand All @@ -40,4 +40,48 @@ <h3 id="_compliant_solution">Compliant solution</h3>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; reference - <a href="https://en.cppreference.com/w/cpp/utility/format/format"><code>std::format</code></a></p>
</li>
<li>
<p>C&#43;&#43; reference - <a href="https://en.cppreference.com/w/cpp/string/basic_string/to_string"><code>std::to_string</code></a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_articles_blog_posts">Articles &amp; blog posts</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; Stories - <a href="https://www.cppstories.com/2022/custom-stdformat-cpp20/">Formatting Custom types with std::format from C&#43;&#43;20</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_related_rules">Related rules</h3>
<div class="ulist">
<ul>
<li>
<p><a data-rspec-id="S6484" class="rspec-auto-link">S6484</a> - Concatenated "std::format" outputs should be replaced by a single invocation</p>
</li>
<li>
<p><a data-rspec-id="S6494" class="rspec-auto-link">S6494</a> - C&#43;&#43; formatting functions should be used instead of C printf-like functions</p>
</li>
<li>
<p><a data-rspec-id="S6495" class="rspec-auto-link">S6495</a> - "std::format" should be used instead of standard output manipulators</p>
</li>
</ul>
</div>
</div>
</div>
</div>
46 changes: 45 additions & 1 deletion rules/S6185/default-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<p><code>std::format</code> 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.</p>
</div>
<div class="paragraph">
<p>This rule reports string concatenation cases that can be replaced by <code>std::format</code> and gain in speed and readability.</p>
<p>This rule reports string concatenation cases that can be replaced by <code>std::format</code> to improve performance and readability.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
Expand All @@ -40,4 +40,48 @@ <h3 id="_compliant_solution">Compliant solution</h3>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; reference - <a href="https://en.cppreference.com/w/cpp/utility/format/format"><code>std::format</code></a></p>
</li>
<li>
<p>C&#43;&#43; reference - <a href="https://en.cppreference.com/w/cpp/string/basic_string/to_string"><code>std::to_string</code></a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_articles_blog_posts">Articles &amp; blog posts</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; Stories - <a href="https://www.cppstories.com/2022/custom-stdformat-cpp20/">Formatting Custom types with std::format from C&#43;&#43;20</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_related_rules">Related rules</h3>
<div class="ulist">
<ul>
<li>
<p><a data-rspec-id="S6484" class="rspec-auto-link">S6484</a> - Concatenated "std::format" outputs should be replaced by a single invocation</p>
</li>
<li>
<p><a data-rspec-id="S6494" class="rspec-auto-link">S6494</a> - C&#43;&#43; formatting functions should be used instead of C printf-like functions</p>
</li>
<li>
<p><a data-rspec-id="S6495" class="rspec-auto-link">S6495</a> - "std::format" should be used instead of standard output manipulators</p>
</li>
</ul>
</div>
</div>
</div>
</div>
60 changes: 50 additions & 10 deletions rules/S6484/cfamily-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ <h2 id="_description">Description</h2>
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p><code>std::format</code> accepts a format string composed of ordinary text and replacement fields (surrounded with <code>{}</code>) that are replaced with a textual representation of the next <code>std::format</code> arguments.
<p><code>std::format</code> accepts a format string composed of ordinary text and replacement fields (surrounded with <code>{}</code>) that are replaced with a textual representation of the remaining <code>std::format</code> arguments.
This allows generating a complex string with a single invocation of <code>std::format</code>.</p>
</div>
<div class="paragraph">
<p>Since calls to <code>std::format</code> produce string objects, it is possible to concatenate them with other string objects or string literals.
However, compared to a single <code>std::format</code> invocation with an adjusted format string, this concatenation is inefficient and less readable.</p>
</div>
<div class="paragraph">
<p>This rule raises an issue when a concatenation an <code>std::format</code> invocation can be replaced with a simple <code>std::format</code> invocation.</p>
<p>This rule raises an issue when the concatenation performed on the result of <code>std::format</code> can be replaced with a single <code>std::format</code> invocation.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
Expand All @@ -25,6 +25,17 @@ <h3 id="_noncompliant_code_example">Noncompliant code example</h3>
<pre class="highlight"><code class="language-cpp" data-lang="cpp">void formatExamples(std::string str, char const* cstr, int i) {
std::string s1 = "You have been greeted " + std::format("{}", i) + " times."; // Noncompliant
std::string s2 = "Hello " + std::format("{:*^20}", str) + "! " + std::format("{:-&gt;15}", cstr) + '.'; // Noncompliant
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">void formatExamples(std::string str, char const* cstr, int i) {
std::string s1 = std::format("You have been greeted {} times.", i); // Compliant
std::string s2 = std::format("Hello {:*^20}! {:-&gt;15}.", str, cstr); // Compliant
}

std::string fullName(std::string name, std::string secondName, std::string surname, std::size_t number) {
Expand All @@ -40,16 +51,45 @@ <h3 id="_noncompliant_code_example">Noncompliant code example</h3>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">void formatExamples(std::string str, char const* cstr, int i) {
std::string s1 = std::format("You have been greeted {} times.", i); // Compliant
std::string s2 = std::format("Hello {:*^20}! {:-&gt;15}.", str, cstr); // Compliant
std::string s3 = std::format("Welcome {:*^20}! {:-&gt;15}.", str, cstr); // Compliant
}</code></pre>
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; reference - <a href="https://en.cppreference.com/w/cpp/utility/format/format"><code>std::format</code></a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_articles_blog_posts">Articles &amp; blog posts</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; Stories - <a href="https://www.cppstories.com/2022/custom-stdformat-cpp20/">Formatting Custom types with std::format from C&#43;&#43;20</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_related_rules">Related rules</h3>
<div class="ulist">
<ul>
<li>
<p><a data-rspec-id="S6185" class="rspec-auto-link">S6185</a> - "std::format" should be used instead of string concatenation and "std::to_string"</p>
</li>
<li>
<p><a data-rspec-id="S6494" class="rspec-auto-link">S6494</a> - C&#43;&#43; formatting functions should be used instead of C printf-like functions</p>
</li>
<li>
<p><a data-rspec-id="S6495" class="rspec-auto-link">S6495</a> - "std::format" should be used instead of standard output manipulators</p>
</li>
</ul>
</div>
</div>
</div>
Expand Down
60 changes: 50 additions & 10 deletions rules/S6484/default-description.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ <h2 id="_description">Description</h2>
<h2 id="_why_is_this_an_issue">Why is this an issue?</h2>
<div class="sectionbody">
<div class="paragraph">
<p><code>std::format</code> accepts a format string composed of ordinary text and replacement fields (surrounded with <code>{}</code>) that are replaced with a textual representation of the next <code>std::format</code> arguments.
<p><code>std::format</code> accepts a format string composed of ordinary text and replacement fields (surrounded with <code>{}</code>) that are replaced with a textual representation of the remaining <code>std::format</code> arguments.
This allows generating a complex string with a single invocation of <code>std::format</code>.</p>
</div>
<div class="paragraph">
<p>Since calls to <code>std::format</code> produce string objects, it is possible to concatenate them with other string objects or string literals.
However, compared to a single <code>std::format</code> invocation with an adjusted format string, this concatenation is inefficient and less readable.</p>
</div>
<div class="paragraph">
<p>This rule raises an issue when a concatenation an <code>std::format</code> invocation can be replaced with a simple <code>std::format</code> invocation.</p>
<p>This rule raises an issue when the concatenation performed on the result of <code>std::format</code> can be replaced with a single <code>std::format</code> invocation.</p>
</div>
<div class="sect2">
<h3 id="_noncompliant_code_example">Noncompliant code example</h3>
Expand All @@ -25,6 +25,17 @@ <h3 id="_noncompliant_code_example">Noncompliant code example</h3>
<pre class="highlight"><code class="language-cpp" data-lang="cpp">void formatExamples(std::string str, char const* cstr, int i) {
std::string s1 = "You have been greeted " + std::format("{}", i) + " times."; // Noncompliant
std::string s2 = "Hello " + std::format("{:*^20}", str) + "! " + std::format("{:-&gt;15}", cstr) + '.'; // Noncompliant
}</code></pre>
</div>
</div>
</div>
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">void formatExamples(std::string str, char const* cstr, int i) {
std::string s1 = std::format("You have been greeted {} times.", i); // Compliant
std::string s2 = std::format("Hello {:*^20}! {:-&gt;15}.", str, cstr); // Compliant
}

std::string fullName(std::string name, std::string secondName, std::string surname, std::size_t number) {
Expand All @@ -40,16 +51,45 @@ <h3 id="_noncompliant_code_example">Noncompliant code example</h3>
</div>
</div>
</div>
</div>
</div>
<div class="sect1">
<h2 id="_resources">Resources</h2>
<div class="sectionbody">
<div class="sect2">
<h3 id="_compliant_solution">Compliant solution</h3>
<div class="listingblock">
<div class="content">
<pre class="highlight"><code class="language-cpp" data-lang="cpp">void formatExamples(std::string str, char const* cstr, int i) {
std::string s1 = std::format("You have been greeted {} times.", i); // Compliant
std::string s2 = std::format("Hello {:*^20}! {:-&gt;15}.", str, cstr); // Compliant
std::string s3 = std::format("Welcome {:*^20}! {:-&gt;15}.", str, cstr); // Compliant
}</code></pre>
<h3 id="_documentation">Documentation</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; reference - <a href="https://en.cppreference.com/w/cpp/utility/format/format"><code>std::format</code></a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_articles_blog_posts">Articles &amp; blog posts</h3>
<div class="ulist">
<ul>
<li>
<p>C&#43;&#43; Stories - <a href="https://www.cppstories.com/2022/custom-stdformat-cpp20/">Formatting Custom types with std::format from C&#43;&#43;20</a></p>
</li>
</ul>
</div>
</div>
<div class="sect2">
<h3 id="_related_rules">Related rules</h3>
<div class="ulist">
<ul>
<li>
<p><a data-rspec-id="S6185" class="rspec-auto-link">S6185</a> - "std::format" should be used instead of string concatenation and "std::to_string"</p>
</li>
<li>
<p><a data-rspec-id="S6494" class="rspec-auto-link">S6494</a> - C&#43;&#43; formatting functions should be used instead of C printf-like functions</p>
</li>
<li>
<p><a data-rspec-id="S6495" class="rspec-auto-link">S6495</a> - "std::format" should be used instead of standard output manipulators</p>
</li>
</ul>
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit ac570a3

Please sign in to comment.