2021-02-13 01:17:49 +00:00
|
|
|
|
using FastColoredTextBoxNS;
|
2020-11-28 08:15:13 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Data;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Text;
|
2021-02-13 01:17:49 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2020-11-28 08:15:13 +00:00
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
using WeifenLuo.WinFormsUI.Docking;
|
|
|
|
|
|
|
|
|
|
namespace 开发辅助工具.Tools
|
|
|
|
|
{
|
|
|
|
|
public partial class FrmStrToCode : DockContent
|
|
|
|
|
{
|
|
|
|
|
public FrmStrToCode()
|
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
2021-02-13 01:17:49 +00:00
|
|
|
|
fastColoredTextBox1.ReadOnly = true;
|
|
|
|
|
fastColoredTextBox1.ClearStylesBuffer();
|
|
|
|
|
fastColoredTextBox1.Range.ClearStyle(StyleIndex.All);
|
|
|
|
|
fastColoredTextBox1.AddStyle(new MarkerStyle(new SolidBrush(Color.FromArgb(40, Color.Gray))));
|
|
|
|
|
fastColoredTextBox1.AutoIndentNeeded -= fctb_AutoIndentNeeded;
|
|
|
|
|
fastColoredTextBox1.Language = Language.JSON;
|
|
|
|
|
fastColoredTextBox1.OnSyntaxHighlight(new TextChangedEventArgs(fastColoredTextBox1.Range));
|
|
|
|
|
}
|
|
|
|
|
private void fctb_AutoIndentNeeded(object sender, AutoIndentEventArgs args)
|
|
|
|
|
{
|
|
|
|
|
//block {}
|
|
|
|
|
if (Regex.IsMatch(args.LineText, @"^[^""']*\{.*\}[^""']*$"))
|
|
|
|
|
return;
|
|
|
|
|
//start of block {}
|
|
|
|
|
if (Regex.IsMatch(args.LineText, @"^[^""']*\{"))
|
|
|
|
|
{
|
|
|
|
|
args.ShiftNextLines = args.TabLength;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//end of block {}
|
|
|
|
|
if (Regex.IsMatch(args.LineText, @"}[^""']*$"))
|
|
|
|
|
{
|
|
|
|
|
args.Shift = -args.TabLength;
|
|
|
|
|
args.ShiftNextLines = -args.TabLength;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//label
|
|
|
|
|
if (Regex.IsMatch(args.LineText, @"^\s*\w+\s*:\s*($|//)") &&
|
|
|
|
|
!Regex.IsMatch(args.LineText, @"^\s*default\s*:"))
|
|
|
|
|
{
|
|
|
|
|
args.Shift = -args.TabLength;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//some statements: case, default
|
|
|
|
|
if (Regex.IsMatch(args.LineText, @"^\s*(case|default)\b.*:\s*($|//)"))
|
|
|
|
|
{
|
|
|
|
|
args.Shift = -args.TabLength / 2;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
//is unclosed operator in previous line ?
|
|
|
|
|
if (Regex.IsMatch(args.PrevLineText, @"^\s*(if|for|foreach|while|[\}\s]*else)\b[^{]*$"))
|
|
|
|
|
if (!Regex.IsMatch(args.PrevLineText, @"(;\s*$)|(;\s*//)"))//operator is unclosed
|
|
|
|
|
{
|
|
|
|
|
args.Shift = args.TabLength;
|
|
|
|
|
return;
|
|
|
|
|
}
|
2020-11-28 08:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
private void Convert()
|
|
|
|
|
{
|
|
|
|
|
StringBuilder builder = new StringBuilder();
|
|
|
|
|
if (RbStrToC.Checked)
|
|
|
|
|
{
|
|
|
|
|
builder.Append(" StringBuilder sb = new StringBuilder();\r\n");
|
|
|
|
|
builder.Append(" sb.Append(\"" + TxtFromCode.Text.Trim().Replace("\"", "\\\"").Replace("\r\n", "\n").Replace("\n", "\");\r\n sb.Append(\"") + "\");");
|
2021-02-13 01:17:49 +00:00
|
|
|
|
fastColoredTextBox1.Language = FastColoredTextBoxNS.Language.CSharp;
|
2020-11-28 08:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
else if (RbStrToJS.Checked)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("var sb=\"" + this.TxtFromCode.Text.Trim().Replace("\"", "\\\"").Replace("\r\n", "\n").Replace("\n", "\";\r\n sb=sb+\"") + "\";");
|
2021-02-13 01:17:49 +00:00
|
|
|
|
fastColoredTextBox1.Language = FastColoredTextBoxNS.Language.JS;
|
2020-11-28 08:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
else if (RbStrToQuickJS.Checked)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("var sb=\"" + this.TxtFromCode.Text.Trim().Replace("\"", "\\\"").Replace("\r\n", "\n").Replace("\n", "\";\r\n sb=sb+\"") + "\";");
|
|
|
|
|
builder = new StringBuilder(builder.ToString().Replace("script", "scr\"+\"ipt") + " document.write(sb);");
|
|
|
|
|
builder.Insert(0, "<script>\r\n");
|
|
|
|
|
builder.Append ("\r\n</script>");
|
2021-02-13 01:17:49 +00:00
|
|
|
|
fastColoredTextBox1.Language = FastColoredTextBoxNS.Language.HTML;
|
2020-11-28 08:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
else if (RbStrToASP.Checked)
|
|
|
|
|
{
|
|
|
|
|
builder.Append("sb=\"" + this.TxtFromCode.Text.Trim().Replace("\"", "\"\"").Replace("\r\n", "\n").Replace("\n", "\" & vbCrLf \r\nsb=sb & \"") + "\"");
|
2021-02-13 01:17:49 +00:00
|
|
|
|
fastColoredTextBox1.Language = FastColoredTextBoxNS.Language.VB;
|
2020-11-28 08:15:13 +00:00
|
|
|
|
}
|
2021-02-13 01:17:49 +00:00
|
|
|
|
fastColoredTextBox1.Text = builder.ToString();
|
2020-11-28 08:15:13 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RbStrToC_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Convert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RbStrToJS_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Convert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void RbStrToQuickJS_CheckedChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Convert();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TxtFromCode_DoubleClick(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
ryControls.Controls.RichTextBox2 txt = (ryControls.Controls.RichTextBox2)sender;
|
|
|
|
|
开发辅助工具.Controls.FrmText frm = new Controls.FrmText
|
|
|
|
|
{
|
|
|
|
|
Icon = Icon
|
|
|
|
|
};
|
|
|
|
|
frm.richTextBox1.Text = txt.Text;
|
|
|
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
txt.Text = frm.richTextBox1.Text;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void TxtFromCode_TextChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
Convert();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|