home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 67 / IOPROG_67A.ISO / soft / Tools / mwsppv4.exe / TOGGLECASE.SCRIPT < prev    next >
Encoding:
Text File  |  2001-10-01  |  1.5 KB  |  70 lines

  1. !!Script
  2.  
  3. /**
  4. @Tool: toggleCase~changes the case of each character in the selection.
  5. @EndTool: 
  6. @Summary: toggleCase~changes the case of each character  
  7. */
  8.  
  9. var gOutput = getOutput("Results");
  10.  
  11. function DoCommand()
  12. {
  13.     var editor = getActiveEditor();
  14.     if (editor)
  15.     {
  16.         var selection = editor.getSelection();
  17.         var lineIndex = selection.startLineIndex;
  18.         var charIndex = selection.startCharIndex;
  19.         
  20.         while( lineIndex <= selection.endLineIndex ) {
  21.             // Get character at the current offset
  22.             var oldChar = editor.copy(
  23.                 lineIndex
  24.                 , charIndex
  25.                 , lineIndex
  26.                 , charIndex + 1
  27.                 );
  28.             
  29.             var newChar = oldChar;
  30.             
  31.             if (oldChar) {
  32.                 /*
  33.                 gOutput.writeLine( 
  34.                 "char: " 
  35.                 + oldChar 
  36.                 + " line: " 
  37.                 + lineIndex 
  38.                 + " char: " 
  39.                 + charIndex 
  40.                 + " oldchar.toUpper: " 
  41.                 + oldChar.toUpperCase()
  42.                 + " nexText char: " 
  43.                 + newChar
  44.                 );
  45.                 */
  46.                 if( oldChar.toUpperCase() == newChar ) {
  47.                     //gOutput.writeLine( "convert to lower case" );
  48.                     editor.replace(newChar.toLowerCase(), lineIndex, charIndex, 
  49.                         lineIndex, charIndex+1 );
  50.                 } else {
  51.                     //gOutput.writeLine( "convert to upper case" );
  52.                     editor.replace(newChar.toUpperCase(), lineIndex, charIndex, 
  53.                         lineIndex, charIndex+1 );
  54.                 }
  55.                 
  56.                 charIndex += 1;
  57.             } else {
  58.                 lineIndex += 1;
  59.                 charIndex = 0;
  60.             }
  61.         }
  62.         
  63.         editor.select(selection); 
  64.         
  65.         editor.setActive("Toggle Case");
  66.     }
  67. }
  68.  
  69. !!/Script
  70.