Click here to Skip to main content
15,892,059 members
Articles / Database Development / SQL Server

LINQ to SQL Database Synchronizer

Rate me:
Please Sign up or sign in to vote.
4.96/5 (14 votes)
1 Jun 2009Ms-PL4 min read 84.8K   1.4K   72  
An open source utility that synchronizes your database structure with a LINQ to SQL model.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CodeRun.Utils.CommandLine
{
	internal class CommandLineArgumentsTokenizer
	{
		public CommandLineArgumentsTokenizer()
		{
		}

		bool InString;
		StringBuilder CurrentToken;
		List<string> Tokens;

		StringBuilder Processed = new StringBuilder();
		public string[] Tokenize(string text)
		{
			Tokens = new List<string>();
			CurrentToken = new StringBuilder();
			InString = false;
			foreach (char ch in text)
			{
				if (ch == '\"')
				{
					if (InString)
					{
						InString = false;
						ContinueToken(ch);
					}
					else
					{
						InString = true;
						BeginOrContinueToken(ch);
					}
				}
				else if (ch == ' ')
				{
					if (InString)
						ContinueToken(ch);
					else
						EndTokenIfExists();
				}
				else
				{
					BeginOrContinueToken(ch);
				}
				Processed.Append(ch);
			}
			EndTokenIfExists();
			return Tokens.ToArray();
		}



		private void BeginToken(char ch)
		{
			BeginToken();
			CurrentToken.Append(ch);
		}
		private void BeginToken()
		{
			if (CurrentToken != null)
				throw new Exception("cannot begin word in the middle of another word");
			CurrentToken = new StringBuilder();
		}
		private void BeginOrContinueToken(char ch)
		{
			if (CurrentToken == null)
				CurrentToken = new StringBuilder();
			CurrentToken.Append(ch);
		}
		private void ContinueToken(char ch)
		{
			CurrentToken.Append(ch);
		}
		void EndToken()
		{
			var s = CurrentToken.ToString();
			if(s.IsNotNullOrEmpty())
				Tokens.Add(s);
			CurrentToken = null;
		}
		private void EndTokenIfExists()
		{
			if (CurrentToken != null)
				Tokens.Add(CurrentToken.ToString());
			CurrentToken = null;
		}

	}
}

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 Microsoft Public License (Ms-PL)


Written By
Architect SharpKit
Israel Israel
Founder of SharpKit

Comments and Discussions