Skip to content

Commit

Permalink
util/string.h: add removeTrailingWhitespaces(), used in DlgTrackInfoM…
Browse files Browse the repository at this point in the history
…ulti

Co-authored-by: Lukas Waslowski <[email protected]>
  • Loading branch information
ronso0 and cr7pt0gr4ph7 committed Nov 3, 2024
1 parent 9c99b90 commit 74dc793
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
15 changes: 5 additions & 10 deletions src/library/dlgtrackinfomulti.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "util/datetime.h"
#include "util/desktophelper.h"
#include "util/duration.h"
#include "util/string.h"
#include "util/stringformat.h"
#include "widget/wcoverartlabel.h"
#include "widget/wcoverartmenu.h"
Expand Down Expand Up @@ -53,18 +54,15 @@ QString validEditText(QComboBox* pBox) {
// flag). For single-value boxes we compare with the original value.
auto* pLine = pBox->lineEdit();
const QString origVal = pBox->property(kOrigValProp).toString();
QString currVal = pLine->text();
const QString currText = pLine->text();
if ((pBox->count() > 0 && !pLine->placeholderText().isNull()) ||
(pBox->count() == 0 && currVal == origVal)) {
(pBox->count() == 0 && currText == origVal)) {
return QString();
}
// We have a new text.
// Remove trailing whitespaces. Keep Leading whitespaces to be consistent
// with the track table's inline editor.
while (currVal.endsWith(' ')) {
currVal.chop(1);
}
return currVal;
return mixxx::removeTrailingWhitespaces(currText);
}

/// Sets the text of a QLabel, either the only/common value or the 'various' string.
Expand Down Expand Up @@ -622,10 +620,7 @@ void DlgTrackInfoMulti::saveTracks() {
if ((txtCommentBox->count() > 0 && txtComment->placeholderText().isNull()) ||
(txtCommentBox->count() == 0 && currText != origText)) {
// Remove trailing whitespaces.
comment = currText;
while (comment.endsWith(' ')) {
comment.chop(1);
}
comment = mixxx::removeTrailingWhitespaces(currText);
}

for (auto& rec : m_trackRecords) {
Expand Down
10 changes: 10 additions & 0 deletions src/util/string.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ inline QString convertWCStringToQString(
return QString::fromWCharArray(wcs, static_cast<int>(wcsnlen_s(wcs, maxLen)));
}

/// Remove trailing spaces from the specified string.
/// Currently only handles simple ASCII spaces (" ").
inline QString removeTrailingWhitespaces(const QString& str) {
QString out = str;
while (out.endsWith(' ')) {
out.chop(1);
}
return out;
}

} // namespace mixxx

// Helper to create html link strings to be used for ui files, mostly in
Expand Down

0 comments on commit 74dc793

Please sign in to comment.