Click here to Skip to main content
15,885,940 members
Articles / Desktop Programming / Windows Forms

Storm - the world's best IDE framework for .NET

Rate me:
Please Sign up or sign in to vote.
4.96/5 (82 votes)
4 Feb 2010LGPL311 min read 274.5K   6.5K   340  
Create fast, flexible, and extensible IDE applications easily with Storm - it takes nearly no code at all!
using System.Text.RegularExpressions;

using Storm.TextEditor.Editor;
using Storm.TextEditor.Parser.Objects;

namespace Storm.TextEditor.Parser
{
	/// <summary>
	/// Contains methods for parsing.
	/// </summary>
	public sealed class ParseTools
	{
		#region Fields

		private static Regex WordSplitter = new Regex(@"(?<space>\s)|(?<tab>\t)", RegexOptions.Compiled);

		#endregion

		#region Methods

		#region Public

		/// <summary>
		/// Adds a word with the given text to the given row.
		/// </summary>
		/// <param name="text">Text of the word.</param>
		/// <param name="row">Row to add the word to.</param>
		/// <param name="pattern">Pattern of the word.</param>
		/// <param name="style">TextStyle of the word.</param>
		/// <param name="segment">Segment of the word.</param>
		/// <param name="hasError">Whether the word should have an error.</param>
		public static void AddPatternString(string text, Row row, Pattern pattern, TextStyle style, Segment segment, bool hasError)
		{
			Word word = row.Add(text);

			word.Style    = style;
			word.Pattern  = pattern;
			word.HasError = hasError;
			word.Segment  = segment;
		}

		/// <summary>
		/// Adds the given text to the given row.
		/// </summary>
		/// <param name="text">Text to add.</param>
		/// <param name="row">Row to add the text to.</param>
		/// <param name="style">TextStyle of the text.</param>
		/// <param name="segment">Segment of the text.</param>
		public unsafe static void AddString(string text, Row row, TextStyle style, Segment segment)
		{
			if (text == "")
				return;

			string[] splittedText = WordSplitter.Split(text);
			string   lineText     = "";

			for (int i = 0; i < splittedText.Length; i++)
			{
				lineText  = splittedText[i];
				Word word = row.Add(lineText);

				word.Style   = style;
				word.Segment = segment;
				
				if (lineText == " ")
					word.Type = WordType.Space;
				else if (lineText == "\t")
					word.Type = WordType.Tab;
			}
		}

		#endregion

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU Lesser General Public License (LGPLv3)



Comments and Discussions