diff options
author | Samuel Gaist <samuel.gaist@edeltech.ch> | 2015-06-17 11:07:14 +0200 |
---|---|---|
committer | Samuel Gaist <samuel.gaist@edeltech.ch> | 2015-06-19 23:23:31 +0000 |
commit | 8481500f639e3d5e2259db57847a2e7068e30650 (patch) | |
tree | 043ab8047f0b11cd1c024b50d2ab8210538addde /src/corelib/tools/qstring.cpp | |
parent | 94e364464ee162ac919a66a44e27ee9adda65c77 (diff) |
Improve QString doc when using non-spaced numbered place marker
Currently when a developer uses a string like
QString("%1%3%2").arg(x).arg(y).arg(z) he can be bitten by the
sequential replacement done by QString. Adding an example with a little
explanation should help future Qt user avoid generating buggy strings.
Task-number: QTBUG-44044
Change-Id: I81e20af8d9fb2a07e12ec61dcd5bb4544d863777
Reviewed-by: Sze Howe Koh <szehowe.koh@gmail.com>
Diffstat (limited to 'src/corelib/tools/qstring.cpp')
-rw-r--r-- | src/corelib/tools/qstring.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp index c933e261cc..bbb5647eea 100644 --- a/src/corelib/tools/qstring.cpp +++ b/src/corelib/tools/qstring.cpp @@ -7206,6 +7206,25 @@ QString QString::arg(const QString &a, int fieldWidth, QChar fillChar) const difference if \a a1 contains e.g. \c{%1}: \snippet qstring/main.cpp 13 + + A similar problem occurs when the numbered place markers are not + white space separated: + + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 97 + + Let's look at the substitutions: + \list + \li First, \c Hello replaces \c {%1} so the string becomes \c {"Hello%3%2"}. + \li Then, \c 20 replaces \c {%2} so the string becomes \c {"Hello%320"}. + \li Since the maximum numbered place marker value is 99, \c 50 replaces \c {%32}. + \endlist + Thus the string finally becomes \c {"Hello500"}. + + In such cases, the following yields the expected results: + + \snippet qstring/main.cpp 12 + \snippet qstring/main.cpp 98 */ /*! |