Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* See: http://r0b0tz.com/2011/11/flashdevelop-script-for-codeformatter-fixes/ */
- using System;
- using System.Text.RegularExpressions;
- using System.Windows.Forms;
- using PluginCore;
- public class FDScript
- {
- /**
- * Fixes CodeFormatter issues
- * @author http://lawrencealan.com
- */
- public static void Execute()
- {
- try
- {
- ScintillaNet.ScintillaControl sci = PluginBase.MainForm.CurrentDocument.SciControl;
- int pos = sci.CurrentPos;
- int line = sci.LineFromPosition(pos);
- if (sci == null) return; // document not editable
- string src = sci.Text;
- // fix single line statements
- string matchpattern = @"(?<!.*//.*)(\s+)?(for|if|while)\s+([^{\n]*)(?<!{)\n\s+";
- string replacementpattern = @"$1$2 $3 ";
- src = Regex.Replace(src, matchpattern, replacementpattern, RegexOptions.IgnoreCase);
- // fix lack of space between "){"
- matchpattern = @"(for|if|while)\s+([^{]*)\{";
- replacementpattern = @"$1 $2 {";
- src = Regex.Replace(src, matchpattern, replacementpattern, RegexOptions.IgnoreCase & RegexOptions.Multiline );
- sci.Text = src;
- sci.GotoLine(line);
- sci.GotoPos(pos);
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.ToString());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment