Created
August 27, 2009 15:46
-
-
Save dtjohnso/176391 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
CmdUtils.CreateCommand({ | |
names: ["check parentheses"], | |
icon: "http://www.mozilla.com/favicon.ico", | |
description: "Does a simple arithmetic check to see if a selected line of code has enough parentheses.", | |
//help: "How to use your command.", | |
author: {name: "Duncan Johnson", email: "duncan@duncanandmeg.org"}, | |
license: "GPL", | |
homepage: "http://andyanglea.com/blog/2009/08/if-problems/", | |
arguments: [{role: 'object', nountype: noun_arb_text}], | |
preview: function preview(pblock, args) { | |
pblock.innerHTML = "Your input is <b>" + args.object.html + "</b>."; | |
}, | |
execute: function execute(args) { | |
var charArray = args.object.text.split(""); | |
var test1Integer = 0; | |
for (var item in charArray) { | |
if (charArray[item] == "(") { | |
test1Integer = test1Integer + 1; | |
} else if (charArray[item] == ")") { | |
test1Integer = test1Integer - 1; | |
} | |
} | |
if (test1Integer !== 0) { | |
displayMessage ("There is an error in the selected line"); | |
} else { displayMessage ("No error detected \(but you still might have bad code, this is no guarantee\)"); | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment