diff options
Diffstat (limited to 'sources/shiboken6/tests/libsample/str.cpp')
-rw-r--r-- | sources/shiboken6/tests/libsample/str.cpp | 95 |
1 files changed, 37 insertions, 58 deletions
diff --git a/sources/shiboken6/tests/libsample/str.cpp b/sources/shiboken6/tests/libsample/str.cpp index f8d1b726f..742c0bb01 100644 --- a/sources/shiboken6/tests/libsample/str.cpp +++ b/sources/shiboken6/tests/libsample/str.cpp @@ -2,91 +2,73 @@ // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 #include "str.h" + #include <cstdio> #include <cstdlib> #include <cstring> #include <sstream> -using namespace std; - -Str::Str(const Str& s) -{ - init(s.cstring()); -} - Str::Str(char c) { char str[2] = { c, 0 }; init(str); } -Str::Str(const char* cstr) +Str::Str(const char *cstr) { init(cstr); } -void -Str::init(const char* cstr) +void Str::init(const char *cstr) { if (cstr) m_str = cstr; } -Str::~Str() -{ -} - -Str -Str::arg(const Str& s) const +Str Str::arg(const Str &s) const { size_t idx = m_str.find_first_of("%VAR"); - if (idx == std::string::npos) { + if (idx == std::string::npos) return *this; - } else { - std::string result = m_str; - result.replace(idx, 4, s.m_str); - return result.c_str(); - } + + std::string result = m_str; + result.replace(idx, 4, s.m_str); + return result.c_str(); } -Str& -Str::append(const Str& s) +Str &Str::append(const Str &s) { m_str += s.m_str; return *this; } -Str& -Str::prepend(const Str& s) +Str &Str::prepend(const Str &s) { m_str = s.m_str + m_str; return *this; } -const char* -Str::cstring() const +const char *Str::cstring() const { return m_str.c_str(); } -int -Str::toInt(bool* ok, int base) const +int Str::toInt(bool *ok, int base) const { - bool my_ok; int result = 0; - istringstream conv(m_str); + std::istringstream conv(m_str); switch (base) { - case 8: - conv >> std::oct >> result; - break; - case 10: - conv >> std::dec >> result; - break; - case 16: - conv >> std::hex >> result; - break; + case 8: + conv >> std::oct >> result; + break; + case 10: + conv >> std::dec >> result; + break; + case 16: + conv >> std::hex >> result; + break; } - my_ok = istringstream::eofbit & conv.rdstate(); + const bool my_ok = std::istringstream::eofbit & conv.rdstate(); if (!my_ok) result = 0; if (ok) @@ -94,20 +76,17 @@ Str::toInt(bool* ok, int base) const return result; } -void -Str::show() const +void Str::show() const { - printf("%s", cstring()); + std::printf("%s", cstring()); } -char -Str::get_char(int pos) const +char Str::get_char(int pos) const { return m_str[pos]; } -bool -Str::set_char(int pos, char ch) +bool Str::set_char(int pos, char ch) { m_str[pos] = ch; return true; @@ -115,42 +94,42 @@ Str::set_char(int pos, char ch) Str Str::operator+(int number) const { - ostringstream in; + std::ostringstream in; in << m_str << number; return in.str().c_str(); } -bool Str::operator==(const Str& other) const +bool Str::operator==(const Str &other) const { return m_str == other.m_str; } -Str operator+(int number, const Str& str) +Str operator+(int number, const Str &str) { - ostringstream in; + std::ostringstream in; in << number << str.m_str; return in.str().c_str(); } -bool Str::operator<(const Str& other) const +bool Str::operator<(const Str &other) const { return m_str < other.m_str; } -unsigned int strHash(const Str& str) +unsigned int strHash(const Str &str) { unsigned int result = 0; for (char c : str.m_str) - result = 5u * result + unsigned(c); + result = 5U * result + unsigned(c); return result; } -void changePStr(PStr* pstr, const char* suffix) +void changePStr(PStr *pstr, const char *suffix) { pstr->append(suffix); } -void duplicatePStr(PStr* pstr) +void duplicatePStr(PStr *pstr) { if (!pstr) return; |