Modified:
trunk/Structures/StringEx.cs
trunk/Structures/Structures.csproj
trunk/Theminds/App.cs
trunk/Theminds/Buffer.cs
trunk/Theminds/Filters/JoinPartQuit.cs
trunk/Theminds/Filters/Names.cs
trunk/Theminds/Filters/Privmsg.cs
trunk/Theminds/Filters/Who.cs
Log:
StringEx now uses C# 3.0 extension methods
Modified: trunk/Structures/StringEx.cs
==============================================================================
--- trunk/Structures/StringEx.cs (original)
+++ trunk/Structures/StringEx.cs Wed Aug 1 15:50:06 2007
@@ -2,7 +2,7 @@
namespace Aspirations {
public static class StringEx {
- public static int[] FindSpaces(string line, int times) {
+ public static int[] FindSpaces(this string line, int times) {
int[] spaces = new int[times];
int last = 0;
for (int i = 0; i < times; ++i) {
@@ -16,8 +16,7 @@
}
// "0123456789", 3, 7 => "3456" (`end`th character removed)
- public static string
- Tween(string haystack, int begin, int end) {
+ public static string Tween(this string haystack, int begin, int end) {
if (end < haystack.Length)
return haystack.Remove(end).Substring(begin);
else
@@ -25,7 +24,7 @@
}
// http://www.irchelp.org/irchelp/rfc/chapter1.html#c1_3
- public static bool IsChannel(string channel) {
+ public static bool IsChannel(this string channel) {
if (channel == null) return false;
if (channel.StartsWith("#")) return true;
if (channel.StartsWith("&")) return true;
Modified: trunk/Structures/Structures.csproj
==============================================================================
--- trunk/Structures/Structures.csproj (original)
+++ trunk/Structures/Structures.csproj Wed Aug 1 15:50:06 2007
@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
- <ProductVersion>8.0.50727</ProductVersion>
+ <ProductVersion>9.0.20706</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{33D6C14F-9C5C-4B5D-8D4C-0B1F75215A9E}</ProjectGuid>
<OutputType>Library</OutputType>
@@ -52,5 +52,8 @@
</ItemGroup>
<ItemGroup>
<Reference Include="System" />
+ <Reference Include="System.Core">
+ <RequiredTargetFramework>3.5</RequiredTargetFramework>
+ </Reference>
</ItemGroup>
</Project>
Modified: trunk/Theminds/App.cs
==============================================================================
--- trunk/Theminds/App.cs (original)
+++ trunk/Theminds/App.cs Wed Aug 1 15:50:06 2007
@@ -1,6 +1,5 @@
using System;
using System.Windows.Forms;
-using System.Diagnostics;
using System.Reflection;
using Aspirations;
using CancelEventArgs = System.ComponentModel.CancelEventArgs;
@@ -65,6 +64,10 @@
/**** Static members ****/
public static void Alert(object alert) {
MessageBox.Show(alert.ToString());
+ }
+
+ public static void Debug(object o) {
+ System.Diagnostics.Debug.WriteLine(o);
}
public static void LoadAttributeLovers(Type attribute,
Modified: trunk/Theminds/Buffer.cs
==============================================================================
--- trunk/Theminds/Buffer.cs (original)
+++ trunk/Theminds/Buffer.cs Wed Aug 1 15:50:06 2007
@@ -3,10 +3,8 @@
// tab (different log view for each tab).
using System;
-using System.Drawing;
-using System.Windows.Forms;
-using System.Diagnostics;
using System.Collections.Generic;
+using System.Drawing;
using Aspirations;
using M = System.Windows.Forms.MethodInvoker;
@@ -95,7 +93,7 @@
string channel = proust[t].Channel;
proust.Remove(t);
app.Tabber.Remove(t);
- if (StringEx.IsChannel(channel))
+ if (channel.IsChannel())
app.Connection.Message("PART {0}", channel);
}
Modified: trunk/Theminds/Filters/JoinPartQuit.cs
==============================================================================
--- trunk/Theminds/Filters/JoinPartQuit.cs (original)
+++ trunk/Theminds/Filters/JoinPartQuit.cs Wed Aug 1 15:50:06 2007
@@ -1,8 +1,6 @@
-using System;
using System.Drawing;
using Aspirations;
using S = System.String;
-using Sx = Aspirations.StringEx;
namespace Theminds.Filters {
[DesiresAppControls]
@@ -23,20 +21,20 @@
string line = data.Line;
JazzNotes notes = new JazzNotes(line);
if (!(line.Contains(" ") && line.StartsWith(":"))) return;
- int[] spaces = Sx.FindSpaces(line, 3);
+ int[] spaces = line.FindSpaces(3);
notes.Spaces = spaces;
findNickAndIp(ref notes);
if (null == notes.Nick) return;
notes.FromMe = (notes.Nick == quirk.Info.Nick);
- notes.Mode = Sx.Tween(line, spaces[0], spaces[1] - 1).ToLowerInvariant();
+ notes.Mode = line.Tween(spaces[0], spaces[1] - 1).ToLowerInvariant();
int reasonIndex = 0;
switch (notes.Mode) {
case "join":
data.Channel = line.Substring(spaces[1] + 1); break;
case "part":
- data.Channel = Sx.Tween(line, spaces[1], spaces[2] - 1);
+ data.Channel = line.Tween(spaces[1], spaces[2] - 1);
reasonIndex = spaces[2] + 1; break;
case "quit":
reasonIndex = spaces[1] + 1;
@@ -76,10 +74,10 @@
}
void findNickAndIp(ref JazzNotes notes) {
- string user = Sx.Tween(notes.Line, 0, notes.Spaces[0] - 1);
+ string user = notes.Line.Tween(0, notes.Spaces[0] - 1);
// Roots out junk like ":<nick> MODE +x"
if (!user.Contains("!")) return;
- notes.Nick = Sx.Tween(user, 1, user.IndexOf('!'));
+ notes.Nick = user.Tween(1, user.IndexOf('!'));
notes.Ip = user.Substring(user.IndexOf('!') + 1);
}
}
Modified: trunk/Theminds/Filters/Names.cs
==============================================================================
--- trunk/Theminds/Filters/Names.cs (original)
+++ trunk/Theminds/Filters/Names.cs Wed Aug 1 15:50:06 2007
@@ -5,12 +5,8 @@
// and RPL_ENDOFNAMES in the RFC. In addition,
// I serve the dual purpose of seeding the
// UserList control.
-using System;
-using System.Collections.Generic;
-using System.Windows.Forms;
-using System.Diagnostics;
+using Aspirations;
using S = System.String;
-using Sx = Aspirations.StringEx;
namespace Theminds.Filters {
[DesiresAppControls]
@@ -35,8 +31,8 @@
if (!data.Line.StartsWith(test)) return;
// Remember the colon! Rememeber the weird tacked space!
- int[] spaces = Sx.FindSpaces(data.Line, 4);
- data.Channel = Sx.Tween(data.Line, spaces[1], spaces[2] - 1);
+ int[] spaces = data.Line.FindSpaces(4);
+ data.Channel = data.Line.Tween(spaces[1], spaces[2] - 1);
string[] nicks = data.Line.Substring(spaces[2] + 1).Trim().Split(' ');
Users.Instance.Clear(data);
foreach (string nick in nicks) {
Modified: trunk/Theminds/Filters/Privmsg.cs
==============================================================================
--- trunk/Theminds/Filters/Privmsg.cs (original)
+++ trunk/Theminds/Filters/Privmsg.cs Wed Aug 1 15:50:06 2007
@@ -3,7 +3,6 @@
using Aspirations;
using MethodInvoker = System.Windows.Forms.MethodInvoker;
using S = System.String;
-using Sx = Aspirations.StringEx;
namespace Theminds.Filters {
[DesiresAppControls]
@@ -28,7 +27,7 @@
string line = data.Line;
if (!line.Contains(" ")) return;
- int[] spaces = Sx.FindSpaces(line, 4);
+ int[] spaces = line.FindSpaces(4);
if (line.StartsWith("PRIVMSG "))
filterSelf(ref data, spaces);
else if (line.StartsWith(":")
@@ -41,13 +40,13 @@
// line ~ "PRIVMSG #channel :\u0001ACTION <msg>\u0001"
void filterSelf(ref BufferData data, int[] spaces) {
string line = data.Line;
- data.Channel = Sx.Tween(line, spaces[0], spaces[1] - 1);
+ data.Channel = line.Tween(spaces[0], spaces[1] - 1);
string nick = quirk.Info.Nick;
string msg = line.Substring(spaces[1]);
// Notice the colon! Weird protocol.
if (msg.StartsWith(":\u0001ACTION")) {
- msg = Sx.Tween(line, spaces[2], line.Length - 1);
+ msg = line.Tween(spaces[2], line.Length - 1);
data.Line = S.Format(actionAll, nick, msg);
data.Color = Color.Green;
return;
@@ -59,12 +58,12 @@
// line ~ ":nick!ip PRIVMSG #channel :\u0001ACTION <msg>\u0001"
void filterOthers(ref BufferData data, int[] spaces) {
string line = data.Line;
- data.Channel = Sx.Tween(line, spaces[1], spaces[2] - 1);
+ data.Channel = line.Tween(spaces[1], spaces[2] - 1);
- string nick = Sx.Tween(line, 1, line.IndexOf('!'));
+ string nick = line.Tween(1, line.IndexOf('!'));
string msg = line.Substring(spaces[2] + 1);
if (msg.StartsWith("\u0001ACTION")) {
- msg = Sx.Tween(line, spaces[3], line.Length - 1);
+ msg = line.Tween(spaces[3], line.Length - 1);
data.Line = S.Format(actionAll, nick, msg);
data.Color = Color.Green;
return;
Modified: trunk/Theminds/Filters/Who.cs
==============================================================================
--- trunk/Theminds/Filters/Who.cs (original)
+++ trunk/Theminds/Filters/Who.cs Wed Aug 1 15:50:06 2007
@@ -1,7 +1,7 @@
using System;
using System.Drawing;
using System.Windows.Forms;
-using Sx = Aspirations.StringEx;
+using Aspirations;
namespace Theminds.Filters {
[DesiresAppControls]
@@ -13,7 +13,7 @@
// WHO commands; thus, Who serves as a dual purpose class.
app.InputBox.Command += (cmd, arg) => {
if ("w" != cmd) return;
- if (!Sx.IsChannel(app.CurrentChannel)) return;
+ if (!app.CurrentChannel.IsChannel()) return;
app.Buffer.Line += filterDel;
app.Connection.Message("WHO " + app.CurrentChannel);
};
@@ -32,7 +32,7 @@
readonly string serverPrefix = App.Lion.Get("server.prefix");
void filter(ref BufferData data) {
string[] tokens = data.Line.Split(' ');
- if (!Sx.IsChannel(tokens[1])) return;
+ if (!tokens[1].IsChannel()) return;
data.Channel = tokens[1];
data.Color = Color.DarkBlue;