예제 #1
0
        public bool MoveNext()
        {
            var span = _sourceStringSegment;

            // Empty string
            if (span.Length == 0)
            {
                return(false);
            }

            // Look for bot command prefix index (typically '!')
            var commandIndex = span.IndexOf(_botPrefix);

            // No command in there
            if (commandIndex == -1)
            {
                return(false);
            }

            // Skip the first part of the message and the bot prefix char
            span = span.Slice(commandIndex + 1);

            // Find the end of the command word
            var endWordIndex = 0;

            while (endWordIndex < span.Length && char.IsLetterOrDigit(span[endWordIndex]))
            {
                ++endWordIndex;
            }

            // Null command or just an isolated prefix char, recurse to look for next command
            if (endWordIndex == 0)
            {
                _sourceStringSegment = span;
                return(MoveNext());
            }

            if (endWordIndex == span.Length)
            {
                Current = new BotCommandItem(span);
                _sourceStringSegment = ReadOnlySpan <char> .Empty;
                return(true);
            }

            Current = new BotCommandItem(span.Slice(0, endWordIndex));
            _sourceStringSegment = span.Slice(endWordIndex + 1);
            return(true);
        }
예제 #2
0
 public BotCommandEnumerator(ReadOnlySpan <char> sourceString, char botPrefix)
 {
     _sourceStringSegment = sourceString;
     _botPrefix           = botPrefix;
     Current = default;
 }