Click here to Skip to main content
15,893,190 members
Articles / Web Development / ASP.NET

XsdTidy beautifies the Xsd.exe output *with full DocBook .NET Wrapper*

Rate me:
Please Sign up or sign in to vote.
4.89/5 (32 votes)
1 Mar 20048 min read 186.2K   2.4K   72  
Refactors the Xsd.exe classes. Shipped with a full .NET wrapper of DocBook.
using System;
using System.Collections;
using System.Collections.Specialized;

namespace XsdTidy
{
	/// <summary>
	/// Summary description for NameConformer.
	/// </summary>
	public class NameConformer
	{
		private Hashtable words = new Hashtable();
		private static string[] basicWords = new String[]
			{
				"able",
				"about",
				"account",
				"acid",
				"across",
				"act",
				"addition",
				"adjustment",
				"advertisement",
				"after",
				"again",
				"against",
				"agreement",
				"air",
				"all",
				"almost",
				"among",
				"amount",
				"amusement",
				"and",
				"angle",
				"angry",
				"animal",
				"answer",
				"ant",
				"any",
				"apparatus",
				"apple",
				"approval",
				"application",
				"arch",
				"argument",
				"arm",
				"army",
				"art",
				"attack",
				"attempt",
				"attention",
				"attraction",
				"authority",
				"automatic",
				"awake",
				"baby",
				"back",
				"bad",
				"bag",
				"balance",
				"ball",
				"band",
				"base",
				"basin",
				"basket",
				"bath",
				"beautiful",
				"because",
				"bed",
				"bee",
				"before",
				"behaviour",
				"belief",
				"bell",
				"bent",
				"berry",
				"between",
				"bird",
				"birth",
				"bit",
				"bite",
				"bitter",
				"black",
				"blade",
				"blood",
				"blow",
				"blue",
				"board",
				"boat",
				"body",
				"boiling",
				"bone",
				"book",
				"boot",
				"bottle",
				"box",
				"boy",
				"brain",
				"brake",
				"branch",
				"brass",
				"bread",
				"breath",
				"brick",
				"bridge",
				"bright",
				"broken",
				"brother",
				"brown",
				"brush",
				"bucket",
				"building",
				"bulb",
				"burn",
				"burst",
				"business",
				"but",
				"butter",
				"button",
				"by",
				"cake",
				"chapter",
				"camera",
				"callout",
				"canvas",
				"card",
				"care",
				"carriage",
				"cart",
				"cat",
				"cause",
				"certain",
				"cite",
				"chain",
				"chalk",
				"chance",
				"change",
				"cheap",
				"cheese",
				"chemical",
				"chest",
				"chief",
				"chin",
				"church",
				"circle",
				"class",
				"clean",
				"clear",
				"clock",
				"cloth",
				"cloud",
				"coal",
				"coat",
				"cold",
				"collar",
				"colour",
				"comb",
				"come",
				"comfort",
				"committee",
				"common",
				"company",
				"comparison",
				"competition",
				"complete",
				"complex",
				"computer",
				"condition",
				"connection",
				"conscious",
				"constant",
				"constructor",
				"contract",
				"control",
				"cook",
				"copper",
				"copy",
				"cord",
				"cork",
				"cotton",
				"cough",
				"country",
				"cover",
				"cow",
				"crack",
				"credit",
				"crime",
				"cruel",
				"crush",
				"cry",
				"cup",
				"current",
				"curtain",
				"curve",
				"cushion",
				"damage",
				"danger",
				"dark",
				"daughter",
				"day",
				"dead",
				"dear",
				"death",
				"debt",
				"decision",
				"deep",
				"degree",
				"delicate",
				"dependent",
				"design",
				"desire",
				"destruction",
				"destructor",
				"detail",
				"development",
				"different",
				"digestion",
				"direction",
				"dirty",
				"discovery",
				"discussion",
				"disease",
				"disgust",
				"distance",
				"distribution",
				"division",
				"do",
				"dog",
				"door",
				"doubt",
				"down",
				"drain",
				"drawer",
				"dress",
				"drink",
				"driving",
				"drop",
				"dry",
				"dust",
				"ear",
				"early",
				"earth",
				"east",
				"edge",
				"education",
				"effect",
				"egg",
				"elastic",
				"electric",
				"end",
				"engine",
				"enough",
				"entry",
				"equal",
				"error",
				"even",
				"event",
				"ever",
				"every",
				"example",
				"exchange",
				"existence",
				"expansion",
				"experience",
				"expert",
				"eye",
				"face",
				"fact",
				"fall",
				"false",
				"family",
				"far",
				"farm",
				"fat",
				"father",
				"fear",
				"feather",
				"feeble",
				"feeling",
				"female",
				"fertile",
				"fiction",
				"field",
				"fight",
				"finger",
				"fire",
				"first",
				"fish",
				"fixed",
				"flag",
				"flame",
				"flat",
				"flight",
				"floor",
				"flower",
				"fly",
				"fold",
				"food",
				"foolish",
				"foot",
				"for",
				"force",
				"fork",
				"form",
				"forward",
				"fowl",
				"frame",
				"free",
				"frequent",
				"friend",
				"from",
				"front",
				"fruit",
				"full",
				"future",
				"garden",
				"general",
				"get",
				"girl",
				"give",
				"glass",
				"glove",
				"go",
				"goat",
				"gold",
				"good",
				"government",
				"grain",
				"grass",
				"great",
				"green",
				"grey",
				"grip",
				"group",
				"growth",
				"gui",
				"guide",
				"gun",
				"hair",
				"hammer",
				"hand",
				"hanging",
				"happy",
				"harbour",
				"hard",
				"harmony",
				"hat",
				"hate",
				"have",
				"he",
				"head",
				"healthy",
				"hear",
				"hearing",
				"heart",
				"heat",
				"help",
				"high",
				"history",
				"hole",
				"hollow",
				"hook",
				"hope",
				"horn",
				"horse",
				"hospital",
				"hour",
				"house",
				"how",
				"humour",
				"ice",
				"idea",
				"if",
				"ill",
				"important",
				"impulse",
				"in",
				"increase",
				"index",
				"industry",
				"ink",
				"insect",
				"instrument",
				"insurance",
				"int",
				"interest",
				"invention",
				"iron",
				"island",
				"jelly",
				"jewel",
				"join",
				"journey",
				"judge",
				"jump",
				"keep",
				"kettle",
				"key",
				"kick",
				"kind",
				"kiss",
				"knee",
				"knife",
				"knot",
				"knowledge",
				"land",
				"language",
				"last",
				"late",
				"laugh",
				"law",
				"lead",
				"leaf",
				"learning",
				"leather",
				"left",
				"leg",
				"let",
				"letter",
				"level",
				"library",
				"lift",
				"light",
				"like",
				"limit",
				"line",
				"linen",
				"lip",
				"liquid",
				"list",
				"little",
				"living",
				"lock",
				"long",
				"look",
				"loose",
				"loss",
				"loud",
				"love",
				"low",
				"machine",
				"make",
				"male",
				"man",
				"manager",
				"map",
				"mark",
				"market",
				"married",
				"mass",
				"match",
				"material",
				"may",
				"meal",
				"measure",
				"meat",
				"medical",
				"meeting",
				"memory",
				"metal",
				"middle",
				"military",
				"milk",
				"mind",
				"mine",
				"minute",
				"mist",
				"mixed",
				"money",
				"monkey",
				"month",
				"moon",
				"morning",
				"mother",
				"motion",
				"mountain",
				"mouth",
				"move",
				"much",
				"muscle",
				"music",
				"nail",
				"name",
				"narrow",
				"nation",
				"natural",
				"near",
				"necessary",
				"neck",
				"need",
				"needle",
				"nerve",
				"net",
				"new",
				"news",
				"night",
				"non",
				"noise",
				"normal",
				"north",
				"nose",
				"not",
				"note",
				"now",
				"null",
				"number",
				"nut",
				"observation",
				"of",
				"off",
				"offer",
				"office",
				"oil",
				"old",
				"on",
				"only",
				"open",
				"operation",
				"opinion",
				"opposite",
				"or",
				"orange",
				"order",
				"organization",
				"ornament",
				"other",
				"out",
				"output",
				"oven",
				"over",
				"owner",
				"page",
				"pain",
				"paint",
				"pair",
				"paper",
				"parallel",
				"parcel",
				"part",
				"past",
				"paste",
				"payment",
				"peace",
				"pen",
				"pencil",
				"person",
				"physical",
				"picture",
				"pig",
				"pin",
				"pipe",
				"place",
				"plane",
				"plant",
				"plate",
				"play",
				"please",
				"pleasure",
				"plough",
				"pocket",
				"point",
				"poison",
				"polish",
				"political",
				"poor",
				"porter",
				"position",
				"possible",
				"pot",
				"potato",
				"powder",
				"power",
				"present",
				"price",
				"print",
				"prison",
				"private",
				"probable",
				"process",
				"produce",
				"profit",
				"property",
				"prose",
				"protest",
				"public",
				"pull",
				"pump",
				"punishment",
				"purpose",
				"push",
				"put",
				"quality",
				"question",
				"quick",
				"quiet",
				"quite",
				"rail",
				"rain",
				"range",
				"rat",
				"rate",
				"ray",
				"reaction",
				"reading",
				"ready",
				"reason",
				"receipt",
				"record",
				"red",
				"regret",
				"regular",
				"relation",
				"religion",
				"representative",
				"request",
				"respect",
				"responsible",
				"rest",
				"reward",
				"rhythm",
				"rice",
				"right",
				"ring",
				"river",
				"road",
				"rod",
				"roll",
				"roof",
				"room",
				"root",
				"rough",
				"round",
				"rub",
				"rule",
				"run",
				"sad",
				"safe",
				"sail",
				"salt",
				"same",
				"sand",
				"say",
				"scale",
				"school",
				"science",
				"scissors",
				"screw",
				"sea",
				"seat",
				"second",
				"secret",
				"secretary",
				"see",
				"seed",
				"seem",
				"selection",
				"self",
				"send",
				"sense",
				"separate",
				"serious",
				"servant",
				"set",
				"shade",
				"shake",
				"shame",
				"sharp",
				"sheep",
				"shelf",
				"ship",
				"shirt",
				"shock",
				"shoe",
				"short",
				"shut",
				"side",
				"sign",
				"silk",
				"silver",
				"simple",
				"sister",
				"size",
				"skin",
				"skirt",
				"sky",
				"sleep",
				"slip",
				"slope",
				"slow",
				"small",
				"smash",
				"smell",
				"smile",
				"smoke",
				"smooth",
				"snake",
				"sneeze",
				"snow",
				"soap",
				"society",
				"sock",
				"soft",
				"solid",
				"some",
				"son",
				"song",
				"sort",
				"sound",
				"soup",
				"south",
				"space",
				"spade",
				"special",
				"sponge",
				"spoon",
				"spring",
				"square",
				"stage",
				"stamp",
				"star",
				"start",
				"statement",
				"station",
				"steam",
				"steel",
				"stem",
				"step",
				"stick",
				"sticky",
				"stiff",
				"still",
				"stitch",
				"stocking",
				"stomach",
				"stone",
				"stop",
				"store",
				"story",
				"straight",
				"strange",
				"street",
				"stretch",
				"string",
				"strong",
				"structure",
				"substance",
				"such",
				"sudden",
				"sugar",
				"suggestion",
				"summer",
				"sun",
				"support",
				"surprise",
				"sweet",
				"synopsis",
				"swim",
				"system",
				"table",
				"tail",
				"take",
				"talk",
				"tall",
				"taste",
				"tax",
				"teaching",
				"tendency",
				"test",
				"than",
				"that",
				"the",
				"then",
				"theory",
				"there",
				"thick",
				"thin",
				"thing",
				"this",
				"thought",
				"thread",
				"throat",
				"through",
				"thumb",
				"thunder",
				"ticket",
				"tight",
				"till",
				"time",
				"tin",
				"tired",
				"title",
				"to",
				"toe",
				"together",
				"tomorrow",
				"tongue",
				"tooth",
				"top",
				"touch",
				"town",
				"trade",
				"train",
				"transport",
				"tray",
				"tree",
				"trick",
				"trouble",
				"trousers",
				"true",
				"turn",
				"twist",
				"umbrella",
				"under",
				"unit",
				"up",
				"use",
				"value",
				"verse",
				"very",
				"vessel",
				"video",
				"view",
				"violent",
				"voice",
				"waiting",
				"walk",
				"wall",
				"war",
				"warm",
				"wash",
				"waste",
				"watch",
				"water",
				"wave",
				"wax",
				"way",
				"weather",
				"week",
				"weight",
				"well",
				"west",
				"wet",
				"wheel",
				"when",
				"where",
				"while",
				"whip",
				"whistle",
				"white",
				"who",
				"why",
				"wide",
				"will",
				"wind",
				"window",
				"wine",
				"wing",
				"winter",
				"wire",
				"wise",
				"with",
				"woman",
				"wood",
				"wool",
				"word",
				"work",
				"worm",
				"wound",
				"writing",
				"wrong",
				"year",
				"yellow",
				"yes",
				"yesterday",
				"young"
			};

