home *** CD-ROM | disk | FTP | other *** search
- !!Script
-
- /**
- @Tool: toggleCase~changes the case of each character in the selection.
- @EndTool:
- @Summary: toggleCase~changes the case of each character
- */
-
- var gOutput = getOutput("Results");
-
- function DoCommand()
- {
- var editor = getActiveEditor();
- if (editor)
- {
- var selection = editor.getSelection();
- var lineIndex = selection.startLineIndex;
- var charIndex = selection.startCharIndex;
-
- while( lineIndex <= selection.endLineIndex ) {
- // Get character at the current offset
- var oldChar = editor.copy(
- lineIndex
- , charIndex
- , lineIndex
- , charIndex + 1
- );
-
- var newChar = oldChar;
-
- if (oldChar) {
- /*
- gOutput.writeLine(
- "char: "
- + oldChar
- + " line: "
- + lineIndex
- + " char: "
- + charIndex
- + " oldchar.toUpper: "
- + oldChar.toUpperCase()
- + " nexText char: "
- + newChar
- );
- */
- if( oldChar.toUpperCase() == newChar ) {
- //gOutput.writeLine( "convert to lower case" );
- editor.replace(newChar.toLowerCase(), lineIndex, charIndex,
- lineIndex, charIndex+1 );
- } else {
- //gOutput.writeLine( "convert to upper case" );
- editor.replace(newChar.toUpperCase(), lineIndex, charIndex,
- lineIndex, charIndex+1 );
- }
-
- charIndex += 1;
- } else {
- lineIndex += 1;
- charIndex = 0;
- }
- }
-
- editor.select(selection);
-
- editor.setActive("Toggle Case");
- }
- }
-
- !!/Script
-