Esempio n. 1
0
        private static PayloadList ParsePayloads(string text, Model.System system)
        {
            if (text == null)
            {
                throw new ArgumentException("Text cannot be null.", nameof(text));
            }

            var list = new PayloadList();
            var currentPayloadText = string.Empty;

            // Let's iterate through the message and parse out all payloads, one by one.
            for (var i = 0; i < text.Length; i++)
            {
                currentPayloadText += text[i];

                if (TryGetPayload(currentPayloadText, out var parsedPayload, system))
                {
                    if (!(parsedPayload is TextPayload))
                    {
                        list.Add(parsedPayload);
                    }
                    else if (!string.IsNullOrEmpty(parsedPayload.RawText))
                    {
                        list.Add(parsedPayload);
                    }

                    currentPayloadText = string.Empty;
                }

                if (i < text.Length - 1 && text[i + 1] == '\\')
                {
                    list.Add(new TextPayload(currentPayloadText));

                    currentPayloadText = string.Empty;
                }
            }

            if (!string.IsNullOrEmpty(currentPayloadText))
            {
                list.Add(new TextPayload(currentPayloadText));
            }

            return(list);
        }
Esempio n. 2
0
        private PayloadList PayloadList()
        {
            PayloadList payload = new PayloadList();

            pos++;             // '['

            SkipWhiteSpacesAndComments();

            // If there are no payloads inside of the list, return an empty list.
            if (currentChar == Syntax.LIST_CLOSING)
            {
                pos++;                 // ']'

                SkipWhiteSpacesAndComments();

                return(payload);
            }


funcPayload_AnotherPayload:

            Payload p = Payload();

            // If the list has a type assigned and the payload is not of this type.
            if (payload.listType != DataType.EmptyList && p.type != payload.listType)
            {
                throw new KFFParseException("Found mismatched payload '" + p.type.ToString() + "' (" + TextFileData.Calculate(this.fileName, this.s, this.pos) + ").");
            }
            payload.Add(p);

            if (currentChar == Syntax.LIST_ELEMENT_SEPARATOR)
            {
                pos++;                 // ','

                SkipWhiteSpacesAndComments();

                goto funcPayload_AnotherPayload;
            }

            if (currentChar == Syntax.LIST_CLOSING)
            {
                pos++;                 // ']'

                SkipWhiteSpacesAndComments();

                return(payload);
            }

            throw new KFFParseException("Expected to find '" + Syntax.LIST_ELEMENT_SEPARATOR + "' or '" + Syntax.LIST_CLOSING + "', but found '" + currentChar + "' (" + TextFileData.Calculate(this.fileName, this.s, pos) + ").");
        }