Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create rule S7118 String methods should be used to query content instead of C apis CPP-5790 #4381

Merged
merged 6 commits into from
Nov 7, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions rules/S7118/cfamily/rule.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,16 @@ std::string beginning{string.c_str()};
// ...
----

=== Going the extra mile

Direct replacement of one C function with the corresponding string method may not lead to the best code overall. When replacing a C function call, you should consider what overall functionality this call is part of and whether your {cpp} version allows to implement that functionality more easily and effectively.

For example using ranges (`std::ranges::views::split`, `std::ranges::views::chunk`), using algorithms, using `std::stringstream` or `std::spanstream`, using `std::string_view`.

tomasz-kaminski-sonarsource marked this conversation as resolved.
Show resolved Hide resolved
== Resources

=== Documentation

* {cpp} reference - https://en.cppreference.com/w/cpp/string/basic_string[Native functions for std::string]

* {cpp} reference - https://en.cppreference.com/w/cpp/ranges#Range_adaptors[ranges documentation]
Loading