Skip to content

Commit

Permalink
Merge pull request #1608 from Waqar144/tests
Browse files Browse the repository at this point in the history
Tests and improvements for Utils::Misc
  • Loading branch information
pbek committed Jan 27, 2020
2 parents 6df9774 + 15d573d commit 2ccf687
Show file tree
Hide file tree
Showing 15 changed files with 295 additions and 90 deletions.
2 changes: 1 addition & 1 deletion src/dialogs/linkdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ QString LinkDialog::getTitleForUrl(const QUrl& url) {
QString title = match.captured(1);

// decode HTML entities
title = Utils::Misc::unescapeHtml(title);
title = Utils::Misc::unescapeHtml(std::move(title));

// replace some other characters we don't want
title.replace(QStringLiteral("["), QStringLiteral("("))
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3017,7 +3017,7 @@ void SettingsDialog::on_addCustomNoteFileExtensionButton_clicked() {
}

// make sure the file extension doesn't start with a point
fileExtension = Utils::Misc::removeIfStartsWith(fileExtension, ".");
fileExtension = Utils::Misc::removeIfStartsWith(std::move(fileExtension), ".");

QListWidgetItem *item = addCustomNoteFileExtension(fileExtension);

Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/updatedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ bool UpdateDialog::initializeMacOSUpdateProcess(QString releaseUrl) {

if (applicationDirPath.endsWith(appPathPart)) {
applicationsPath = Utils::Misc::removeIfEndsWith(
applicationDirPath, appPathPart);
std::move(applicationDirPath), appPathPart);
}

if (Utils::Gui::question(
Expand Down
6 changes: 3 additions & 3 deletions src/entities/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1488,10 +1488,10 @@ QString Note::getFullFilePathForFile(const QString& fileName) {
QSettings settings;

// prepend the portable data path if we are in portable mode
QString notesPath = Utils::Misc::prependPortableDataPathIfNeeded(
const QString notesPath = Utils::Misc::prependPortableDataPathIfNeeded(
settings.value(QStringLiteral("notesPath")).toString());

return Utils::Misc::removeIfEndsWith(notesPath, QStringLiteral("/")) +
return Utils::Misc::removeIfEndsWith(std::move(notesPath), QStringLiteral("/")) +
Utils::Misc::dirSeparator() + fileName;
}

Expand Down Expand Up @@ -3218,7 +3218,7 @@ QString Note::getNotePreviewText(bool asHtml, int lines) const {
}

if (asHtml) {
noteText = Utils::Misc::htmlspecialchars(noteText);
noteText = Utils::Misc::htmlspecialchars(std::move(noteText));
noteText.replace(QStringLiteral("\n"), QStringLiteral("<br>"));
}

Expand Down
14 changes: 7 additions & 7 deletions src/entities/notefolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@ QString NoteFolder::currentRemotePath(bool addTrailingSlash) {
}

// add a leading "/"
remotePath = Utils::Misc::prependIfDoesNotStartWith(remotePath, QStringLiteral("/"));
remotePath = Utils::Misc::prependIfDoesNotStartWith(std::move(remotePath), QStringLiteral("/"));

if (addTrailingSlash) {
// add a trailing "/"
remotePath = Utils::Misc::appendIfDoesNotEndWith(remotePath, QStringLiteral("/"));
remotePath = Utils::Misc::appendIfDoesNotEndWith(std::move(remotePath), QStringLiteral("/"));
} else {
// remove a trailing "/"
remotePath = Utils::Misc::removeIfEndsWith(remotePath, QStringLiteral("/"));
remotePath = Utils::Misc::removeIfEndsWith(std::move(remotePath), QStringLiteral("/"));
}

return remotePath;
Expand All @@ -369,8 +369,8 @@ QString NoteFolder::currentLocalPath() {
settings.value(QStringLiteral("notesPath")).toString());
}

path = Utils::Misc::removeIfEndsWith(path, QDir::separator());
path = Utils::Misc::removeIfEndsWith(path, Utils::Misc::dirSeparator());
path = Utils::Misc::removeIfEndsWith(std::move(path), QDir::separator());
path = Utils::Misc::removeIfEndsWith(std::move(path), Utils::Misc::dirSeparator());

return path;
}
Expand Down Expand Up @@ -453,8 +453,8 @@ QString NoteFolder::suggestRemotePath() {
* Removes a leading or trailing slash from the remote path
*/
QString NoteFolder::fixRemotePath() {
remotePath = Utils::Misc::removeIfStartsWith(remotePath, QStringLiteral("/"));
remotePath = Utils::Misc::removeIfEndsWith(remotePath, QStringLiteral("/"));
remotePath = Utils::Misc::removeIfStartsWith(std::move(remotePath), QStringLiteral("/"));
remotePath = Utils::Misc::removeIfEndsWith(std::move(remotePath), QStringLiteral("/"));
return remotePath;
}

Expand Down
4 changes: 2 additions & 2 deletions src/entities/notesubfolder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,14 +140,14 @@ QString NoteSubFolder::pathData() const {
*/
NoteSubFolder NoteSubFolder::fetchByPathData(QString pathData,
const QString& separator) {
pathData = Utils::Misc::removeIfStartsWith(pathData, separator);
pathData = Utils::Misc::removeIfStartsWith(std::move(pathData), separator);
QStringList pathList = pathData.split(separator);
NoteSubFolder noteSubFolder;
QStringListIterator itr(pathList);

// loop through all names to fetch the deepest note sub folder
while (itr.hasNext()) {
QString name = itr.next();
const QString name = itr.next();
noteSubFolder = NoteSubFolder::fetchByNameAndParentId(
name, noteSubFolder.getId());
if (!noteSubFolder.isFetched()) {
Expand Down
8 changes: 4 additions & 4 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1765,7 +1765,7 @@ void MainWindow::changeNoteFolder(const int noteFolderId, const bool forceChange
settings.setValue(
QStringLiteral("notesPath"),
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
folderName));
std::move(folderName)));

// we have to unset the current note otherwise it might show up after
// switching to another note folder
Expand Down Expand Up @@ -3366,7 +3366,7 @@ QString MainWindow::selectOwnCloudNotesFolder() {
settings.setValue(
QStringLiteral("notesPath"),
Utils::Misc::makePathRelativeToPortableDataPathIfNeeded(
dir));
std::move(dir)));

// update the current folder tooltip
updateCurrentFolderTooltip();
Expand Down Expand Up @@ -7074,7 +7074,7 @@ void MainWindow::handleInsertingFromMimeData(const QMimeData *mimeData) {
*/
void MainWindow::insertHtml(QString html) {
// convert html tags to markdown
html = Utils::Misc::htmlToMarkdown(html);
html = Utils::Misc::htmlToMarkdown(std::move(html));

// match image tags
QRegularExpression re(QStringLiteral("<img.+?src=[\"'](.+?)[\"'].*?>"),
Expand Down Expand Up @@ -7121,7 +7121,7 @@ void MainWindow::insertHtml(QString html) {
html.remove(QRegularExpression(QStringLiteral("<.+?>")));

// unescape some html special characters
html = Utils::Misc::unescapeHtml(html).trimmed();
html = Utils::Misc::unescapeHtml(std::move(html)).trimmed();

QOwnNotesMarkdownTextEdit* textEdit = activeNoteTextEdit();
QTextCursor c = textEdit->textCursor();
Expand Down
2 changes: 1 addition & 1 deletion src/services/owncloudservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1705,7 +1705,7 @@ void OwnCloudService::updateNoteShareStatus(QXmlQuery &query,
}

// remove the note path from the path
path = Utils::Misc::removeIfStartsWith(path, serverNotesPath);
path = Utils::Misc::removeIfStartsWith(std::move(path), serverNotesPath);

QFileInfo fileInfo(path);
QString fileName = fileInfo.fileName();
Expand Down
2 changes: 1 addition & 1 deletion src/services/websocketserverservice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ void WebSocketServerService::processMessage(const QString &message) {
MainWindow::CreateNewNoteOption::UseNameAsHeadline));

if (contentTypeIsHTML) {
mainWindow->insertHtml(text);
mainWindow->insertHtml(std::move(text));
}
#endif
} else if (type == "getBookmarks") {
Expand Down
Loading

0 comments on commit 2ccf687

Please sign in to comment.