PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms 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
Possible License(s): BSD-3-Clause, AGPL-1.0, Apache-2.0, LGPL-2.0, LGPL-3.0, GPL-2.0, CC-BY-SA-3.0, LGPL-2.1, GPL-3.0, MPL-2.0-no-copyleft-exception, IPL-1.0
  1. /**
  2. * Converts keyword token types to upper case.
  3. */
  4. void 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. //long t1 = System.currentTimeMillis();
  13. try
  14. {
  15. buffer.beginCompoundEdit();
  16. Selection[] selection = textArea.getSelection();
  17. Buffer.TokenList info = null;
  18. int pos = 0;
  19. int lineStart = 0;
  20. for(int line = 0; line < textArea.getLineCount(); ++line)
  21. {
  22. info = buffer.markTokens(line);
  23. token = info.getFirstToken();
  24. lineStart = buffer.getLineStartOffset(line);
  25. pos = lineStart;
  26. while(token != null)
  27. {
  28. if(KEYWORD1 <= token.id && token.id <= KEYWORD4)
  29. {
  30. String word = buffer.getText(pos,token.length);
  31. buffer.remove(pos,token.length);
  32. buffer.insert(pos,word.toUpperCase());
  33. }
  34. pos += token.length;
  35. token = token.next;
  36. }
  37. }
  38. view.getTextArea().setSelection(selection);
  39. }
  40. finally
  41. {
  42. buffer.endCompoundEdit();
  43. }
  44. //long t2 = System.currentTimeMillis();
  45. //print("elapsed: " + (t2-t1));
  46. view.getStatus().setMessageAndClear("Converted Keywords to Upper Case");
  47. }
  48. keywords2upper(view);