Ejemplo n.º 1
0
		static internal string Comment(ParserType type, TextData data, Range range)
		{
			switch (type)
			{
				case ParserType.CSharp: return CSharpVisitor.Comment(data, range);
				case ParserType.HTML:
				case ParserType.XML:
					return HTMLVisitor.Comment(data, range);
				default: throw new Exception("Cannot comment this content type");
			}
		}
Ejemplo n.º 2
0
		SplitDialog(TextData data)
		{
			InitializeComponent();
			calcNumFiles = new RunOnceTimer(() => CalculateNumFiles());
			calcSize = new RunOnceTimer(() => CalculateSize());
			this.data = data;
			OutputDir = Path.GetDirectoryName(data.FileName);
			OutputTemplate = $"{Path.GetFileNameWithoutExtension(data.FileName)} - {{0}}{Path.GetExtension(data.FileName)}";

			foreach (var value in Helpers.GetValues<SizeTypeEnum>())
				sizeType.Items.Add(value);

			Size = 50;
			SizeType = SizeTypeEnum.MB;
		}
Ejemplo n.º 3
0
		public void FixWhitespace(TextData template, bool ignoreCase, bool ignoreNumbers)
		{
			if ((diffData == null) || (template.diffData == null))
				return;

			var lines0 = Enumerable.Range(0, NumLines).Where(line => diffData.LineMatch[line] != LCS.MatchType.Gap).Select(line => GetLine(line, true)).Select(line => FormatDiffLine(line, true, ignoreCase, ignoreNumbers, true)).ToList();
			var lines1 = Enumerable.Range(0, template.NumLines).Where(line => template.diffData.LineMatch[line] != LCS.MatchType.Gap).Select(line => template.GetLine(line, true)).Select(line => FormatDiffLine(line, true, ignoreCase, ignoreNumbers, true)).ToList();
			var linesLCS = LCS.GetLCS(lines0, lines1);

			for (var line = 0; line < linesLCS.Count; ++line)
			{
				if (!linesLCS[line].IsMatch)
					continue;

				var line0 = GetLine(line, true).ToList();
				var line1 = template.GetLine(line, true).ToList();
				var colsLCS = LCS.GetLCS(line0, line1);
				if (line == 19)
					colsLCS = colsLCS;

				//var start = default(int?);
				//var pos = 0;
				//for (var col = 0; col <= colsLCS.Count; ++col, ++pos)
				//{
				//	if ((col == colsLCS.Count) || (colsLCS[col].IsMatch))
				//	{
				//		if (start.HasValue)
				//			diffData.ColCompare[line].Add(Tuple.Create(start.Value, pos));
				//		start = null;
				//		continue;
				//	}

				//	if (colsLCS[col] != LCS.MatchType.Mismatch)
				//	{
				//		--pos;
				//		continue;
				//	}

				//	start = start ?? pos;
				//}
			}

			//	for (var pass = 0; pass < 2; ++pass)
			//	{
			//		var diffData = pass == 0 ? diffData : template.diffData;
			//		var cols = pass == 0 ? cols0 : cols1;
			//		var map = pass == 0 ? map0 : map1;
			//		int? start = null;
			//		int pos = 0;
			//		diffData.ColCompare[line] = new List<Tuple<int, int>>();
			//	}
			//}
		}
Ejemplo n.º 4
0
		static public Result Run(Window parent, TextData data)
		{
			var dialog = new SplitDialog(data) { Owner = parent };
			return dialog.ShowDialog() ? dialog.result : null;
		}
Ejemplo n.º 5
0
		public static void CalculateDiff(TextData data0, TextData data1, bool ignoreWhitespace, bool ignoreCase, bool ignoreNumbers, bool ignoreLineEndings)
		{
			if ((data0.diffData != null) && (data1.diffData != null) && (data0.diffData.Data == data0.Data) && (data1.diffData.Data == data1.Data) && (data0.diffData.IgnoreWhitespace == ignoreWhitespace) && (data1.diffData.IgnoreWhitespace == ignoreWhitespace) && (data0.diffData.IgnoreCase == ignoreCase) && (data1.diffData.IgnoreCase == ignoreCase) && (data0.diffData.IgnoreNumbers == ignoreNumbers) && (data1.diffData.IgnoreNumbers == ignoreNumbers) && (data0.diffData.IgnoreLineEndings == ignoreLineEndings) && (data1.diffData.IgnoreLineEndings == ignoreLineEndings))
				return;

			var data = new TextData[] { data0, data1 };
			var lines = new List<string>[2];
			for (var pass = 0; pass < 2; ++pass)
			{
				data[pass].ClearDiff();
				data[pass].diffData = new DiffData(data[pass].Data, ignoreWhitespace, ignoreCase, ignoreNumbers, ignoreLineEndings);
				lines[pass] = Enumerable.Range(0, data[pass].NumLines).Select(line => data[pass].GetLine(line, true)).Select(line => FormatDiffLine(line, ignoreWhitespace, ignoreCase, ignoreNumbers, ignoreLineEndings)).ToList();
			}

			var linesLCS = LCS.GetLCS(lines[0], lines[1]);
			for (var pass = 0; pass < 2; ++pass)
			{
				data[pass].diffData.LineMatch = linesLCS.Select(lcsResult => lcsResult.Match(pass)).ToList();

				for (var line = 0; line < linesLCS.Count; ++line)
					if (!linesLCS[line].Index(pass).HasValue)
					{
						data[pass].lineOffset.Insert(line, data[pass].lineOffset[line]);
						data[pass].endingOffset.Insert(line, data[pass].lineOffset[line]);
					}

				data[pass].diffData.LineMap = new Dictionary<int, int>();
				var pos = -1;
				for (var line = 0; line < linesLCS.Count; ++line)
				{
					pos = linesLCS[line].Index(pass) ?? pos;
					data[pass].diffData.LineMap[line] = pos;
				}
				data[pass].diffData.LineRevMap = data[pass].diffData.LineMap.GroupBy(pair => pair.Value).ToDictionary(group => group.Key, group => group.Min(pair => pair.Key));
				data[pass].diffData.ColCompare = new List<Tuple<int, int>>[linesLCS.Count];
			}

			for (var line = 0; line < linesLCS.Count; ++line)
			{
				if (linesLCS[line].IsMatch)
					continue;

				var skip = false;
				for (var pass = 0; pass < 2; ++pass)
					if (!linesLCS[line].Index(pass).HasValue)
					{
						data[1 - pass].diffData.ColCompare[line] = new List<Tuple<int, int>> { Tuple.Create(0, int.MaxValue) };
						skip = true;
					}
				if (skip)
					continue;

				var text = new List<char>[2];
				for (var pass = 0; pass < 2; ++pass)
					text[pass] = data[pass].GetLine(line, true).ToList();
				var colsLCS = LCS.GetLCS(text[0], text[1]);

				for (var pass = 0; pass < 2; ++pass)
				{
					var map = data[pass].GetLineColumnMap(line, true);
					int? start = null;
					data[pass].diffData.ColCompare[line] = new List<Tuple<int, int>>();
					for (var col = 0; col <= colsLCS.Count; ++col)
					{
						if ((col == colsLCS.Count) || (colsLCS[col].IsMatch))
						{
							if (start.HasValue)
								data[pass].diffData.ColCompare[line].Add(Tuple.Create(map[start.Value], map[colsLCS[col].Index(pass).Value]));
							start = null;
							continue;
						}

						start = start ?? colsLCS[col].Index(pass);
					}
				}
			}
		}