mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-04 23:05:47 +02:00
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
This commit is contained in:
parent
4e7f132020
commit
e252be5dd5
2 changed files with 26 additions and 0 deletions
|
@ -110,4 +110,21 @@ public class TextUtil {
|
||||||
}
|
}
|
||||||
return -1;
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,6 +76,8 @@ import org.eclipse.cdt.ui.actions.CdtActionConstants;
|
||||||
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
import org.eclipse.cdt.ui.actions.OpenViewActionGroup;
|
||||||
import org.eclipse.cdt.ui.refactoring.actions.CRefactoringActionGroup;
|
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.CPluginImages;
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
import org.eclipse.cdt.internal.ui.IContextMenuConstants;
|
||||||
|
@ -727,6 +729,13 @@ public class CHViewPart extends ViewPart {
|
||||||
message= Messages.format(format, label, scope);
|
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);
|
setContentDescription(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue