From e252be5dd53c7e12d31381c8144ff4d6b602f490 Mon Sep 17 00:00:00 2001 From: Nathan Ridge Date: Mon, 12 Dec 2016 05:18:07 -0500 Subject: [PATCH] Bug 495098 - Avoid & character in function signature being treated as SWT mnemonic In an SWT label, '&' characters are treated as mnemonics. Some labels can contain this character as their content (e.g. if they represent the signature of a function with arguments of C++ reference type), so they need to be escaped. Change-Id: I8ca57308f5dc3fa06648ce7f76df003e76fac3b6 --- .../cdt/internal/core/util/TextUtil.java | 17 +++++++++++++++++ .../internal/ui/callhierarchy/CHViewPart.java | 9 +++++++++ 2 files changed, 26 insertions(+) diff --git a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/TextUtil.java b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/TextUtil.java index b2922223ec3..51d51304364 100644 --- a/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/TextUtil.java +++ b/core/org.eclipse.cdt.core/model/org/eclipse/cdt/internal/core/util/TextUtil.java @@ -110,4 +110,21 @@ public class TextUtil { } return -1; } + + /** + * Returns an escaped version of the string 'input' where instances of the + * character 'specialChar' are escaped by replacing them with a two instances + * of 'specialChar'. + */ + public static String escape(String input, char specialChar) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < input.length(); i++) { + char ch = input.charAt(i); + if (ch == specialChar) { + builder.append(specialChar); + } + builder.append(ch); + } + return builder.toString(); + } } diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java index 88ffa8c4caf..492821502a5 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/callhierarchy/CHViewPart.java @@ -76,6 +76,8 @@ import org.eclipse.cdt.ui.actions.CdtActionConstants; import org.eclipse.cdt.ui.actions.OpenViewActionGroup; import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup; +import org.eclipse.cdt.internal.core.util.TextUtil; + import org.eclipse.cdt.internal.ui.CPluginImages; import org.eclipse.cdt.internal.ui.ICHelpContextIds; import org.eclipse.cdt.internal.ui.IContextMenuConstants; @@ -727,6 +729,13 @@ public class CHViewPart extends ViewPart { message= Messages.format(format, label, scope); } } + + // Escape '&' characters in the message, otherwise SWT interprets them + // as mnemonics. '&' characters can appear in the label of a CElement + // if the CElement represents a function with arguments of C++ + // reference type. + message = TextUtil.escape(message, '&'); + setContentDescription(message); }