Code Coverage Statistics for Source File

c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Gui\BracketHighlighter.cs

Sequence Point Coverage
N/A
0 of 0
Branch Coverage
N/A
0 of 0
Lines
86
Highlight: Uncovered Code Covered Code
L V Source
1
// <file>
2
//     <copyright see="prj:///doc/copyright.txt"/>
3
//     <license see="prj:///doc/license.txt"/>
4
//     <owner name="Mike Krüger" email="mike@icsharpcode.net"/>
5
//     <version>$Revision: 2659 $</version>
6
// </file>
7
8
using System;
9
using System.Drawing;
10
using ICSharpCode.TextEditor.Document;
11
12
namespace ICSharpCode.TextEditor
13
{
14
	public class Highlight
15
	{
16
		public TextLocation OpenBrace { get; set; }
17
		public TextLocation CloseBrace { get; set; }
18
		
19
		public Highlight(TextLocation openBrace, TextLocation closeBrace)
20
		{
21
			this.OpenBrace = openBrace;
22
			this.CloseBrace = closeBrace;
23
		}
24
	}
25
	
26
	public class BracketHighlightingSheme
27
	{
28
		char opentag;
29
		char closingtag;
30
		
31
		public char OpenTag {
32
			get {
33
				return opentag;
34
			}
35
			set {
36
				opentag = value;
37
			}
38
		}
39
		
40
		public char ClosingTag {
41
			get {
42
				return closingtag;
43
			}
44
			set {
45
				closingtag = value;
46
			}
47
		}
48
		
49
		public BracketHighlightingSheme(char opentag, char closingtag)
50
		{
51
			this.opentag    = opentag;
52
			this.closingtag = closingtag;
53
		}
54
		
55
		public Highlight GetHighlight(IDocument document, int offset)
56
		{
57
			int searchOffset;
58
			if (document.TextEditorProperties.BracketMatchingStyle == BracketMatchingStyle.After) {
59
				searchOffset = offset;
60
			} else {
61
				searchOffset = offset + 1;
62
			}
63
			char word = document.GetCharAt(Math.Max(0, Math.Min(document.TextLength - 1, searchOffset)));
64
			
65
			TextLocation endP = document.OffsetToPosition(searchOffset);
66
			if (word == opentag) {
67
				if (searchOffset < document.TextLength) {
68
					int bracketOffset = TextUtilities.SearchBracketForward(document, searchOffset + 1, opentag, closingtag);
69
					if (bracketOffset >= 0) {
70
						TextLocation p = document.OffsetToPosition(bracketOffset);
71
						return new Highlight(p, endP);
72
					}
73
				}
74
			} else if (word == closingtag) {
75
				if (searchOffset > 0) {
76
					int bracketOffset = TextUtilities.SearchBracketBackward(document, searchOffset - 1, opentag, closingtag);
77
					if (bracketOffset >= 0) {
78
						TextLocation p = document.OffsetToPosition(bracketOffset);
79
						return new Highlight(p, endP);
80
					}
81
				}
82
			}
83
			return null;
84
		}
85
	}
86
}