Sfm2Xml.ByteReader.GetNextSfmMarkerAndData C# (CSharp) Method

GetNextSfmMarkerAndData() public method

This is the public method that returns the 'next' marker and data and boolean as to the success of the operation. This method will return the look ahead values and then fetch the next ones. This supports the ability to look ahead a single sfm now for beter planning. (Possible enhancement would be to read the whole file in and store the infor in an internal structure, but that would lead to a duplication of memory - the contents being stored twice.) So, for now as it isn't needed, we'll just read ahead one token.
public GetNextSfmMarkerAndData ( string &sfmMarker, byte &sfmData, byte &badSfmData ) : bool
sfmMarker string
sfmData byte
badSfmData byte
return bool
		public bool GetNextSfmMarkerAndData(out string sfmMarker, out byte[] sfmData, out byte[] badSfmData)
		{
			// on the first time through, get the 'look ahead' sfm and data too.
			// on following calls, return the look ahead and continue to find next and put in lookahead
			if (m_position == 0 || (m_foundBOM && m_position == m_BOMLength))
			{
				// get the first and next (look ahead) and return the first
				bool success = getNextSfmMarkerAndData(out sfmMarker, out sfmData, out badSfmData);
				if (!success)
					return false;
				int saveLineNum = m_FoundLineNumber;
				m_hasLookAhead = getNextSfmMarkerAndData(out m_sfmLookAheadMarker, out m_sfmLookAheadData, out m_sfmLookAheadMarkerBadBytes);
				m_LookAheadLineNumber = m_FoundLineNumber;
				m_FoundLineNumber = saveLineNum;	// restore line number for current marker
				return true;
			}

			if (m_hasLookAhead && (m_position <= m_FileData.Length))
			{
				// return the look ahead and get the next one
				sfmMarker = m_sfmLookAheadMarker;
				sfmData = m_sfmLookAheadData;
				badSfmData = m_sfmLookAheadMarkerBadBytes;	// bad bytes in the marker
				// handle possible last line where count's aren't updated
				if (m_FoundLineNumber == m_LookAheadLineNumber)
					m_LookAheadLineNumber++;
				m_FoundLineNumber = m_LookAheadLineNumber;
				m_hasLookAhead = getNextSfmMarkerAndData(out m_sfmLookAheadMarker, out m_sfmLookAheadData, out m_sfmLookAheadMarkerBadBytes);

				// make sure the line number is correct
				int saveLineNum = m_FoundLineNumber;
				m_FoundLineNumber = m_LookAheadLineNumber;
				m_LookAheadLineNumber = saveLineNum;
				return true;
			}

			// there is no look ahead available, so we're done
			return getNextSfmMarkerAndData(out sfmMarker, out sfmData, out badSfmData);
		}