diff options
Diffstat (limited to 'sources/shiboken6/tests/libsample/str.cpp')
-rw-r--r-- | sources/shiboken6/tests/libsample/str.cpp | 128 |
1 files changed, 40 insertions, 88 deletions
diff --git a/sources/shiboken6/tests/libsample/str.cpp b/sources/shiboken6/tests/libsample/str.cpp index 634bd4a86..742c0bb01 100644 --- a/sources/shiboken6/tests/libsample/str.cpp +++ b/sources/shiboken6/tests/libsample/str.cpp @@ -1,117 +1,74 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of Qt for Python. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** Commercial License Usage -** Licensees holding valid commercial Qt licenses may use this file in -** accordance with the commercial license agreement provided with the -** Software or, alternatively, in accordance with the terms contained in -** a written agreement between you and The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// 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) @@ -119,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; @@ -140,44 +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; - const std::string& cppStr = str.m_str; - std::string::const_iterator it = cppStr.begin(); - for (; it != cppStr.end(); ++it) - result = 5 * result + *it; + for (char c : str.m_str) + 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; |