• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.12
  • kdelibs
  • kdecore
  • localization
common_helpers.cpp
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2008 Chusslove Illich <caslav.ilic@gmx.net>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #include <common_helpers_p.h>
21 
22 // If pos points to alphanumeric X in "...(X)...", which is preceded or
23 // followed only by non-alphanumerics, then "(X)" gets removed.
24 static QString removeReducedCJKAccMark (const QString &label, int pos)
25 {
26  if ( pos > 0 && pos + 1 < label.length()
27  && label[pos - 1] == QLatin1Char('(') && label[pos + 1] == QLatin1Char(')')
28  && label[pos].isLetterOrNumber())
29  {
30  // Check if at start or end, ignoring non-alphanumerics.
31  int len = label.length();
32  int p1 = pos - 2;
33  while (p1 >= 0 && !label[p1].isLetterOrNumber()) {
34  --p1;
35  }
36  ++p1;
37  int p2 = pos + 2;
38  while (p2 < len && !label[p2].isLetterOrNumber()) {
39  ++p2;
40  }
41  --p2;
42 
43  if (p1 == 0) {
44  return label.left(pos - 1) + label.mid(p2 + 1);
45  } else if (p2 + 1 == len) {
46  return label.left(p1) + label.mid(pos + 2);
47  }
48  }
49  return label;
50 }
51 
52 QString removeAcceleratorMarker (const QString &label_)
53 {
54  QString label = label_;
55 
56  int p = 0;
57  bool accmarkRemoved = false;
58  while (true) {
59  p = label.indexOf(QLatin1Char('&'), p);
60  if (p < 0 || p + 1 == label.length()) {
61  break;
62  }
63 
64  if (label[p + 1].isLetterOrNumber()) {
65  // Valid accelerator.
66  label = label.left(p) + label.mid(p + 1);
67 
68  // May have been an accelerator in CJK-style "(&X)"
69  // at the start or end of text.
70  label = removeReducedCJKAccMark(label, p);
71 
72  accmarkRemoved = true;
73  } else if (label[p + 1] == QLatin1Char('&')) {
74  // Escaped accelerator marker.
75  label = label.left(p) + label.mid(p + 1);
76  }
77 
78  ++p;
79  }
80 
81  // If no marker was removed, and there are CJK characters in the label,
82  // also try to remove reduced CJK marker -- something may have removed
83  // ampersand beforehand.
84  if (!accmarkRemoved) {
85  bool hasCJK = false;
86  foreach (const QChar &c, label) {
87  if (c.unicode() >= 0x2e00) { // rough, but should be sufficient
88  hasCJK = true;
89  break;
90  }
91  }
92  if (hasCJK) {
93  p = 0;
94  while (true) {
95  p = label.indexOf(QLatin1Char('('), p);
96  if (p < 0) {
97  break;
98  }
99  label = removeReducedCJKAccMark(label, p + 1);
100  ++p;
101  }
102  }
103  }
104 
105  return label;
106 }
QString
removeAcceleratorMarker
QString removeAcceleratorMarker(const QString &label_)
Definition: common_helpers.cpp:52
common_helpers_p.h
removeReducedCJKAccMark
static QString removeReducedCJKAccMark(const QString &label, int pos)
Definition: common_helpers.cpp:24
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:47:07 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal