示例#1
0
        internal static IrcMessage Parse(string data)
        {
            var    sb          = new StringBuilder();
            var    para        = new List <string>();
            var    size        = data.Length > 512 ? 512 : data.Length;
            var    messageData = data.ToCharArray(0, size);
            var    pos         = 0;
            string prefix      = null;
            string command     = null;

            if (messageData[0] == ':')
            {
                for (pos = 1; pos < messageData.Length; pos++)
                {
                    if (messageData[pos] == ' ')
                    {
                        break;
                    }

                    sb.Append(messageData[pos]);
                }
                prefix    = sb.ToString();
                sb.Length = 0;
                pos++;
            }

            for (; pos < messageData.Length; pos++)
            {
                if (messageData[pos] == ' ')
                {
                    break;
                }
                sb.Append(messageData[pos]);
            }
            command   = sb.ToString();
            sb.Length = 0;
            pos++;

            var trailing = false;

            while (pos < messageData.Length)
            {
                if (messageData[pos] == ':')
                {
                    trailing = true;
                    pos++;
                }

                for (; pos < messageData.Length; pos++)
                {
                    if (messageData[pos] == ' ' &&
                        !trailing)
                    {
                        break;
                    }
                    sb.Append(messageData[pos]);
                }
                para.Add(sb.ToString());
                sb.Length = 0;
                pos++;
            }

            return(new IrcMessage(IrcPrefix.Parse(prefix), command, para.ToArray()));
        }
示例#2
0
 internal IrcMessage(IrcPrefix prefix, string command, params string[] parameters)
 {
     From       = prefix;
     Command    = command;
     Parameters = parameters;
 }