using System; using System.Text.RegularExpressions; using System.Threading; using System.Windows.Forms; namespace LrcTool { public partial class LrcPreProcessPage : UserControl { public LrcPreProcessPage() { InitializeComponent(); } private void PasteButton_Click(object sender, EventArgs e) { LeftRichTextBox.Text = Clipboard.GetText(); } private delegate void Action(); private void FireButton_Click(object sender, EventArgs e) { var lrc = LeftRichTextBox.Text; var shouldFixFloatPoint = Fixed2CheckBox.Checked; var shouldRemoveBlankLines = RemoveBlankLinesCheckBox.Checked; var shouldRemoveBrackets = RemoveBracketsCheckBox.Checked; var shouldChangeFullWidthSpaceToHalfWide = FullWidthSpaceToHalfWideCheckBox.Checked; FireButton.Enabled = false; new Thread(() => { try { if (shouldFixFloatPoint) { lrc = Regex.Replace(lrc, @"(\[\d\d\:\d\d.\d\d)\d(\])", @"$1$2"); lrc = Regex.Replace(lrc, @"(\[\d\d\:\d\d.\d)(\])", @"${1}0$2"); } if (shouldRemoveBlankLines) { lrc = string.Join(Environment.NewLine, Regex.Replace(lrc, @"^\[\d\d\:\d\d.\d\d\]\s*$", "", RegexOptions.Multiline) .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) ); } if (shouldRemoveBrackets) { lrc = string.Join(Environment.NewLine, Regex.Replace(lrc, @"[(\(]\p{IsHiragana}+?[\))]", "") .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries) ); } if (shouldChangeFullWidthSpaceToHalfWide) { lrc = lrc.Replace(" ", " "); } Invoke(new Action(() => RightRichTextBox.Text = lrc)); } catch (Exception exception) { MessageBox.Show(exception.ToString()); } Invoke(new Action(() => FireButton.Enabled = true)); }).Start(); } } }