		public NameConformer()
		{
			foreach(string w in basicWords)
			{
				this.words.Add(w,null);
			}
		}

		public NameConformer(ICollection wordList)
		{
			foreach(string w in wordList)
			{
				this.words.Add(w,null);
			}
		}

		public string ToCamel(string name)
		{
			if (name==null)
				throw new ArgumentNullException("name");
			if (name.Length<=2)
				return name.ToLower();

			string cname = null;
			foreach(string s in WordSplit(name))
			{
				if (cname==null)
					cname = s;								
				else
					cname += Cap(s);
			}
			return LowerPlural(cname).Trim();
		}

		public string ToCapitalized(string name)
		{
			if (name==null)
				throw new ArgumentNullException("name");
			if (name.Length<=2)
				return name.ToUpper();

			string cname = "";
			foreach(string s in WordSplit(name))
			{
				cname += Cap(s);
			}
			return LowerPlural(cname).Trim();
		}

		private StringCollection WordSplit(string str)
		{
			StringCollection list = new StringCollection();
			// avoid short names
			if (str.Length<=2)
			{
				list.Add(str.ToLower());
				return list;
			}

			// split words
			int previous = 0;
			for (int i = 2;i<str.Length;++i)
			{
				for (int j=i+1;j<str.Length;++j)
				{
					String sub = str.Substring(previous,j-previous);
					if (this.words.Contains(sub))
					{
						// add to list
						list.Add(sub);
						previous = j;
						i=previous+1;
						break;
					}
				}
			}
			
			if (previous<str.Length)
				list.Add(str.Substring(previous,str.Length-previous));
			return list;
		}

		private string Cap(string str)
		{
			return string.Format("{0}{1}",
				Char.ToUpper(str[0]), 
				str.Substring(1,str.Length-1).ToLower()
				);
		}

		private string LowerPlural(string str)
		{
			if (str.ToLower().EndsWith("ies"))
			{
				return str.Substring(0, str.Length-3) + str.Substring(str.Length-3,3);
			}
			if (str.ToLower().EndsWith("s"))
			{
				if (str.Length==1)
					return str.ToLower();
				return str.Substring(0,str.Length-1) + Char.ToLower(str[str.Length-1]);
			}
			return str;
		}
	}
}

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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Engineer
United States United States
Jonathan de Halleux is Civil Engineer in Applied Mathematics. He finished his PhD in 2004 in the rainy country of Belgium. After 2 years in the Common Language Runtime (i.e. .net), he is now working at Microsoft Research on Pex (http://research.microsoft.com/pex).

Comments and Discussions