Erste Zeilen des Parser-Codes
This commit is contained in:
@@ -54,6 +54,7 @@
|
|||||||
<Compile Include="src\Player.cs" />
|
<Compile Include="src\Player.cs" />
|
||||||
<Compile Include="src\Parser.cs" />
|
<Compile Include="src\Parser.cs" />
|
||||||
<Compile Include="src\Backend.cs" />
|
<Compile Include="src\Backend.cs" />
|
||||||
|
<Compile Include="src\StringUtils.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="src\DefaultGui\" />
|
<Folder Include="src\DefaultGui\" />
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ namespace WorldOfPeacecraft
|
|||||||
private Queue<string> Buffer = new Queue<string> ();
|
private Queue<string> Buffer = new Queue<string> ();
|
||||||
private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false);
|
private AutoResetEvent BufferFilledEvent = new AutoResetEvent (false);
|
||||||
private Thread ParserThread;
|
private Thread ParserThread;
|
||||||
private List<string> message;
|
private LinkedList<string> message;
|
||||||
private Regex LastLineRegex;
|
private Regex LastLineRegex;
|
||||||
|
|
||||||
public Parser ()
|
public Parser ()
|
||||||
@@ -33,7 +33,7 @@ namespace WorldOfPeacecraft
|
|||||||
if (waitRequired)
|
if (waitRequired)
|
||||||
BufferFilledEvent.WaitOne ();
|
BufferFilledEvent.WaitOne ();
|
||||||
lock (Buffer) {
|
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 package is not complete wait for more lines
|
||||||
if (!IsCompletePackage())
|
if (!IsCompletePackage())
|
||||||
return;
|
return;
|
||||||
// TODO Implement
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsCompletePackage()
|
public bool IsCompletePackage()
|
||||||
@@ -64,6 +64,33 @@ namespace WorldOfPeacecraft
|
|||||||
BufferFilledEvent.Set ();
|
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