KStatusNotifierItem

utils.cpp
1/* This file is part of the dbusmenu-qt library
2 SPDX-FileCopyrightText: 2010 Canonical
3 Author: Aurelien Gateau <aurelien.gateau@canonical.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7#include "utils_p.h"
8
9// Qt
10#include <QString>
11
12QString swapMnemonicChar(const QString &in, const QChar &src, const QChar &dst)
13{
14 QString out;
15 bool mnemonicFound = false;
16
17 for (int pos = 0; pos < in.length();) {
18 QChar ch = in[pos];
19 if (ch == src) {
20 if (pos == in.length() - 1) {
21 // 'src' at the end of string, skip it
22 ++pos;
23 } else {
24 if (in[pos + 1] == src) {
25 // A real 'src'
26 out += src;
27 pos += 2;
28 } else if (!mnemonicFound) {
29 // We found the mnemonic
30 mnemonicFound = true;
31 out += dst;
32 ++pos;
33 } else {
34 // We already have a mnemonic, just skip the char
35 ++pos;
36 }
37 }
38 } else if (ch == dst) {
39 // Escape 'dst'
40 out += dst;
41 out += dst;
42 ++pos;
43 } else {
44 out += ch;
45 ++pos;
46 }
47 }
48
49 return out;
50}
qsizetype length() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:01:46 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.