diff --git a/inf3.csproj b/inf3.csproj index 0e64768..271866d 100644 --- a/inf3.csproj +++ b/inf3.csproj @@ -55,6 +55,7 @@ + diff --git a/src/Parser.cs b/src/Parser.cs index 498fdad..7d76635 100644 --- a/src/Parser.cs +++ b/src/Parser.cs @@ -43,7 +43,13 @@ namespace WorldOfPeacecraft // If package is not complete wait for more lines if (!IsCompletePackage()) return; - + Block mainBlock = new Block(message, 0, message.Count - 1); + MapData(mainBlock); + } + + public void MapData (Block block) + { + // TODO Implement } public bool IsCompletePackage() @@ -74,12 +80,27 @@ namespace WorldOfPeacecraft public Block (String[] message, int start, int end) { int pos = start; + Name = StringUtils.SubstringAfter(message[pos], ":"); + pos++; while (pos < end) { // Is the next element a block or a value? if (message[pos].StartsWith("begin:")) { // It's a block + int blockstart = pos; + int begins = 1; + while (begins > 0) + { + pos++; + if (pos >= end) + throw new ParsingException("The message is missing end:-lines"); + if (message[pos].StartsWith("end:")) + begins--; + else if(message[pos].StartsWith("begin:")) + begins++; + } + Blocks.Add(new Block(message, blockstart, pos)); } else { diff --git a/src/ParsingException.cs b/src/ParsingException.cs new file mode 100644 index 0000000..fb97636 --- /dev/null +++ b/src/ParsingException.cs @@ -0,0 +1,16 @@ +using System; +using System.Runtime.Serialization; + +namespace WorldOfPeacecraft +{ + public class ParsingException : Exception + { + public ParsingException () : base(); + + public ParsingException (string message) : base(message); + + public ParsingException (SerializationInfo info, StreamingContext context) : base(info, context); + + public ParsingException (string message, Exception innerException) : base(message, innerException); + } +}