Let's say you start with all lowercase characters:
t e s t
t e s T
t e S t
t e S T
t E s t
...
T E S T
This is the same as the following pattern:0 0 0 0
0 0 0 1
0 0 1 0
0 0 1 1
0 1 0 0
...
1 1 1 1
Try to code something up.
Good luck.
Hi,
Code:
=====
Color color = new Color(Display.getCurrent(), 0, 0, 0);
IToken plainCode =new Token(new TextAttribute(color));
WordRule keywordsRule = new WordRule(new IWordDetector(){
public boolean isWordStart(char c) {
return Character.isLetterOrDigit(c) || Character.isJavaIdentifierStart(c);
}
public boolean isWordPart(char c) {
return (c == '.') || Character.isLetterOrDigit(c) || Character.isJavaIdentifierPart(c);
}
},plainCode);
String keyword = "Test";
keywordsRule.addWord(keyword,plainCode );
I am not able to highlight "TEST","TEst","test".It highlights only "Test".
So I planned to generate all mixed case of a word and store in a arraylist.
for (int j = 0; j < searchKeyword.size(); ++j) {
String keyword = (String)searchKeyword.get(j);
keywordsRule.addWord(keyword,plainCode );
}
Pls let me know how to handle in all cases.
Thanks in Advance.
Sarayu.
if your strings are all letters
Unpack String to char[] foo;
Observe that you can toggle case of a char with a single line
foo[j] = (char) (foo[j]^' ');
Use a loopless Gray code to identify the proper index to toggel on each pass.
Loopless Gray code is beautifully explained and only 4 steps long! Find it in the recently published:
Knuth- Art of Computer Programming Vol 4, Facicle 2, p10.
The advantage of this approach is that it is just about as fast as it is possible to do this task. The code is about as short as it is possible to write. It takes only 6 instructions to step to the next perumtation. One of those lines is the toggle line from above and another is the test to see if you are done. So really only 4 instructions to determine the toggle, before you are back to spewing out your next result. In Knuth's words, "blindly fast". Totally cool!
Furthermore, when you hand in this assignment, if that's what it is, your professor will admire the sheer beauty of the loopless Gray code, will be enormously pleased that you took the trouble to read Knuth, and will know for an absolute fact that you did not think of this all by yourself.
Dude 1
dude 2
dUde 3
DUde 4
DUDe 5
dUDe 6
duDe 7
DuDe 8
DuDE 9
duDE 10
dUDE 11
DUDE 12
DUdE 13
dUdE 14
dudE 15
DudE 16
Enjoy!
I don't quite fully understand this, but it appears you're doing syntax highlighting for Java? Java is case sensitive, so doing case insensitive matching may not be what you want. But, in case it is what you want, trying to generate all combinations is a lot of work. What you want is to effectively generate one canonical representation for all words. There are endless posibilities, but the two simplest are probably converting to all uppercase or all lowercase. You can do this using java.lang.Character.toUpperCase or toLowerCase before your comparison.
> Hi,
>
> Code:
> =====
> Color color = new Color(Display.getCurrent(), 0, 0,
> 0);
> IToken plainCode =new Token(new
> TextAttribute(color));
> WordRule keywordsRule = new WordRule(new
> IWordDetector(){
>
>
> public boolean isWordStart(char c) {
> return Character.isLetterOrDigit(c) ||
> Character.isJavaIdentifierStart(c);
> }
> public boolean isWordPart(char c) {
> return (c == '.') || Character.isLetterOrDigit(c) ||
> Character.isJavaIdentifierPart(c);
> }
>
> },plainCode);
>
> String keyword = "Test";
> keywordsRule.addWord(keyword,plainCode );
>
>
>
> I am not able to highlight "TEST","TEst","test".It
> highlights only "Test".
>
> So I planned to generate all mixed case of a word and
> store in a arraylist.
>
> for (int j = 0; j < searchKeyword.size(); ++j) {
> String keyword = (String)searchKeyword.get(j);
> keywordsRule.addWord(keyword,plainCode );
> }
>
> Pls let me know how to handle in all cases.
>
> Thanks in Advance.
>
> Sarayu.
Hi,
Thanks for ur help.
Yes I am doing syntax highlighting using org.eclipse.jface.text.rules.WordRule.
public void addWord(String word,
IToken token)
Adds a word and the token to be returned if it is detected.
Parameters:
word - the word this rule will search for, may not be null
token - the token to be returned if the word has been found, may not be null
In this case i am not able to use equalsIgnoreCase method.so explicity i am trying to generate different combinations of a word.
Thanks,
Sarayu.
public static void spewPermutations(String s){
// arrays for index focus calculations
int n = s.length();
int[] a = new int[n];
char[] foo = new char[n];
int[] f = new int[n+1];
int j;
// initialize
for(int i = 0; i<n; i++){
a[i] = 0;
f[i] = i;
foo[i] = s.charAt(i); // put input string into char array.
}
f[n] = n;
// un necessary stat variable to cout number of permutations generated.
int k = 0;
while(true){
// output print one result
for(int i = 0; i><n; i++){System.out.print (foo[i]);}
System.out.println(" " + ++k);
// compute next index
j = f[0];
f[0] = 0;
// exit when done
if(j==n)break;
// more index computation
f[j] = f[j+1];
f[j+1] = j+1;
// toggle at appropriate index
foo[j] = (char)(foo[j] ^ ' ');
}
}
public static void main(String args[]){
spewPermutations("Dude");
}
>