Erste Zeilen des Parser-Codes
This commit is contained in:
@@ -10,7 +10,7 @@ namespace WorldOfPeacecraft
|
||||
private Queue<string> Buffer = new Queue<string> ();
|
||||
private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false);
|
||||
private Thread ParserThread;
|
||||
private List<string> message;
|
||||
private LinkedList<string> message;
|
||||
private Regex LastLineRegex;
|
||||
|
||||
public Parser ()
|
||||
@@ -33,7 +33,7 @@ namespace WorldOfPeacecraft
|
||||
if (waitRequired)
|
||||
BufferFilledEvent.WaitOne ();
|
||||
lock (Buffer) {
|
||||
message.Add (Buffer.Dequeue ());
|
||||
message.AddLast (Buffer.Dequeue ());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ namespace WorldOfPeacecraft
|
||||
// If package is not complete wait for more lines
|
||||
if (!IsCompletePackage())
|
||||
return;
|
||||
// TODO Implement
|
||||
|
||||
}
|
||||
|
||||
public bool IsCompletePackage()
|
||||
@@ -64,6 +64,33 @@ namespace WorldOfPeacecraft
|
||||
BufferFilledEvent.Set ();
|
||||
}
|
||||
}
|
||||
|
||||
private class Block
|
||||
{
|
||||
private string Name;
|
||||
private ISet<Block> Blocks = new HashSet<Block>();
|
||||
private Dictionary<String, String> Values = new Dictionary<String, String>();
|
||||
|
||||
public Block (String[] message, int start, int end)
|
||||
{
|
||||
int pos = start;
|
||||
while (pos < end)
|
||||
{
|
||||
// Is the next element a block or a value?
|
||||
if (message[pos].StartsWith("begin:"))
|
||||
{
|
||||
// It's a block
|
||||
}
|
||||
else
|
||||
{
|
||||
string name = StringUtils.SubstringBefore(message[pos], ":");
|
||||
string val = StringUtils.SubstringAfter(message[pos], ":");
|
||||
Values[name] = val;
|
||||
pos++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
19
src/StringUtils.cs
Normal file
19
src/StringUtils.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace WorldOfPeacecraft
|
||||
{
|
||||
public class StringUtils
|
||||
{
|
||||
public static string SubstringBefore(string str, string separator)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return str.Substring(0, str.IndexOf(separator));
|
||||
}
|
||||
|
||||
public static string SubstringAfter(string str, string separator)
|
||||
{
|
||||
if (str == null)
|
||||
return null;
|
||||
return str.Substring(str.IndexOf(separator) + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user