File indexing completed on 2025-01-12 03:40:51
0001 /* This file is part of the dbusmenu-qt library 0002 SPDX-FileCopyrightText: 2010 Canonical 0003 Author: Aurelien Gateau <aurelien.gateau@canonical.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 #include "utils_p.h" 0008 0009 // Qt 0010 #include <QString> 0011 0012 QString swapMnemonicChar(const QString &in, const QChar &src, const QChar &dst) 0013 { 0014 QString out; 0015 bool mnemonicFound = false; 0016 0017 for (int pos = 0; pos < in.length();) { 0018 QChar ch = in[pos]; 0019 if (ch == src) { 0020 if (pos == in.length() - 1) { 0021 // 'src' at the end of string, skip it 0022 ++pos; 0023 } else { 0024 if (in[pos + 1] == src) { 0025 // A real 'src' 0026 out += src; 0027 pos += 2; 0028 } else if (!mnemonicFound) { 0029 // We found the mnemonic 0030 mnemonicFound = true; 0031 out += dst; 0032 ++pos; 0033 } else { 0034 // We already have a mnemonic, just skip the char 0035 ++pos; 0036 } 0037 } 0038 } else if (ch == dst) { 0039 // Escape 'dst' 0040 out += dst; 0041 out += dst; 0042 ++pos; 0043 } else { 0044 out += ch; 0045 ++pos; 0046 } 0047 } 0048 0049 return out; 0050 }