RTools.Util.StreamTokenizer.GrabInt C# (CSharp) Method

GrabInt() private method

Starting from current stream location, scan forward over an int. Determine whether it's an integer or not. If so, push the integer characters to the specified CharBuffer. If not, put them in backString (essentially leave the stream as it was) and return false.

If it was an int, the stream is left 1 character after the end of the int, and that character is output in the thisChar parameter.

The formats for integers are: 1, +1, and -1

The + and - signs are included in the output buffer.
private GrabInt ( CharBuffer sb, bool allowPlus, char &thisChar ) : bool
sb CharBuffer The CharBuffer to append to.
allowPlus bool Whether or not to consider + to be part /// of an integer.
thisChar char The last character read by this method.
return bool
        private bool GrabInt(CharBuffer sb, bool allowPlus, out char thisChar)
        {
            tmpSb.Clear(); // use tmp CharBuffer

            // first character can be -, maybe can be + depending on arg
            thisChar = (char)GetNextChar();
            if (thisChar == Eof)
            {
                return (false);
            }
            else if (thisChar == '+')
            {
                if (allowPlus)
                {
                    tmpSb.Append(thisChar);
                }
                else
                {
                    backString.Append(thisChar);
                    return (false);
                }
            }
            else if (thisChar == '-')
            {
                tmpSb.Append(thisChar);
            }
            else if (settings.IsCharType(thisChar, CharTypeBits.Digit))
            {
                // a digit, back this out so we can handle it in loop below
                backString.Append(thisChar);
            }
            else
            {
                // not a number starter
                backString.Append(thisChar);
                return (false);
            }

            // rest of chars have to be digits
            bool gotInt = false;
            while (((thisChar = (char)GetNextChar()) != Eof)
                && (settings.IsCharType(thisChar, CharTypeBits.Digit)))
            {
                gotInt = true;
                tmpSb.Append(thisChar);
            }

            if (gotInt)
            {
                sb.Append(tmpSb);
#if DEBUG
                log.Debug("Grabbed int {0}, sb = {1}", tmpSb, sb);
#endif
                return (true);
            }
            else
            {
                // didn't get any chars after first 
                backString.Append(tmpSb); // put + or - back on
                if (thisChar != Eof) backString.Append(thisChar);
                return (false);
            }
        }