Пример #1
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;
				}
			}
		}
Пример #2
0
		/////////////////////////////////////////////////////////////////////////////

		public static NmpStringList Split( StringIndexer input, char openChar, char closeChar, bool splitCastMode = false )
		{
			// ******
			NmpStringList subStrings = new NmpStringList();

			// ******
			StringBuilder sb = new StringBuilder();
			char ch;

			while( true ) {
				ch = input.NextChar();

				// ******
				if( ESCAPE_CHAR == ch ) {
					ch = input.NextChar();

					if( END_OF_STRING == ch ) {
						continue;
					}
					else if( escapeChars.IndexOf(ch) >= 0 || openChar == ch || closeChar == ch ) {
						sb.Append( ch );
						continue;
					}

					//
					// not a valid escape char so add escape into output and fall thru to handle
					// ch
					//
					sb.Append( ESCAPE_CHAR );
				}

				// ******
				if( END_OF_STRING == ch || SPLIT_CHAR == ch || closeChar == ch ) {
					subStrings.Add( sb.ToString().Trim() );
					sb.Length = 0;

					if( END_OF_STRING == ch || closeChar == ch ) {
						break;
					}
				}
				else if( OPEN_BRACKET == ch || OPEN_PAREN == ch || openChar == ch ) {
					char closer;

					switch( ch ) {
						case OPEN_BRACKET:
							closer = CLOSE_BRACKET;
							break;

						case OPEN_PAREN:
							closer = CLOSE_PAREN;
							break;

						default:
							closer = closeChar;
							break;
					}
					
					// ******
					NmpStringList s = Split( input, ch, closer );

					sb.Append( ch );
					sb.Append( s.Join(';') );
					sb.Append( closer );

					// ******
					if( OPEN_PAREN == ch && splitCastMode ) {
						//
						// once we've seen a complete parenthesized chunk of text we:
						//
						//		add it to the list
						//		then add the remainder of the text to the next entry
						//		and return
						//
						subStrings.Add( sb.ToString() );
						subStrings.Add( input.Remainder.Trim() );
						return subStrings;
					}
				}
				else {
					sb.Append( ch );
				}
			}

			// ******
			//
			// did not find terminating character
			//
			if( END_OF_STRING != closeChar && END_OF_STRING == ch ) {
				throw ExceptionHelpers.CreateException( "Helpers.SplitString: unbalanced string, could not locate closing character '{0}'", closeChar );
			}

			// ******
			return subStrings;
		}
Пример #3
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();
		}