PageRenderTime 127ms CodeModel.GetById 124ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/jEdit/tags/jedit-4-2-pre14/macros/Editing/Keywords_to_Upper_Case.bsh

#
Unknown | 55 lines | 48 code | 7 blank | 0 comment | 0 complexity | ab5f021ddd9e01c9d3ec93a2d2bec737 MD5 | raw file
 1/**
 2 * Converts keyword token types to upper case.
 3 */
 4void keywords2upper(View view)
 5{
 6	// declarations run faster than doing Token.KEYWORDx comparison
 7	byte KEYWORD1 = Token.KEYWORD1;
 8	byte KEYWORD4 = Token.KEYWORD4;
 9	Buffer buffer = view.getBuffer();
10	JEditTextArea textArea = view.getTextArea();
11	Token token = null;
12
13	//long t1 = System.currentTimeMillis();
14
15	try
16	{
17		buffer.beginCompoundEdit();
18		Selection[] selection = textArea.getSelection();
19		Buffer.TokenList info = null;
20		int pos = 0;
21		int lineStart = 0;
22
23		for(int line = 0; line < textArea.getLineCount(); ++line)
24		{
25			info = buffer.markTokens(line);
26			token = info.getFirstToken();
27			lineStart = buffer.getLineStartOffset(line);
28			pos = lineStart;
29			while(token != null)
30			{
31				if(KEYWORD1 <= token.id && token.id <= KEYWORD4)
32				{
33					String word = buffer.getText(pos,token.length);
34					buffer.remove(pos,token.length);
35					buffer.insert(pos,word.toUpperCase());
36				}
37				pos += token.length;
38				token = token.next;
39			}
40		}
41		view.getTextArea().setSelection(selection);
42	}
43	finally
44	{
45		buffer.endCompoundEdit();
46	}
47
48	//long t2 = System.currentTimeMillis();
49	//print("elapsed: " + (t2-t1));
50
51	view.getStatus().setMessageAndClear("Converted Keywords to Upper Case");
52}
53
54keywords2upper(view);
55