private void ReadStringIntoBuffer() { int charPos = _charPos; int initialPosition = _charPos; int lastWritePosition = _charPos; StringBuffer buffer = null; while (true) { var charAt = _chars[charPos++]; if ('\0' == charAt) { if (_charsUsed == charPos - 1) { charPos--; if (ReadData(true) == 0) { _charPos = charPos; throw EdiReaderException.Create(this, "Unterminated string. Expected delimiter."); } } } // Make use of the release character. Identify escape sequence else if (Grammar.ReleaseCharacter == charAt) { _charPos = charPos; if (!EnsureChars(0, true)) { _charPos = charPos; throw EdiReaderException.Create(this, "Unterminated string. Expected delimiter."); } // start of escape sequence int escapeStartPos = charPos - 1; char currentChar = _chars[charPos]; char writeChar; if (Grammar.IsSpecial(currentChar) || Grammar.ReleaseCharacter == currentChar) { charPos++; writeChar = currentChar; } else { charPos++; _charPos = charPos; throw EdiReaderException.Create(this, "Bad EDI escape sequence: {0}.".FormatWith(CultureInfo.InvariantCulture, Grammar.ReleaseCharacter + currentChar)); } if (buffer == null) buffer = GetBuffer(); WriteCharToBuffer(buffer, writeChar, lastWritePosition, escapeStartPos); lastWritePosition = charPos; } else if (StringUtils.CarriageReturn == charAt) { _charPos = charPos - 1; ProcessCarriageReturn(true); charPos = _charPos; } else if (StringUtils.LineFeed == charAt) { _charPos = charPos - 1; ProcessLineFeed(); charPos = _charPos; } else if (Grammar.IsSpecial(_chars[charPos - 1])) { charPos--; if (initialPosition == lastWritePosition) { _stringReference = new StringReference(_chars, initialPosition, charPos - initialPosition); } else { if (buffer == null) buffer = GetBuffer(); if (charPos > lastWritePosition) buffer.Append(_chars, lastWritePosition, charPos - lastWritePosition); _stringReference = new StringReference(buffer.GetInternalBuffer(), 0, buffer.Position); } _charPos = charPos; return; } } }
private void ClearRecentString() { if (_buffer != null) _buffer.Position = 0; _stringReference = new StringReference(); }