midrange.com code scratchpad
Name:
To mixed case
Scriptlanguage:
Plain Text
Tabwidth:
4
Date:
06/30/2008 10:28:56 pm
IP:
Logged
Description:
Convert code to first character upper casing for individual tokens
Code:
  1. --- Came wiffling through the eclipsey wood ---
  2. /*
  3.  * Menu: RPG > ToMixedCase    
  4.  * Kudos: Matt Tyler via Joe Pluta
  5.  * License: EPL 1.0
  6.  * DOM: http://download.eclipse.org/technology/das\
  7. h/update/org.eclipse.eclipsemonkey.lang.javascript
  8.  */ 
  9.  
  10. function main() {
  11.     function popup(title, msg) {
  12.         Packages.org.eclipse.jface.dialogs.MessageDia\
  13. log.openInformation(            
  14.                  window.getShell(), title, msg
  15.         );
  16.     }
  17.     String.prototype.toMixedCase = function()
  18.     {
  19.        function toUpper(sChar){ return sChar.toUpperC\
  20. ase(sChar); }
  21.        return this.toLowerCase().replace(/\b([A-Za-z]\
  22. )/g,toUpper);
  23.     }
  24.  
  25.     var editor = editors.activeEditor;
  26. //    popup('The value of getId()',editor.Id);    
  27.     var range = editor.selectionRange;
  28.     var offset = range.startingOffset;
  29.     var offset2 = range.endingOffset;
  30.     var result = editor.source.substring(offset, offs\
  31. et2).toMixedCase();
  32.     editor.beginCompoundChange();    
  33.     editor.applyEdit(offset, range.endingOffset - off\
  34. set, result);
  35.     editor.endCompoundChange();
  36. }
  37.  
  38. --- And burbled as it ran! ---
  39.  
© 2004-2019 by midrange.com generated in 0.006s valid xhtml & css