From 3fc13f8a61cdbef3cb57c0b2ab943818b0a7555c Mon Sep 17 00:00:00 2001 From: Christian Hoffmann Date: Tue, 25 Jan 2022 11:55:31 +0100 Subject: [PATCH] Client: Fix wrong truncation of unicode aliases If the 16th char of the user-selected alias was a multi-byte unicode char, it would be incorrectly split in half, rendering it invalid. This commit makes the truncation unicode-aware. The fix was initially developed in ce370e95d43b2051ba20160e5ec50f13b2de5748. It got lost during PR merge in commit a8853b6a7deb19e3596fb47bbb72a5baf29c4c7a, most likely during conflict resolution due to code reorganizations in d94fd69e1404a874beec53d6a721abcd74caf8fb. This commit re-applies the fix to the new place (CClientSettingsDlg::OnAliasTextChanged instead of the no longer existing CMusProfDlg::OnAliasTextChanged). It also adds a function declaration to the header to make inclusion by other files possible in the first place. This also required dropping the `static` and `inline` keywords. Fixes #1994 (for real). Fixes #2274. Co-authored-by: Martin Kaistra --- ChangeLog | 4 ++-- src/clientsettingsdlg.cpp | 2 +- src/util.cpp | 2 +- src/util.h | 3 +++ 4 files changed, 7 insertions(+), 4 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2bc9cb6453..e035deb2f4 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,8 +18,8 @@ - Client: Added Conductor to list of instruments (#2140). (contributed by @henkdegroot) -- Client: Fix wrong display of Unicode characters at line wrap (#1994). - (contributed by @djfun, @pljones) +- Client: Fix wrong display of Unicode characters at line wrap and settings screen (#1994, #2274). + (contributed by @djfun, @pljones, @hoffie) - Client: Fixed incorrect operation of feedback detection on first connect in run (#2120). (contributed by @softins) diff --git a/src/clientsettingsdlg.cpp b/src/clientsettingsdlg.cpp index 8c0c9408e9..3b68d4fa27 100644 --- a/src/clientsettingsdlg.cpp +++ b/src/clientsettingsdlg.cpp @@ -1093,7 +1093,7 @@ void CClientSettingsDlg::OnAliasTextChanged ( const QString& strNewName ) else { // text is too long, update control with shortened text - pedtAlias->setText ( strNewName.left ( MAX_LEN_FADER_TAG ) ); + pedtAlias->setText ( TruncateString ( strNewName, MAX_LEN_FADER_TAG ) ); } } diff --git a/src/util.cpp b/src/util.cpp index 1df7f01b1e..f3d105307b 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -667,7 +667,7 @@ void CLanguageComboBox::OnLanguageActivated ( int iLanguageIdx ) } } -static inline QString TruncateString ( QString str, int position ) +QString TruncateString ( QString str, int position ) { QTextBoundaryFinder tbfString ( QTextBoundaryFinder::Grapheme, str ); diff --git a/src/util.h b/src/util.h index 6072c7727c..f707e87b79 100644 --- a/src/util.h +++ b/src/util.h @@ -99,6 +99,9 @@ inline int CalcBitRateBitsPerSecFromCodedBytes ( const int iCeltNumCodedBytes, c QString GetVersionAndNameStr ( const bool bDisplayInGui = true ); QString MakeClientNameTitle ( QString win, QString client ); +#ifndef HEADLESS +QString TruncateString ( QString str, int position ); +#endif /******************************************************************************\ * CVector Base Class *