LrcPreProcessPage.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.Threading;
  4. using System.Windows.Forms;
  5. namespace LrcTool
  6. {
  7. public partial class LrcPreProcessPage : UserControl
  8. {
  9. public LrcPreProcessPage()
  10. {
  11. InitializeComponent();
  12. }
  13. private void PasteButton_Click(object sender, EventArgs e)
  14. {
  15. LeftRichTextBox.Text = Clipboard.GetText();
  16. }
  17. private delegate void Action();
  18. private void FireButton_Click(object sender, EventArgs e)
  19. {
  20. var lrc = LeftRichTextBox.Text;
  21. var shouldFixFloatPoint = Fixed2CheckBox.Checked;
  22. var shouldRemoveBlankLines = RemoveBlankLinesCheckBox.Checked;
  23. var shouldRemoveBrackets = RemoveBracketsCheckBox.Checked;
  24. var shouldChangeFullWidthSpaceToHalfWide = FullWidthSpaceToHalfWideCheckBox.Checked;
  25. FireButton.Enabled = false;
  26. new Thread(() =>
  27. {
  28. try
  29. {
  30. if (shouldFixFloatPoint)
  31. {
  32. lrc = Regex.Replace(lrc, @"(\[\d\d\:\d\d.\d\d)\d(\])", @"$1$2");
  33. lrc = Regex.Replace(lrc, @"(\[\d\d\:\d\d.\d)(\])", @"${1}0$2");
  34. }
  35. if (shouldRemoveBlankLines)
  36. {
  37. lrc = string.Join(Environment.NewLine,
  38. Regex.Replace(lrc, @"^\[\d\d\:\d\d.\d\d\]\s*$", "", RegexOptions.Multiline)
  39. .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
  40. );
  41. }
  42. if (shouldRemoveBrackets)
  43. {
  44. lrc = string.Join(Environment.NewLine,
  45. Regex.Replace(lrc, @"[(\(]\p{IsHiragana}+?[\))]", "")
  46. .Split(new[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries)
  47. );
  48. }
  49. if (shouldChangeFullWidthSpaceToHalfWide)
  50. {
  51. lrc = lrc.Replace(" ", " ");
  52. }
  53. Invoke(new Action(() => RightRichTextBox.Text = lrc));
  54. }
  55. catch (Exception exception)
  56. {
  57. MessageBox.Show(exception.ToString());
  58. }
  59. Invoke(new Action(() => FireButton.Enabled = true));
  60. }).Start();
  61. }
  62. }
  63. }