From 277339421d69c0dfec6dcec077bf421cc2d5316e Mon Sep 17 00:00:00 2001 From: kasthack Date: Wed, 30 Apr 2014 18:17:20 +0400 Subject: [PATCH] Cleanup --- {regexer => source}/Form1.Designer.cs | 0 source/Form1.cs | 91 ++++++++++++++++++ {regexer => source}/Form1.resx | 0 {regexer => source}/Program.cs | 0 .../Properties/AssemblyInfo.cs | 0 .../Properties/Resources.Designer.cs | 0 {regexer => source}/Properties/Resources.resx | 0 .../Properties/Settings.Designer.cs | 0 .../Properties/Settings.settings | 0 {regexer => source}/i.ico | Bin {regexer => source}/regexer.csproj | 0 11 files changed, 91 insertions(+) rename {regexer => source}/Form1.Designer.cs (100%) create mode 100644 source/Form1.cs rename {regexer => source}/Form1.resx (100%) rename {regexer => source}/Program.cs (100%) rename {regexer => source}/Properties/AssemblyInfo.cs (100%) rename {regexer => source}/Properties/Resources.Designer.cs (100%) rename {regexer => source}/Properties/Resources.resx (100%) rename {regexer => source}/Properties/Settings.Designer.cs (100%) rename {regexer => source}/Properties/Settings.settings (100%) rename {regexer => source}/i.ico (100%) rename {regexer => source}/regexer.csproj (100%) diff --git a/regexer/Form1.Designer.cs b/source/Form1.Designer.cs similarity index 100% rename from regexer/Form1.Designer.cs rename to source/Form1.Designer.cs diff --git a/source/Form1.cs b/source/Form1.cs new file mode 100644 index 0000000..bfaad8b --- /dev/null +++ b/source/Form1.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text.RegularExpressions; +using System.Windows.Forms; +namespace regexer { + public partial class Form1 : Form { + private Regex _r; + public Form1() { this.InitializeComponent(); } + + private bool CreateRegex( bool msg ) { + try { + var s = this.txt_regex.Text; + if ( string.IsNullOrWhiteSpace( s ) ) + return false; + this._r = new Regex( s ); + return true; + } + catch { + if ( msg ) MessageBox.Show( @"Wrong regex" ); + return false; + } + } + + private void update_input_box( IEnumerable v1 ) { + try { + this.ResumeLayout(); + this.txt_in.SuspendLayout(); + int selPos = this.txt_in.SelectionStart, sellen = this.txt_in.SelectionLength; + this.txt_in.SuspendLayout(); + this.txt_in.SelectAll(); + this.txt_in.SelectionBackColor = Color.White; + foreach ( var keyWordMatch in v1 ) { + this.txt_in.Select( keyWordMatch.Index, keyWordMatch.Length ); + this.txt_in.SelectionBackColor = Color.Yellow; + } + this.txt_in.SelectionStart = selPos; + this.txt_in.SelectionLength = sellen; + this.txt_in.ResumeLayout(); + } + finally { + Application.DoEvents(); + this.ResumeLayout(); + this.txt_in.ResumeLayout(); + } + } + + private void update_output( IEnumerable v1 ) { + var f = this.txt_replace_what.Text; + var t = this.txt_replace_with.Text; + var v = this.rd_match.Checked ? v1.Select( a => a.ToString() ).ToArray() : ( this.txt_in.Lines ).ToArray().Where( a => this._r.Match( a ).Index > 0 ).ToArray(); + if ( !String.IsNullOrEmpty( f ) ) + v = v.Select( a => a.Replace( f, t ) ).ToArray(); + this.txt_out.Lines = v.ToArray(); + } + + private void auto_up() { + if ( this.chk_onthefly.Checked ) + if ( this.CreateRegex( false ) ) + this.update_results(); + } + + private void update_results() { + try { + var v1 = ( from Match m in this._r.Matches( this.txt_in.Text ) select m ).ToArray(); + this.update_output( v1 ); + this.update_input_box( v1 ); + } + catch {} + } + + private void btn_go_Click( object sender, EventArgs e ) { + if ( this.CreateRegex( true ) ) { + this.txt_regex.Items.Insert( 0, this.txt_regex.Text ); + this.update_results(); + } + } + + private void txt_regex_TextChanged( object sender, EventArgs e ) { this.auto_up(); } + private void txt_in_TextChanged( object sender, EventArgs e ) { this.auto_up(); } + + private void rd_match_CheckedChanged( object sender, EventArgs e ) { this.auto_up(); } + + private void rd_grep_CheckedChanged( object sender, EventArgs e ) { this.auto_up(); } + + private void txt_replace_what_TextChanged( object sender, EventArgs e ) { this.auto_up(); } + + private void txt_replace_with_TextChanged( object sender, EventArgs e ) { this.auto_up(); } + } +} \ No newline at end of file diff --git a/regexer/Form1.resx b/source/Form1.resx similarity index 100% rename from regexer/Form1.resx rename to source/Form1.resx diff --git a/regexer/Program.cs b/source/Program.cs similarity index 100% rename from regexer/Program.cs rename to source/Program.cs diff --git a/regexer/Properties/AssemblyInfo.cs b/source/Properties/AssemblyInfo.cs similarity index 100% rename from regexer/Properties/AssemblyInfo.cs rename to source/Properties/AssemblyInfo.cs diff --git a/regexer/Properties/Resources.Designer.cs b/source/Properties/Resources.Designer.cs similarity index 100% rename from regexer/Properties/Resources.Designer.cs rename to source/Properties/Resources.Designer.cs diff --git a/regexer/Properties/Resources.resx b/source/Properties/Resources.resx similarity index 100% rename from regexer/Properties/Resources.resx rename to source/Properties/Resources.resx diff --git a/regexer/Properties/Settings.Designer.cs b/source/Properties/Settings.Designer.cs similarity index 100% rename from regexer/Properties/Settings.Designer.cs rename to source/Properties/Settings.Designer.cs diff --git a/regexer/Properties/Settings.settings b/source/Properties/Settings.settings similarity index 100% rename from regexer/Properties/Settings.settings rename to source/Properties/Settings.settings diff --git a/regexer/i.ico b/source/i.ico similarity index 100% rename from regexer/i.ico rename to source/i.ico diff --git a/regexer/regexer.csproj b/source/regexer.csproj similarity index 100% rename from regexer/regexer.csproj rename to source/regexer.csproj