private void button3_Click(object sender, EventArgs e)
{
source.Text = Regex.Replace(source.Text, @"(
){2,}", "
");
source.Text = Regex.Replace(source.Text, @"\t", "");
source.Text = Regex.Replace(source.Text, @"\( ", "(");
source.Text = Regex.Replace(source.Text, @" \)", ")");
source.Text = Regex.Replace(source.Text, @"\[ ", "[");
source.Text = Regex.Replace(source.Text, @" \]", "]");
source.Text = Regex.Replace(source.Text, ", ", ",");
source.Text = Regex.Replace(source.Text, @" \+ ", @"+");
source.Text = Regex.Replace(source.Text, " - ", "-");
source.Text = Regex.Replace(source.Text, " = ", "=");
source.Text = Regex.Replace(source.Text, " == ", "=");
source.Text = Regex.Replace(source.Text, " != ", "!=");
source.Text = Regex.Replace(source.Text, @" \+= ", @"+=");
source.Text = Regex.Replace(source.Text, " -= ", "-=");
source.Text = Regex.Replace(source.Text, @" \+\+ ", @"++");
source.Text = Regex.Replace(source.Text, " < ", "<");
source.Text = Regex.Replace(source.Text, " > ", ">");
source.Text = Regex.Replace(source.Text, "; ", ";");
source.Text = Regex.Replace(source.Text, "for ", "for");
source.Text = Regex.Replace(source.Text, "if ", "if");
source.Text = Regex.Replace(source.Text, "\\s+\\n", "");
MessageBox.Show("Code Simplified Successfully!", "Success!");
}
}
}
private void beautify()
{
indentChar = '\t';
bool whiteSpace = false,
whiteSpacePrev = false,
newLine = false,
nextEndLine = false,
inForLoop = false;
int srcLen = ActiveEditor.Text.Length;
System.Text.StringBuilder dst = new System.Text.StringBuilder(srcLen + (srcLen >> 2));
string prevChar = String.Empty;
string escapedChar = String.Empty;
foreach (char ch in ActiveEditor.Text)
{
nextChar = ch.ToString();
if (escapedChar.Length > 0)
{
escapedChar += nextChar;
if ((escapedChar[0] == 'u' || escapedChar[0] == 'U'
&& escapedChar.Length < 5)
continue;
if (escapedChar.Length >= 3)
{
dst.Length--;
char escCh;
string escapedCharLower = escapedChar.ToLower();
try
{
if (escapedCharLower[0] == 'x' || escapedCharLower[0] == 'u'
{
escCh = (char)int.Parse(escapedCharLower.Substring(1), System.Globalization.NumberStyles.HexNumber);
}
else
{
int oct = (int.Parse(escapedCharLower[0].ToString()) << 6) + (int.Parse(escapedCharLower[1].ToString()) << 3) + int.Parse(escapedCharLower[2].ToString());
escCh = (char)((byte)oct);
}
if (escCh >= ' ' && escCh <= '~'
{
dst[dst.Length - 1] = escCh;
prevChar = escCh.ToString();
}
else
dst.Append(escapedChar);
}
catch
{
dst.Append(escapedChar);
}
escapedChar = String.Empty;
continue;
}
else
continue;
}
if (nextEndLine)
{
if (ch != ';'
dst.Append("
" + spaces(level));
nextEndLine = false;
}
whiteSpacePrev = whiteSpace;
whiteSpace = false;
if (prevChar == "\\" && inString != StringType.None)
{
if (ch == 'x' || ch == 'X' || ch == 'u' || ch == 'U' || (ch >= '0' && ch <= '9'
)
escapedChar = nextChar;
}
switch (ch)
{
case ' ':
case '\t':
case '\r':
case '\n':
if (!newLine)
whiteSpace = true;
nextChar = String.Empty;
break;
case '{':
if (inString == StringType.None)
{
removeWhitespaceAtEnd(dst);
newLine = true;
dst.Append("
" + spaces(level) + "{
");
nextChar = String.Empty;
dst.Append(spaces(++level));
}
break;
case '}':
if (inString == StringType.None)
{
newLine = true;
if (--level < 0)
{
dst.Append("
<<< Bogus level >>>
");
level = 0;
}
removeWhitespaceAtEnd(dst);
if (!endsWith(dst, "
"))
dst.Append("
");
dst.Append(spaces(level) + "}");
nextEndLine = true;
nextChar = String.Empty;
}
break;
case ';':
if (inString == StringType.None)
{
nextChar = String.Empty;
if (endsWith(dst, "
"))
dst.Length -= 2;
dst.Append(";");
if (!inForLoop)
dst.Append("
" + spaces(level));
newLine = true;
}
break;
case '\'':
if (inString != StringType.DoubleQuote &&
prevChar != "\\")
inString = (inString == StringType.None ? StringType.SingleQuote : StringType.None);
break;
case '\"':
if (inString != StringType.SingleQuote &&
prevChar != "\\")
inString = (inString == StringType.None ? StringType.DoubleQuote : StringType.None);
break;
case '(':
if (endsWith(dst, "for"))
inForLoop = true;
break;
case '
':
inForLoop = false;
break;
}
if (!whiteSpace)
{
prevChar = ch.ToString();
if (whiteSpacePrev)
{
if (!newLine)
dst.Append(" ");
whiteSpace = false;
}
if (nextChar != String.Empty)
{
dst.Append(nextChar);
newLine = false;
}
}
} // For loop
ActiveEditor.Text = dst.ToString();
MessageBox.Show("Code Beautified Successfully!", "Success!");
}
enum StringType
{
None,
SingleQuote,
DoubleQuote
}
string spaces(int level)
{
return new string(indentChar, level);
}
void removeWhitespaceAtEnd(System.Text.StringBuilder dst)
{
int x = dst.Length - 1;
while (dst[x] == ' ' || dst[x] == '\t'
--x;
dst.Length = x + 1;
}
bool endsWith(System.Text.StringBuilder dst, string check)
{
int x = dst.Length - check.Length,
y = 0;
while (dst[x] == check[y++])
{
++x;
if (y == check.Length)
break;
}
return x == dst.Length;
}
void*Optimise()
********{
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*{",*"{");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("{*",*"{");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*{*",*"{");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*(",*"(");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("(*",*"(");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*(*",*"(");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*=",*"=");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("=*",*"=");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*=*",*"=");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*;",*";");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace(";*",*";");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*;*",*";");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*\"",*"\"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*\"*",*"\"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("\"*",*"\"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*,",*",");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace(",*",*",");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*,*",*",");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*<",*"<");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("<*",*"<");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*<*",*"<");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*>",*">");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace(">*",*">");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*>*",*">");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*&&",*"&&");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("&&*",*"&&");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*&&*",*"&&");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*++",*"++");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("++*",*"++");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*++*",*"++");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*--",*"--");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("--*",*"--");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("*--*",*"--");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("****",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("********",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("****************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("********************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("************************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("****************************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("********************************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("************************************",*"");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("**",*"*");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("***",*"*");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace("****",*"*");
************textEditorControl1.Text*=*textEditorControl1.Text.Replace(Environment.NewLine,*"");
********}*
Copyright © 2026, NextGenUpdate.
All Rights Reserved.