namespace com.azkoss.excellite { using System; using System.Collections; using System.Text; /// ///Buffer class is used as the wrapper aroung input string for FormulaParser providing ///additional helpful methods for accessing string buffer. /// internal class Buffer { // Methods /// ///Initializes a new instance of the class. /// ///The string data to wrap. public Buffer(string data) { this.data = data; this.pos = -1; } /// ///Gets the current ñhar data. /// ///current char data public char GetCurrent() { return this.data[this.pos]; } /// ///Gets the next char from buffer. /// ///read char or special char indicating no read status public char GetNext() { if (this.IsEOF) { return '@'; } this.pos++; return this.data[this.pos]; } /// ///Gets the next on demand( if next symbol is peek, than read it and return back ). /// ///The char to peek for. ///read char or special char indicating no read status public char GetNextOnDemand(char peek) { return this.GetNextOnDemand(peek, true); } /// ///Gets the next on demand( if next symbol is of the given chars, than read it and return back ). /// ///The char array to peek for. /// ///read char or special char indicating no read status /// public char GetNextOnDemand(char[] charsToPeekFor) { char ch1 = '@'; for (int num1 = 0; num1 < charsToPeekFor.Length; num1++) { ch1 = this.GetNextOnDemand(charsToPeekFor[num1]); if (ch1 != '@') { break; } } return ch1; } /// ///Gets the next on demand( if next symbol is peek, than read it and return back ). ///Additionally it can skip whitespaces on demand. /// ///The char to peek for. ///if set to true [skip whitespaces]. /// ///read char or special char indicating no read status /// public char GetNextOnDemand(char peek, bool skipWhitespaces) { if (skipWhitespaces) { this.SkipWhitespaces(); } if (this.Peek() != peek) { return '@'; } return this.GetNext(); } /// ///Gets the next string from buffer with skipping whitespaces. /// ///read string public string GetNextString() { return this.GetNextString(true); } /// ///Gets the next string from buffer with optional skipping whitespaces. /// ///read string public string GetNextString(bool skipWhitespaces) { bool flag1 = false; StringBuilder builder1 = new StringBuilder(); char ch1 = this.Peek(); bool flag2 = ch1 == '.'; if (char.IsLetter(ch1)) { do { builder1.Append(ch1); this.GetNext(); ch1 = this.Peek(); } while (char.IsLetterOrDigit(this.Peek())); } else if ((char.IsDigit(ch1) || flag2) && !flag1) { do { builder1.Append(ch1); this.GetNext(); ch1 = this.Peek(); if ((ch1 == '.') && flag2) { break; } flag2 = ch1 == '.'; } while (char.IsDigit(ch1) || flag2); } if (skipWhitespaces) { this.SkipWhitespaces(); } return builder1.ToString(); } /// ///Gets the next string from buffer. /// ///The arrag of chars used as end marks during reading. ///read string public string GetNextString(char[] endChars) { ArrayList list1 = new ArrayList(endChars); StringBuilder builder1 = new StringBuilder(); while (!this.IsEOF && !list1.Contains(this.Peek())) { builder1.Append(this.GetNext()); } this.SkipWhitespaces(); return builder1.ToString(); } /// ///Gets the next string from buffer. /// ///The char used as end mark during reading. ///read string public string GetNextString(char endChar) { StringBuilder builder1 = new StringBuilder(); while ((this.Peek() != endChar) && !this.IsEOF) { builder1.Append(this.GetNext()); } this.SkipWhitespaces(); return builder1.ToString(); } /// ///Gets the next on demand( if next symbol is peek, than read it and return back ). ///Additionally it always skip whitespaces. /// ///read char or special char indicating no read status public char GetNextWithWhitespaceSkippling() { char ch1 = this.GetNext(); this.SkipWhitespaces(); return ch1; } /// ///Peeks for the next char. /// ///read char or special char indicating no read status public char Peek() { if (!this.IsEOF) { return this.data[this.pos + 1]; } return '@'; } /// ///Peeks for the next char at specified forward-position /// ///read char or special char indicating no read status public char Peek(int peekPos) { if (((this.pos + 1) + peekPos) < this.data.Length) { return this.data[(this.pos + 1) + peekPos]; } return '@'; } /// ///Skips the whitespaces. /// public void SkipWhitespaces() { while (!this.IsEOF && (this.Peek() == ' ')) { this.GetNext(); } } // Properties /// ///Gets the input data string buffer. /// ///The input data string buffer. public string Data { get { return this.data; } } /// ///Gets a value indicating whether we have reached end of input buffer. /// ///true if we have reached end of input buffer; otherwise, false. public bool IsEOF { get { return (this.data.Length == (this.pos + 1)); } } /// ///Gets the position of input data string buffer. /// ///The position of input data string buffer. public int Pos { get { return this.pos; } } // Fields private string data; /// ///Unique char to identify that char is empty /// public const char Empty = '@'; /// ///Unique integer to identify that integer is null /// public const int EmptyInteger = -2147483648; private int pos; } }