summaryrefslogtreecommitdiff
path: root/CSharp/Ivy/IvyPPC/IvyBinding.cs
diff options
context:
space:
mode:
Diffstat (limited to 'CSharp/Ivy/IvyPPC/IvyBinding.cs')
-rw-r--r--CSharp/Ivy/IvyPPC/IvyBinding.cs41
1 files changed, 24 insertions, 17 deletions
diff --git a/CSharp/Ivy/IvyPPC/IvyBinding.cs b/CSharp/Ivy/IvyPPC/IvyBinding.cs
index c5fd5fe..1ff96e5 100644
--- a/CSharp/Ivy/IvyPPC/IvyBinding.cs
+++ b/CSharp/Ivy/IvyPPC/IvyBinding.cs
@@ -1,5 +1,6 @@
using System;
using System.Collections;
+using System.Collections.Specialized;
using System.Text.RegularExpressions;
namespace IvyBus
@@ -9,39 +10,42 @@ namespace IvyBus
/// </summary>
internal abstract class IvyBindingBase
{
-
- internal int key;
+
+ internal ushort key;
internal string expression;
-
- public IvyBindingBase(int id, string exp)
+
+ public IvyBindingBase(ushort id, string exp)
{
key = id;
expression = exp;
}
- public abstract IvyArgument Match(string message);
+ public abstract string[] Match(string message);
}
internal class IvyBindingRegexp : IvyBindingBase
{
internal Regex regexp;
-
- public IvyBindingRegexp(int id, string exp):base(id,exp)
+
+ public IvyBindingRegexp(ushort id, string exp)
+ : base(id, exp)
{
regexp = new Regex(expression,RegexOptions.Compiled|RegexOptions.IgnoreCase);
}
- public override IvyArgument Match(string message)
+ public override string[] Match(string message)
{
- IvyArgument args = null;
+ string[] args = null;
// use of regexp to extract info
Match result = regexp.Match(message);
if (result.Success)
{
// Start at 1 because group 0 represent entire matching
- args = new IvyArgument("");
+ StringCollection coll = new StringCollection();
for (int sub = 1; sub < result.Groups.Count; sub++)
{
- args.addChild( new IvyArgument( result.Groups[sub].Value ));
+ coll.Add(result.Groups[sub].Value);
}
+ args = new string[coll.Count];
+ coll.CopyTo(args, 0);
}
return args;
}
@@ -52,8 +56,9 @@ namespace IvyBus
internal string[] msgargs; // list of message args names
static string msgtag; // send message name
static Hashtable args_values = null; // send message args[name]=value
-
- public IvyBindingSimple(int id, string exp):base(id,exp)
+
+ public IvyBindingSimple(ushort id, string exp)
+ : base(id, exp)
{
string[] expr = expression.Split( ' ' );
msgname = expr[0];
@@ -78,19 +83,21 @@ namespace IvyBus
}
}
- public override IvyArgument Match(string message)
+ public override string[] Match(string message)
{
// the message is already parsed by prepare
//
- IvyArgument args = null;
+ string[] args = null;
if (msgtag == msgname)
{
- args = new IvyArgument("");
+ StringCollection coll = new StringCollection();
for( int sub= 0; sub < msgargs.Length; sub++)
{
- args.addChild( new IvyArgument( (string) args_values[ msgargs[sub]] ));
+ coll.Add((string)args_values[msgargs[sub]]);
}
+ args = new string[coll.Count];
+ coll.CopyTo(args, 0);
}
return args;
}