/// <summary>
		/// Close the underlying reader.
		/// </summary>
		public void Close()
		{
			reader.Close();
			cb = null;
		}
		/// <summary>
		/// Constructor
		/// </summary>
		/// <param name="reader">The TextReader to wrap.</param>
		public BufferedTextReader(TextReader reader)
		{
			this.reader = reader;
			buffer = new char[BlockSize];
			cb = new CharBuffer(0);
		}
		/// <summary>
		/// Utility function, things common to constructors.
		/// </summary>
		void Initialize()
		{
			log = new Logger("StreamTokenizer");
			log.Verbosity = VerbosityLevel.Warn;
			backString = new CharBuffer(32);
			nextTokenSb = new CharBuffer(1024);

			InitializeStream();
			settings = new StreamTokenizerSettings();
			settings.SetDefaults();

			expSb = new CharBuffer();
			tmpSb = new CharBuffer();
		}
Exemple #4
0
		/// <summary>
		/// Append a string to this buffer.
		/// </summary>
		/// <param name="s">The string to append.</param>
		public void Append(CharBuffer s)
		{
			if (s.Length + tailIndex >= capacity) CheckCapacity(Length + s.Length);
			for(int i = 0; i < s.Length; i++)
				buffer[tailIndex++] = s[i];
		}
		/// <summary>
		/// 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.
		/// <para>
		/// 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.
		/// </para>
		/// <para>The formats for integers are: 1, +1, and -1</para>
		/// The + and - signs are included in the output buffer.
		/// </summary>
		/// <param name="sb">The CharBuffer to append to.</param>
		/// <param name="allowPlus">Whether or not to consider + to be part
		/// of an integer.</param>
		/// <param name="thisChar">The last character read by this method.</param>
		/// <returns>true for parsed an int, false for not an int</returns>
		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);
			}
		}