예제 #1
0
        public IRCMessage Parse(string text)
        {
            var span = new StringSpan(text);
            var peek = span.PeekChar();

            if (peek == IRCMessage.TagsPrefix)
            {
                span.NextChar();
                var tagsText = span.TakeToSeparator(IRCMessage.TagsSuffix, false, true);
                this.Tags = new IRCTags().Parse(tagsText);
            }
            else
            {
                this.Tags = null;
            }

            peek = span.PeekChar();

            if (peek == IRCMessage.PrefixsPrefix)
            {
                span.NextChar();
                var prefixText = span.TakeToSeparator(IRCMessage.PrefixsSuffix, false, true);
                this.Prefix = new IRCPrefix().Parse(prefixText);
            }
            else
            {
                this.Prefix = null;
            }

            var commandText = span.TakeToSeparator(IRCParams.ParamsPrefix, false);

            this.Command = commandText;

            var paramsText = span.TakeToEnd();

            this.Params = new IRCParams().Parse(paramsText);

            return(this);
        }
예제 #2
0
        public IRCParams Parse(string text)
        {
            var span = new StringSpan(text);

            var values = this.Values;

            values.Clear();

            if (span.Position < span.Length)
            {
                while (true)
                {
                    if (span.NextChar(IRCParams.ParamsPrefix) == IRCParams.ParamsPrefix)
                    {
                        var peek = span.PeekChar();

                        if (peek == IRCParams.TrailingPrefix)
                        {
                            values.Add(span.TakeToEnd());
                        }
                        else
                        {
                            var value = span.TakeToSeparator(IRCParams.ParamsPrefix, false);
                            values.Add(value);
                        }
                    }
                    else
                    {
                        break;
                    }

                    if (span.Position >= span.Length)
                    {
                        break;
                    }
                }
            }

            return(this);
        }