Skip to content

Commit

Permalink
fix: put everything from utils/strings.h into the namespace Utils
Browse files Browse the repository at this point in the history
Closed: #44
  • Loading branch information
Montel authored and narnaud committed Jun 21, 2024
1 parent ff46f1c commit 94bdab8
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 66 deletions.
2 changes: 1 addition & 1 deletion src/core/codedocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ Symbol *CodeDocument::findSymbol(const QString &name, int options) const
LOG("CodeDocument::findSymbol", LOG_ARG("text", name), options);

auto symbols = this->symbols();
const auto regexp = (options & FindRegexp) ? createRegularExpression(name, options) : QRegularExpression {};
const auto regexp = (options & FindRegexp) ? Utils::createRegularExpression(name, options) : QRegularExpression {};
auto byName = [name, options, regexp](Symbol *symbol) {
if (options & FindWholeWords)
return symbol->name().compare(name,
Expand Down
12 changes: 6 additions & 6 deletions src/core/textdocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ bool TextDocument::replaceOne(const QString &before, const QString &after, int o
const bool usesRegExp = options & FindRegexp;
const bool preserveCase = options & PreserveCase;

auto regexp = createRegularExpression(before, options, usesRegExp);
auto regexp = Utils::createRegularExpression(before, options, usesRegExp);
if (find(before, options)) {
cursor.beginEditBlock();
auto found = m_document->textCursor();
Expand All @@ -1367,9 +1367,9 @@ bool TextDocument::replaceOne(const QString &before, const QString &after, int o
QString afterText = after;
if (usesRegExp) {
QRegularExpressionMatch match = regexp.match(selectedText());
afterText = expandRegExpReplacement(after, match.capturedTexts());
afterText = Utils::expandRegExpReplacement(after, match.capturedTexts());
} else if (preserveCase) {
afterText = matchCaseReplacement(cursor.selectedText(), after);
afterText = Utils::matchCaseReplacement(cursor.selectedText(), after);
}
cursor.insertText(afterText);
cursor.endEditBlock();
Expand Down Expand Up @@ -1449,7 +1449,7 @@ int TextDocument::replaceAll(const QString &before, const QString &after, int op
m_document->setTextCursor(cursor);
cursor.beginEditBlock();

auto regexp = createRegularExpression(before, options, usesRegExp);
auto regexp = Utils::createRegularExpression(before, options, usesRegExp);
while (find(before, options)) {
const auto found = m_document->textCursor();
cursor.setPosition(found.selectionStart());
Expand All @@ -1461,9 +1461,9 @@ int TextDocument::replaceAll(const QString &before, const QString &after, int op
QString afterText = after;
if (usesRegExp) {
QRegularExpressionMatch match = regexp.match(selectedText());
afterText = expandRegExpReplacement(after, match.capturedTexts());
afterText = Utils::expandRegExpReplacement(after, match.capturedTexts());
} else if (preserveCase) {
afterText = matchCaseReplacement(cursor.selectedText(), after);
afterText = Utils::matchCaseReplacement(cursor.selectedText(), after);
}
cursor.insertText(afterText);
++count;
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ QString Utils::mktemp(const QString &pattern)
QString Utils::convertCase(const QString &str, Case from, Case to)
{
LOG("Utils::convertCase", str, from, to);
return Core::convertCase(str, static_cast<::Core::Case>(from), static_cast<::Core::Case>(to));
return ::Utils::convertCase(str, static_cast<::Utils::Case>(from), static_cast<::Utils::Case>(to));
}

/*!
Expand Down
14 changes: 7 additions & 7 deletions src/core/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ class Utils : public QObject

public:
enum Case {
CamelCase = static_cast<int>(::Core::Case::CamelCase),
PascalCase = static_cast<int>(::Core::Case::PascalCase),
SnakeCase = static_cast<int>(::Core::Case::SnakeCase),
UpperCase = static_cast<int>(::Core::Case::UpperCase),
KebabCase = static_cast<int>(::Core::Case::KebabCase),
TitleCase = static_cast<int>(::Core::Case::TitleCase),
CamelCase = static_cast<int>(::Utils::Case::CamelCase),
PascalCase = static_cast<int>(::Utils::Case::PascalCase),
SnakeCase = static_cast<int>(::Utils::Case::SnakeCase),
UpperCase = static_cast<int>(::Utils::Case::UpperCase),
KebabCase = static_cast<int>(::Utils::Case::KebabCase),
TitleCase = static_cast<int>(::Utils::Case::TitleCase),
};
Q_ENUM(Case)

Expand All @@ -48,7 +48,7 @@ public slots:

static QString mktemp(const QString &pattern);

static QString convertCase(const QString &str, Core::Utils::Case from, Core::Utils::Case to);
static QString convertCase(const QString &str, Case from, Case to);

static void copyToClipboard(const QString &text);

Expand Down
2 changes: 1 addition & 1 deletion src/utils/strings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <QSet>
#include <QTextDocument>

namespace Core {
namespace Utils {

static QString nextWordInString(const QString &str, QString::const_iterator &i, Case c)
{
Expand Down
2 changes: 1 addition & 1 deletion src/utils/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <QRegularExpression>
#include <QString>

namespace Core {
namespace Utils {

enum class Case {
CamelCase,
Expand Down
98 changes: 49 additions & 49 deletions tests/tst_stringutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

#include <QTest>

using namespace Core;
using namespace Utils;

class TestStringUtils : public QObject
{
Expand All @@ -21,59 +21,59 @@ class TestStringUtils : public QObject
private slots:
void test_formatCase()
{
QCOMPARE(convertCase("toCamelCase", Core::Case::CamelCase, Core::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("ToCamelCase", Core::Case::PascalCase, Core::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("to_camel_case", Core::Case::SnakeCase, Core::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("to-camel-case", Core::Case::KebabCase, Core::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("TO_CAMEL_CASE", Core::Case::UpperCase, Core::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("To Camel Case", Core::Case::TitleCase, Core::Case::CamelCase), "toCamelCase");

QCOMPARE(convertCase("toPascalCase", Core::Case::CamelCase, Core::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("ToPascalCase", Core::Case::PascalCase, Core::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("to_pascal_case", Core::Case::SnakeCase, Core::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("to-pascal-case", Core::Case::KebabCase, Core::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("TO_PASCAL_CASE", Core::Case::UpperCase, Core::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("To Pascal Case", Core::Case::TitleCase, Core::Case::PascalCase), "ToPascalCase");

QCOMPARE(convertCase("toSnakeCase", Core::Case::CamelCase, Core::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("ToSnakeCase", Core::Case::PascalCase, Core::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("to_snake_case", Core::Case::SnakeCase, Core::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("to-snake-case", Core::Case::KebabCase, Core::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("TO_SNAKE_CASE", Core::Case::UpperCase, Core::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("To Snake Case", Core::Case::TitleCase, Core::Case::SnakeCase), "to_snake_case");

QCOMPARE(convertCase("toUpperCase", Core::Case::CamelCase, Core::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("ToUpperCase", Core::Case::PascalCase, Core::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("to_upper_case", Core::Case::SnakeCase, Core::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("to-upper-case", Core::Case::KebabCase, Core::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("TO_UPPER_CASE", Core::Case::UpperCase, Core::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("To Upper Case", Core::Case::TitleCase, Core::Case::UpperCase), "TO_UPPER_CASE");

QCOMPARE(convertCase("toKebabCase", Core::Case::CamelCase, Core::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("ToKebabCase", Core::Case::PascalCase, Core::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("to_kebab_case", Core::Case::SnakeCase, Core::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("to-kebab-case", Core::Case::KebabCase, Core::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("TO_KEBAB_CASE", Core::Case::UpperCase, Core::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("To Kebab Case", Core::Case::TitleCase, Core::Case::KebabCase), "to-kebab-case");

QCOMPARE(convertCase("toTitleCase", Core::Case::CamelCase, Core::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("ToTitleCase", Core::Case::PascalCase, Core::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("to_title_case", Core::Case::SnakeCase, Core::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("to-title-case", Core::Case::KebabCase, Core::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("TO_TITLE_CASE", Core::Case::UpperCase, Core::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("To Title Case", Core::Case::TitleCase, Core::Case::TitleCase), "To Title Case");

QCOMPARE(convertCase("toTitleCaseWithAnException", Core::Case::CamelCase, Core::Case::TitleCase),
QCOMPARE(convertCase("toCamelCase", Utils::Case::CamelCase, Utils::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("ToCamelCase", Utils::Case::PascalCase, Utils::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("to_camel_case", Utils::Case::SnakeCase, Utils::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("to-camel-case", Utils::Case::KebabCase, Utils::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("TO_CAMEL_CASE", Utils::Case::UpperCase, Utils::Case::CamelCase), "toCamelCase");
QCOMPARE(convertCase("To Camel Case", Utils::Case::TitleCase, Utils::Case::CamelCase), "toCamelCase");

QCOMPARE(convertCase("toPascalCase", Utils::Case::CamelCase, Utils::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("ToPascalCase", Utils::Case::PascalCase, Utils::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("to_pascal_case", Utils::Case::SnakeCase, Utils::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("to-pascal-case", Utils::Case::KebabCase, Utils::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("TO_PASCAL_CASE", Utils::Case::UpperCase, Utils::Case::PascalCase), "ToPascalCase");
QCOMPARE(convertCase("To Pascal Case", Utils::Case::TitleCase, Utils::Case::PascalCase), "ToPascalCase");

QCOMPARE(convertCase("toSnakeCase", Utils::Case::CamelCase, Utils::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("ToSnakeCase", Utils::Case::PascalCase, Utils::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("to_snake_case", Utils::Case::SnakeCase, Utils::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("to-snake-case", Utils::Case::KebabCase, Utils::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("TO_SNAKE_CASE", Utils::Case::UpperCase, Utils::Case::SnakeCase), "to_snake_case");
QCOMPARE(convertCase("To Snake Case", Utils::Case::TitleCase, Utils::Case::SnakeCase), "to_snake_case");

QCOMPARE(convertCase("toUpperCase", Utils::Case::CamelCase, Utils::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("ToUpperCase", Utils::Case::PascalCase, Utils::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("to_upper_case", Utils::Case::SnakeCase, Utils::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("to-upper-case", Utils::Case::KebabCase, Utils::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("TO_UPPER_CASE", Utils::Case::UpperCase, Utils::Case::UpperCase), "TO_UPPER_CASE");
QCOMPARE(convertCase("To Upper Case", Utils::Case::TitleCase, Utils::Case::UpperCase), "TO_UPPER_CASE");

QCOMPARE(convertCase("toKebabCase", Utils::Case::CamelCase, Utils::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("ToKebabCase", Utils::Case::PascalCase, Utils::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("to_kebab_case", Utils::Case::SnakeCase, Utils::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("to-kebab-case", Utils::Case::KebabCase, Utils::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("TO_KEBAB_CASE", Utils::Case::UpperCase, Utils::Case::KebabCase), "to-kebab-case");
QCOMPARE(convertCase("To Kebab Case", Utils::Case::TitleCase, Utils::Case::KebabCase), "to-kebab-case");

QCOMPARE(convertCase("toTitleCase", Utils::Case::CamelCase, Utils::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("ToTitleCase", Utils::Case::PascalCase, Utils::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("to_title_case", Utils::Case::SnakeCase, Utils::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("to-title-case", Utils::Case::KebabCase, Utils::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("TO_TITLE_CASE", Utils::Case::UpperCase, Utils::Case::TitleCase), "To Title Case");
QCOMPARE(convertCase("To Title Case", Utils::Case::TitleCase, Utils::Case::TitleCase), "To Title Case");

QCOMPARE(convertCase("toTitleCaseWithAnException", Utils::Case::CamelCase, Utils::Case::TitleCase),
"To Title Case With an Exception");
QCOMPARE(convertCase("ToTitleCaseWithAnException", Core::Case::PascalCase, Core::Case::TitleCase),
QCOMPARE(convertCase("ToTitleCaseWithAnException", Utils::Case::PascalCase, Utils::Case::TitleCase),
"To Title Case With an Exception");
QCOMPARE(convertCase("to_title_case_with_an_exception", Core::Case::SnakeCase, Core::Case::TitleCase),
QCOMPARE(convertCase("to_title_case_with_an_exception", Utils::Case::SnakeCase, Utils::Case::TitleCase),
"To Title Case With an Exception");
QCOMPARE(convertCase("to-title-case-with-an-exception", Core::Case::KebabCase, Core::Case::TitleCase),
QCOMPARE(convertCase("to-title-case-with-an-exception", Utils::Case::KebabCase, Utils::Case::TitleCase),
"To Title Case With an Exception");
QCOMPARE(convertCase("TO_TITLE_CASE_WITH_AN_EXCEPTION", Core::Case::UpperCase, Core::Case::TitleCase),
QCOMPARE(convertCase("TO_TITLE_CASE_WITH_AN_EXCEPTION", Utils::Case::UpperCase, Utils::Case::TitleCase),
"To Title Case With an Exception");
QCOMPARE(convertCase("To Title Case With an Exception", Core::Case::TitleCase, Core::Case::TitleCase),
QCOMPARE(convertCase("To Title Case With an Exception", Utils::Case::TitleCase, Utils::Case::TitleCase),
"To Title Case With an Exception");
}

Expand Down

0 comments on commit 94bdab8

Please sign in to comment.