Skip to content

Commit

Permalink
Per #3087, drive down a few more SonarQube code smells.
Browse files Browse the repository at this point in the history
  • Loading branch information
JohnHalleyGotway committed Feb 19, 2025
1 parent 172f81e commit 8d92478
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 19 deletions.
20 changes: 11 additions & 9 deletions src/basic/vx_log/concat_string.cc
Original file line number Diff line number Diff line change
Expand Up @@ -527,8 +527,9 @@ void ConcatString::replace(const char * target, const char * replacement,

void ConcatString::set_upper()
{
for (auto c = s.begin(); s.end() != c; ++c)
*c = toupper(*c);
for_each(s.begin(), s.end(), [](char &c) {
c = (char) toupper(c);
});
}


Expand All @@ -537,8 +538,9 @@ void ConcatString::set_upper()

void ConcatString::set_lower()
{
for (auto c = s.begin(); s.end() != c; ++c)
*c = tolower(*c);
for_each(s.begin(), s.end(), [](char &c) {
c = (char) tolower(c);
});
}


Expand Down Expand Up @@ -758,8 +760,8 @@ ConcatString & operator<<(ConcatString & a, CSInlineCommand c)

switch ( c ) {

case cs_erase: a.erase(); break;
case cs_clear: a.clear(); break;
case CSInlineCommand::cs_erase: a.erase(); break;
case CSInlineCommand::cs_clear: a.clear(); break;

default:
mlog << Error << "\noperator<<(ostream &, CSInlineCommand) -> "
Expand Down Expand Up @@ -1226,7 +1228,7 @@ int ConcatString::find(int c) const
////////////////////////////////////////////////////////////////////////


int ConcatString::compare(size_t pos, size_t len, std::string str)
int ConcatString::compare(size_t pos, size_t len, std::string &str) const

{
return s.compare(pos, len, str);
Expand All @@ -1236,7 +1238,7 @@ int ConcatString::compare(size_t pos, size_t len, std::string str)
////////////////////////////////////////////////////////////////////////


int ConcatString::comparecase(size_t pos, size_t len, std::string str)
int ConcatString::comparecase(size_t pos, size_t len, std::string &str) const

{
std::string lower_s = s;
Expand All @@ -1250,7 +1252,7 @@ int ConcatString::comparecase(size_t pos, size_t len, std::string str)
////////////////////////////////////////////////////////////////////////


int ConcatString::comparecase(const char * str)
int ConcatString::comparecase(const char * str) const

{
std::string lower_s = s;
Expand Down
12 changes: 6 additions & 6 deletions src/basic/vx_log/concat_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ static const int concat_string_max_precision = 12;
////////////////////////////////////////////////////////////////////////


enum CSInlineCommand {
enum class CSInlineCommand {

cs_erase,
cs_clear
Expand Down Expand Up @@ -69,8 +69,8 @@ class ConcatString {
ConcatString();
~ConcatString();
ConcatString(const ConcatString &);
ConcatString(const std::string &);
ConcatString(const char *);
explicit ConcatString(const std::string &);
explicit ConcatString(const char *);
ConcatString & operator=(const ConcatString &);
ConcatString & operator=(const std::string &);
ConcatString & operator=(const char *);
Expand Down Expand Up @@ -169,9 +169,9 @@ class ConcatString {
void set_lower();

int find(int c) const;
int compare(size_t pos, size_t len, std::string str);
int comparecase(size_t pos, size_t len, std::string str);
int comparecase(const char *);
int compare(size_t pos, size_t len, std::string &str) const;
int comparecase(size_t pos, size_t len, std::string &str) const;
int comparecase(const char *) const;

};

Expand Down
8 changes: 4 additions & 4 deletions src/basic/vx_log/file_fxns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ConcatString replace_path(const ConcatString path) {
////////////////////////////////////////////////////////////////////////

ConcatString replace_path(const char * path) {
return replace_path((string)path);
return replace_path(ConcatString(path));
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -70,20 +70,20 @@ ConcatString replace_path(const char * path) {
////////////////////////////////////////////////////////////////////////

int met_open(const char *path, int oflag) {
return open(replace_path(path).c_str(), oflag);
return open(replace_path(path).c_str(), oflag);
}

////////////////////////////////////////////////////////////////////////

void met_open(ifstream &in, const char *path) {
in.open(replace_path(path).c_str());
in.open(replace_path(path).c_str());
return;
}

////////////////////////////////////////////////////////////////////////

void met_open(ofstream &out, const char *path) {
out.open(replace_path(path).c_str());
out.open(replace_path(path).c_str());
return;
}

Expand Down

0 comments on commit 8d92478

Please sign in to comment.