mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-10 17:55:39 +02:00
C/C++ search for operators, bug 295150.
This commit is contained in:
parent
d8117374fc
commit
1cf5491c65
3 changed files with 57 additions and 3 deletions
|
@ -57,6 +57,7 @@ import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
import org.eclipse.cdt.core.model.ICElement;
|
import org.eclipse.cdt.core.model.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
|
import org.eclipse.cdt.core.parser.Keywords;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
import org.eclipse.cdt.internal.ui.ICHelpContextIds;
|
||||||
|
@ -344,15 +345,37 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
|
||||||
patternCombo = new Combo( result, SWT.SINGLE | SWT.BORDER );
|
patternCombo = new Combo( result, SWT.SINGLE | SWT.BORDER );
|
||||||
patternCombo.addVerifyListener(new VerifyListener() {
|
patternCombo.addVerifyListener(new VerifyListener() {
|
||||||
public void verifyText(VerifyEvent e) {
|
public void verifyText(VerifyEvent e) {
|
||||||
|
final String text = patternCombo.getText();
|
||||||
|
boolean relax= text.contains(Keywords.OPERATOR + " "); //$NON-NLS-1$
|
||||||
char[] chars= e.text.toCharArray();
|
char[] chars= e.text.toCharArray();
|
||||||
StringBuilder result= new StringBuilder(chars.length);
|
StringBuilder result= new StringBuilder(chars.length);
|
||||||
for (char c : chars) {
|
for (int i = 0; i < chars.length; i++) {
|
||||||
|
final char c = chars[i];
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case '_':
|
case '_':
|
||||||
case ':': // scope operator
|
case ':': // scope operator
|
||||||
case '?': case '*': // wild cards
|
case '?': case '*': // wild cards
|
||||||
|
case '\\': // escaping wild-cards
|
||||||
result.append(c);
|
result.append(c);
|
||||||
break;
|
break;
|
||||||
|
case ' ':
|
||||||
|
if (prefix(text, e, e.start+i).endsWith(Keywords.OPERATOR)) {
|
||||||
|
relax= true;
|
||||||
|
result.append(c);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case '&': case '|': case '+': case '-':
|
||||||
|
case '!': case '=': case '>': case '<':
|
||||||
|
case '%': case '^': case '(': case ')':
|
||||||
|
case '[': case ']':
|
||||||
|
if (prefix(text, e, e.start+i).endsWith(Keywords.OPERATOR)) {
|
||||||
|
result.append(' ');
|
||||||
|
relax= true;
|
||||||
|
}
|
||||||
|
if (relax)
|
||||||
|
result.append(c);
|
||||||
|
break;
|
||||||
|
case '~':
|
||||||
default:
|
default:
|
||||||
if (Character.isLetterOrDigit(c)) {
|
if (Character.isLetterOrDigit(c)) {
|
||||||
result.append(c);
|
result.append(c);
|
||||||
|
@ -362,6 +385,13 @@ public class PDOMSearchPage extends DialogPage implements ISearchPage {
|
||||||
e.text= result.toString();
|
e.text= result.toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String prefix(String text, VerifyEvent e, int length) {
|
||||||
|
StringBuilder result= new StringBuilder(length);
|
||||||
|
result.append(text, 0, e.start);
|
||||||
|
result.append(e.text, 0, length-e.start);
|
||||||
|
return result.toString();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
patternCombo.addModifyListener( new ModifyListener() {
|
patternCombo.addModifyListener( new ModifyListener() {
|
||||||
|
|
|
@ -23,6 +23,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
import org.eclipse.core.runtime.IStatus;
|
||||||
import org.eclipse.core.runtime.OperationCanceledException;
|
import org.eclipse.core.runtime.OperationCanceledException;
|
||||||
import org.eclipse.core.runtime.Status;
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.osgi.util.NLS;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.dom.ast.DOMException;
|
import org.eclipse.cdt.core.dom.ast.DOMException;
|
||||||
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
import org.eclipse.cdt.core.dom.ast.ICompositeType;
|
||||||
|
@ -89,6 +90,22 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
char c = patternStr.charAt(i);
|
char c = patternStr.charAt(i);
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
case '\\':
|
||||||
|
if (i+1 < n) {
|
||||||
|
switch(patternStr.charAt(i+1)) {
|
||||||
|
case '?':
|
||||||
|
buff.append("\\?"); //$NON-NLS-1$
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
buff.append("\\*"); //$NON-NLS-1$
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
buff.append('\\');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
buff.append('\\');
|
||||||
|
}
|
||||||
|
break;
|
||||||
case '*':
|
case '*':
|
||||||
buff.append(".*"); //$NON-NLS-1$
|
buff.append(".*"); //$NON-NLS-1$
|
||||||
break;
|
break;
|
||||||
|
@ -104,6 +121,9 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
buff = new StringBuffer();
|
buff = new StringBuffer();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case '|': case '+': case '^': case '(': case ')': case '[': case ']':
|
||||||
|
buff.append('\\').append(c);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
buff.append(c);
|
buff.append(c);
|
||||||
}
|
}
|
||||||
|
@ -186,7 +206,7 @@ public class PDOMSearchPatternQuery extends PDOMSearchQuery {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getResultLabel(int numMatches) {
|
public String getResultLabel(int numMatches) {
|
||||||
String patternInScope = CSearchMessages.bind(
|
String patternInScope = NLS.bind(
|
||||||
CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, patternStr, scopeDesc);
|
CSearchMessages.PDOMSearchPatternQuery_PatternQuery_labelPatternInScope, patternStr, scopeDesc);
|
||||||
return getResultLabel(patternInScope, numMatches);
|
return getResultLabel(patternInScope, numMatches);
|
||||||
}
|
}
|
||||||
|
|
|
@ -125,7 +125,7 @@ is to be searched:</p>
|
||||||
<tr>
|
<tr>
|
||||||
<td width="49%"> <samp>*</samp></td>
|
<td width="49%"> <samp>*</samp></td>
|
||||||
<td width="51%">Any string<p><b>Tip:<br>
|
<td width="51%">Any string<p><b>Tip:<br>
|
||||||
</b> Use the character <samp>*</samp> to search for
|
</b> Use the character sequence <samp>\*</samp> to search for
|
||||||
operators that begin with *. See syntax examples in the table below.</td>
|
operators that begin with *. See syntax examples in the table below.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -137,11 +137,13 @@ is to be searched:</p>
|
||||||
<td width="51%">Nested elements</td>
|
<td width="51%">Nested elements</td>
|
||||||
</tr>
|
</tr>
|
||||||
</table>
|
</table>
|
||||||
|
<!-- no support for function parameters
|
||||||
<p><b>Tip: </b>Do not use wild cards between the brackets of a function or
|
<p><b>Tip: </b>Do not use wild cards between the brackets of a function or
|
||||||
method pattern. For example, the search
|
method pattern. For example, the search
|
||||||
string <samp>f( * )</samp> is an invalid search that results in a search for any function <samp>f</samp>
|
string <samp>f( * )</samp> is an invalid search that results in a search for any function <samp>f</samp>
|
||||||
because
|
because
|
||||||
the asterisk is interpreted as a pointer rather than a wild card.</p>
|
the asterisk is interpreted as a pointer rather than a wild card.</p>
|
||||||
|
-->
|
||||||
<h2>Syntax examples</h2>
|
<h2>Syntax examples</h2>
|
||||||
<p>The table below provides syntax examples and an explanation for each example
|
<p>The table below provides syntax examples and an explanation for each example
|
||||||
to help you conduct an effective search.</p>
|
to help you conduct an effective search.</p>
|
||||||
|
@ -163,6 +165,7 @@ to help you conduct an effective search.</p>
|
||||||
<td width="64%" height="32"> <samp>::A</samp> </td>
|
<td width="64%" height="32"> <samp>::A</samp> </td>
|
||||||
<td width="36%" height="32">Searches for A not nested in anything</td>
|
<td width="36%" height="32">Searches for A not nested in anything</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<!-- no support for function parameters
|
||||||
<tr>
|
<tr>
|
||||||
<td width="64%" height="17"> <samp>*()</samp></td>
|
<td width="64%" height="17"> <samp>*()</samp></td>
|
||||||
<td width="36%" height="17">Any function taking no parameters</td>
|
<td width="36%" height="17">Any function taking no parameters</td>
|
||||||
|
@ -183,6 +186,7 @@ to help you conduct an effective search.</p>
|
||||||
<td width="36%" height="64">Will search for a function f, taking 2 parameters; one is a
|
<td width="36%" height="64">Will search for a function f, taking 2 parameters; one is a
|
||||||
const char array, the other is a reference to type A</td>
|
const char array, the other is a reference to type A</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
-->
|
||||||
<tr>
|
<tr>
|
||||||
<td width="64%" height="32"> <samp>operator \*</samp></td>
|
<td width="64%" height="32"> <samp>operator \*</samp></td>
|
||||||
<td width="36%" height="32">Finds only operator *</td>
|
<td width="36%" height="32">Finds only operator *</td>
|
||||||
|
|
Loading…
Add table
Reference in a new issue