mirror of
https://github.com/silverqx/TinyORM.git
synced 2026-01-08 20:09:53 -06:00
added support for MSYS2 gcc/clang
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
#include "orm/tiny/utils/string.hpp"
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
#include "orm/constants.hpp"
|
||||
|
||||
using Orm::Constants::DASH;
|
||||
@@ -28,7 +32,7 @@ namespace
|
||||
using SnakeCache = std::unordered_map<QString, QString>;
|
||||
|
||||
/*! Snake cache for already computed strings. */
|
||||
Q_GLOBAL_STATIC(SnakeCache, snakeCache);
|
||||
Q_GLOBAL_STATIC(SnakeCache, snakeCache); // NOLINT(readability-redundant-member-init)
|
||||
} // namespace
|
||||
|
||||
QString String::snake(QString string, const QChar delimiter)
|
||||
@@ -70,7 +74,7 @@ namespace
|
||||
using StudlyCache = std::unordered_map<QString, QString>;
|
||||
|
||||
/*! Studly cache for already computed strings. */
|
||||
Q_GLOBAL_STATIC(StudlyCache, studlyCache);
|
||||
Q_GLOBAL_STATIC(StudlyCache, studlyCache); // NOLINT(readability-redundant-member-init)
|
||||
} // namespace
|
||||
|
||||
QString String::studly(QString string)
|
||||
@@ -147,35 +151,27 @@ bool String::isNumber(const QString &string, const bool allowFloating)
|
||||
}
|
||||
|
||||
#ifndef TINYORM_DISABLE_TOM
|
||||
/*! Split a string by the given width (not in the middle of a word). */
|
||||
std::vector<QString> String::splitStringByWidth(const QString &string, const int width)
|
||||
namespace
|
||||
{
|
||||
// Nothing to split
|
||||
if (string.size() <= width)
|
||||
return {string};
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
using StringViewType = QStringView;
|
||||
#else
|
||||
using StringViewType = QStringRef;
|
||||
#endif
|
||||
|
||||
std::vector<QString> lines;
|
||||
QString line;
|
||||
/*! Split the token to multiple lines by the given width. */
|
||||
bool splitLongToken(StringViewType token, const int width, QString &line,
|
||||
std::vector<QString> &lines)
|
||||
{
|
||||
auto shouldContinue = false;
|
||||
|
||||
for (auto token : string.tokenize(SPACE)) {
|
||||
/* If there is still a space on the line then append the token */
|
||||
if (line.size() + token.size() + 1 <= width) {
|
||||
// Don't prepend the space at beginning of an empty line
|
||||
if (!line.isEmpty())
|
||||
line.append(' ');
|
||||
|
||||
line.append(token);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If a token is longer than the width or an empty space on the current line */
|
||||
const auto spaceSize = line.isEmpty() ? 0 : 1;
|
||||
|
||||
if (const auto emptySpace = width - line.size() + spaceSize;
|
||||
token.size() > emptySpace
|
||||
) {
|
||||
// If on the line is still more than 30% of an empty space, use/fill it
|
||||
if (emptySpace > llround(static_cast<float>(width) * 0.3)) {
|
||||
if (emptySpace > std::llround(static_cast<float>(width) * 0.3F)) {
|
||||
// Position where to split the token
|
||||
auto pos = width - line.size() - spaceSize;
|
||||
|
||||
@@ -208,12 +204,45 @@ std::vector<QString> String::splitStringByWidth(const QString &string, const int
|
||||
// Push to lines
|
||||
lines.emplace_back(std::move(line));
|
||||
// Start a new line
|
||||
line.clear();
|
||||
line.clear(); // NOLINT(bugprone-use-after-move)
|
||||
}
|
||||
|
||||
shouldContinue = true;
|
||||
}
|
||||
|
||||
return shouldContinue;
|
||||
}
|
||||
} // namespace
|
||||
|
||||
/*! Split a string by the given width (not in the middle of a word). */
|
||||
std::vector<QString> String::splitStringByWidth(const QString &string, const int width)
|
||||
{
|
||||
// Nothing to split
|
||||
if (string.size() <= width)
|
||||
return {string};
|
||||
|
||||
std::vector<QString> lines;
|
||||
QString line;
|
||||
|
||||
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
||||
for (auto token : string.tokenize(SPACE)) {
|
||||
#else
|
||||
for (auto token : string.splitRef(SPACE)) { // NOLINT(performance-for-range-copy) clazy:exclude=range-loop
|
||||
#endif
|
||||
/* If there is still a space on the line then append the token */
|
||||
if (line.size() + token.size() + 1 <= width) {
|
||||
// Don't prepend the space at beginning of an empty line
|
||||
if (!line.isEmpty())
|
||||
line.append(SPACE);
|
||||
|
||||
line.append(token);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* If a token is longer than the width or an empty space on the current line */
|
||||
if (splitLongToken(token, width, line, lines))
|
||||
continue;
|
||||
|
||||
// No space on the line, push to lines and start a new line
|
||||
lines.emplace_back(std::move(line));
|
||||
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace Concerns
|
||||
public:
|
||||
/*! Default constructor. */
|
||||
inline CallsCommands() = default;
|
||||
/*! Default destructor. */
|
||||
inline ~CallsCommands() = default;
|
||||
/*! Virtual destructor. */
|
||||
inline virtual ~CallsCommands() = default;
|
||||
|
||||
/*! Call another console command. */
|
||||
inline int call(const QString &command, QStringList &&arguments = {}) const;
|
||||
|
||||
@@ -34,8 +34,8 @@ namespace Concerns
|
||||
public:
|
||||
/*! Constructor (int param. to avoid interpret it as copy ctor). */
|
||||
Confirmable(Command &command, int);
|
||||
/*! Default destructor. */
|
||||
inline ~Confirmable() = default;
|
||||
/*! Virtual destructor. */
|
||||
inline virtual ~Confirmable() = default;
|
||||
|
||||
/*! Confirm before proceeding with the action (only in production environment). */
|
||||
bool confirmToProceed(
|
||||
|
||||
@@ -40,8 +40,8 @@ namespace Concerns
|
||||
|
||||
/*! Constructor. */
|
||||
explicit InteractsWithIO(const QCommandLineParser &parser);
|
||||
/*! Default destructor. */
|
||||
~InteractsWithIO();
|
||||
/*! Virtual destructor. */
|
||||
virtual ~InteractsWithIO();
|
||||
|
||||
/*! Base enum for the verbosity levels. */
|
||||
enum struct Verbosity {
|
||||
|
||||
@@ -29,8 +29,8 @@ namespace Concerns
|
||||
public:
|
||||
/*! Constructor (int param. to avoid interpret it as copy ctor). */
|
||||
PrintsOptions(const Commands::Command &command, int);
|
||||
/*! Default destructor. */
|
||||
inline ~PrintsOptions() = default;
|
||||
/*! Virtual destructor. */
|
||||
inline virtual ~PrintsOptions() = default;
|
||||
|
||||
/*! Print options section. */
|
||||
int printOptionsSection(bool commonOptions) const;
|
||||
|
||||
@@ -139,7 +139,7 @@ namespace Tom
|
||||
/*! The database connection resolver instance. */
|
||||
std::shared_ptr<ConnectionResolverInterface> m_resolver;
|
||||
/*! The name of the database connection to use. */
|
||||
QString m_connection;
|
||||
QString m_connection {};
|
||||
|
||||
/*! Reference to the migrations vector to process. */
|
||||
const std::vector<std::shared_ptr<Migration>> &m_migrations;
|
||||
|
||||
@@ -76,9 +76,9 @@ namespace Tom
|
||||
#endif
|
||||
|
||||
/*! Cache for detected ansi output. */
|
||||
mutable std::unordered_map<std::ostream *, bool> m_isAnsiOutput;
|
||||
mutable std::unordered_map<std::ostream *, bool> m_isAnsiOutput {};
|
||||
/*! Cache for detected ansi output, wide version. */
|
||||
mutable std::unordered_map<std::wostream *, bool> m_isAnsiWOutput;
|
||||
mutable std::unordered_map<std::wostream *, bool> m_isAnsiWOutput {};
|
||||
|
||||
/*! Current terminal width. */
|
||||
int m_lastWidth = 80;
|
||||
|
||||
Reference in New Issue
Block a user