Example #1
0
		/////////////////////////////////////////////////////////////////////////////

		public void Skip( StringIndexer input )
		{
			// ******
			if( FirstChar == input.Peek() && input.StartsWith(Sequence) ) {
				input.Skip( Sequence.Length );
			}
			else {
				throw new Exception( string.Format("input buffer does not begin with \"{1}\"", Sequence) );
			}
		}
Example #2
0
		/////////////////////////////////////////////////////////////////////////////

		private static string GetText( StringIndexer reader )
		{
			// ******
			var sb = new StringBuilder();
			
			// ******
			while( true ) {
				char ch = reader.NextChar();
				
				if( SC.CR == ch || SC.NEWLINE == ch || SC.NO_CHAR == ch ) {
					if( SC.CR == ch && SC.NEWLINE == reader.Peek() ) {
						//
						// skip the newline if preceeded by cr
						//
						reader.Skip( 1 );
					}
						
					break;
				}

				sb.Append( ch );
			}

			// ******
			return sb.ToString();
		}
Example #3
0
		/////////////////////////////////////////////////////////////////////////////

		private static void ReadToEOL( StringIndexer reader )
		{
			while( true ) {
				char ch = reader.NextChar();
				
				if( SC.CR == ch || SC.NEWLINE == ch || SC.NO_CHAR == ch ) {
					if( SC.CR == ch && SC.NEWLINE == reader.Peek() ) {
						//
						// skip the newline if preceeded by cr
						//
						reader.Skip( 1 );
					}
						
					return;
				}
			}
		}
		/////////////////////////////////////////////////////////////////////////////
		
		public string GetQuotedText( StringIndexer input, bool keepQuotes )
		{
			// ******
			StringBuilder sb = new StringBuilder();
			if( keepQuotes ) {
				sb.Append( SeqOpenQuote.Sequence );
			}
		
			// ******
			while( true ) {
				char ch = input.Peek();

				if( SeqOpenQuote.FirstChar == ch && SeqOpenQuote.Starts(input) ) {
					SeqOpenQuote.Skip( input );

					// ******
					sb.Append( GetQuotedText(input, true) );
				}

				else if( SeqCloseQuote.FirstChar == ch && SeqCloseQuote.Starts(input) ) {
					SeqCloseQuote.Skip( input );

					// ******
					if( keepQuotes ) {
						sb.Append( SeqCloseQuote.Sequence );
					}
					return sb.ToString();
				}
				else if( SC.NO_CHAR == ch ) {

	// TODO: need file/line/col number for use with MPError

					ThreadContext.MacroError( "end of data: unbalanced quotes" );

				}
				else {
					input.Skip( 1 );
					sb.Append( ch );
				}
			}
		}