/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { int nextChar = AcquireChar(); if (nextChar == From) { return(To); } return(nextChar); }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { if (_spacesRemaining == 0) { int nextChar = AcquireChar(); if (nextChar == '\t') { _spacesRemaining = TabLength - 1; return(' '); } else { return(nextChar); } } else { _spacesRemaining--; return(' '); } }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { int ch; // either read the next character or if there is a buffer output // the next character if (_outputBuffer == null) { ch = base.Read(); } else { // characters left in the buffer? if (_bufferPosition < _outputBuffer.Length) { // if this is the last character of a token string that is // unknown then process the charactor again since it might // be the beginning of another token if ((_tokenNotFound == true) && (_unknownToken == true) && (_bufferPosition == _outputBuffer.Length - 1)) { // process token end char again as it could be the same // as token begin ch = _outputBuffer[_outputBuffer.Length - 1]; _bufferPosition++; } else { // pass along buffer character return(_outputBuffer[_bufferPosition++]); } } else // end of buffer // reset buffer and get next char { _outputBuffer = null; _bufferPosition = 0; // read the next character or end the stream the end of the // stream was encountered while reading the buffer if (!_endStreamAfterBuffer) { ch = ReadChar(); } else { return(-1); } } } //Process beginning token if (CompareCharacters(ch, _beginToken)) { //Look for a token after _beginToken and return either the replacement token //or the charactors that were read. _outputBuffer = FindTokenContents(out _tokenNotFound, out _unknownToken, out _endStreamAfterBuffer); //A token was not found so _beginToken needs to be accounted for. if (_tokenNotFound) { _bufferPosition = 0; return(_beginToken); } else { //Output first character of buffer _bufferPosition = 1; return(_outputBuffer[0]); } } else { // this was not a beginning token so just pass it through return(ch); } }
/// <summary> /// Construct that allows this filter to be chained to the one /// in the parameter chainedReader. /// </summary> /// <param name="chainedReader">Filter that the filter will be chained to</param> public override void Chain(ChainableReader chainedReader) { base.Chain(chainedReader); ReadChar = new AcquireCharDelegate(base.Read); }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { int ch; //Either read the next character or if there is a buffer output the next character if (_outputBuffer == null) { ch = base.Read(); } else { // characters left in the buffer? if (_bufferPosition < _outputBuffer.Length) { //If this is the last character of a buffer that was not the replacemant string //process the last charactor again since it might be the beginning of another token. if ((_stringNotFound == true) && (_bufferPosition == _outputBuffer.Length - 1)) { //Process token end char again. It could be the same as token begin. ch = _outputBuffer[_outputBuffer.Length - 1]; _bufferPosition++; } else { //Pass along buffer character return(_outputBuffer[_bufferPosition++]); } } else //End of buffer //Reset buffer and get next char { _outputBuffer = null; _bufferPosition = 0; //Read the next character or end the stream the end of the stream //was encountered while reading the buffer. if (!_endStreamAfterBuffer) { ch = ReadChar(); } else { return(-1); } } } // if the character matches the first character of the target string then search // for the string. if (CompareCharacters(ch, _from[0])) { // search for the target string if (FindString(ch, out _endStreamAfterBuffer, out _outputBuffer) == true) { //Target was found _stringNotFound = false; //Do nothing if _to is null; otherwise output _to if (_to == string.Empty) { _outputBuffer = null; return(GetNextCharacter(AcquireChar)); } else { _outputBuffer = _to; _bufferPosition = 1; } return(_to[0]); } else { //Target not found _stringNotFound = true; _bufferPosition = 1; return(ch); } } else { //This was not a beginning token so just pass it through return(ch); } }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { int ch; // either read the next character or if there is a buffer output // the next character if (_outputBuffer == null) { ch = base.Read(); } else { // characters left in the buffer? if (_bufferPosition < _outputBuffer.Length) { // if this is the last character of a token string that is // unknown then process the charactor again since it might // be the beginning of another token if ((_tokenNotFound == true) && (_unknownToken == true) && (_bufferPosition == _outputBuffer.Length - 1)) { // process token end char again as it could be the same // as token begin ch = _outputBuffer[_outputBuffer.Length - 1]; _bufferPosition++; } else { // pass along buffer character return _outputBuffer[_bufferPosition++]; } } else { // end of buffer // reset buffer and get next char _outputBuffer = null; _bufferPosition = 0; // read the next character or end the stream the end of the // stream was encountered while reading the buffer if (!_endStreamAfterBuffer) { ch = ReadChar(); } else { return -1; } } } // process beginning token if (CompareCharacters(ch, BeginToken)) { // look for a token after BeginToken and return either the // replacement token or the charactors that were read _outputBuffer = FindTokenContents(out _tokenNotFound, out _unknownToken, out _endStreamAfterBuffer); // a token was not found so BeginToken needs to be accounted for. if (_tokenNotFound) { _bufferPosition = 0; return BeginToken; } else { if (_outputBuffer.Length > 0) { // output first character of buffer _bufferPosition = 1; return _outputBuffer[0]; } else { // return next character return GetNextCharacter(AcquireChar); } } } else { // this was not a beginning token so just pass it through return ch; } }
/// <summary> /// Construct that allows this filter to be chained to the one /// in the parameter chainedReader. /// </summary> /// <param name="chainedReader">Filter that the filter will be chained to</param> public override void Chain(ChainableReader chainedReader) { base.Chain(chainedReader); ReadChar = new AcquireCharDelegate(base.Read); }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { int ch; //Either read the next character or if there is a buffer output the next character if (_outputBuffer == null) { ch = base.Read(); } else { // characters left in the buffer? if (_bufferPosition < _outputBuffer.Length) { //If this is the last character of a buffer that was not the replacemant string //process the last charactor again since it might be the beginning of another token. if ((_stringNotFound == true) && (_bufferPosition == _outputBuffer.Length - 1)) { //Process token end char again. It could be the same as token begin. ch = _outputBuffer[_outputBuffer.Length - 1]; _bufferPosition++; } else { //Pass along buffer character return _outputBuffer[_bufferPosition++]; } } else {//End of buffer //Reset buffer and get next char _outputBuffer = null; _bufferPosition = 0; //Read the next character or end the stream the end of the stream //was encountered while reading the buffer. if (!_endStreamAfterBuffer) { ch = ReadChar(); } else { return -1; } } } // if the character matches the first character of the target string then search // for the string. if (CompareCharacters(ch, _from[0])) { // search for the target string if (FindString(ch, out _endStreamAfterBuffer, out _outputBuffer) == true) { //Target was found _stringNotFound = false; //Do nothing if _to is null; otherwise output _to if (_to==string.Empty) { _outputBuffer = null; return GetNextCharacter(AcquireChar); } else { _outputBuffer = _to; _bufferPosition = 1; } return _to[0]; } else { //Target not found _stringNotFound = true; _bufferPosition = 1; return ch; } } else { //This was not a beginning token so just pass it through return ch; } }
public override void Chain(ChainableReader parentChainedReader) { base.Chain(parentChainedReader); this.ReadChar = new AcquireCharDelegate(base.Read); }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { int nextChar = AcquireChar(); if (nextChar == From) { return To; } return nextChar; }
/// <summary> /// Returns the next character in the stream replacing the specified character. Using the /// <see cref="AcquireCharDelegate"/> allows for the same implementation for Read and Peek /// </summary> /// <param name="AcquireChar">Delegate to acquire the next character. (Read/Peek)</param> /// <returns>Char as an int or -1 if at the end of the stream</returns> private int GetNextCharacter(AcquireCharDelegate AcquireChar) { if (_spacesRemaining == 0) { int nextChar = AcquireChar(); if (nextChar == '\t') { _spacesRemaining = TabLength - 1; return ' '; } else { return nextChar; } } else { _spacesRemaining--; return ' '; } }