From 709b088a22ed61f91cee204f09e19ed2983090df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20V=C3=B6gele?= Date: Fri, 4 Apr 2014 08:45:50 +0200 Subject: [PATCH] =?UTF-8?q?Strukturanalyse=20im=20Parser=20ist=20komplett,?= =?UTF-8?q?=20Daten=20m=C3=BCssen=20nur=20noch=20gemapped=20werden?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- inf3.csproj | 1 + src/Parser.cs | 23 ++++++++++++++++++++++- src/ParsingException.cs | 16 ++++++++++++++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/ParsingException.cs 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); + } +}