Code Coverage Statistics for Source File

c:\Tools\SD3\src\Libraries\ICSharpCode.TextEditor\Project\Src\Document\TextBufferStrategy\StringTextBufferStrategy.cs

Sequence Point Coverage
N/A
0 of 0
Branch Coverage
N/A
0 of 0
Lines
85
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: 2682 $</version>
6
// </file>
7
8
using System;
9
using System.IO;
10
using System.Text;
11
12
namespace ICSharpCode.TextEditor.Document
13
{
14
	/// <summary>
15
	/// Simple implementation of the ITextBuffer interface implemented using a
16
	/// string.
17
	/// Only for fall-back purposes.
18
	/// </summary>
19
	public class StringTextBufferStrategy : ITextBufferStrategy
20
	{
21
		string storedText = "";
22
		
23
		public int Length {
24
			get {
25
				return storedText.Length;
26
			}
27
		}
28
		
29
		public void Insert(int offset, string text)
30
		{
31
			if (text != null) {
32
				storedText = storedText.Insert(offset, text);
33
			}
34
		}
35
		
36
		public void Remove(int offset, int length)
37
		{
38
			storedText = storedText.Remove(offset, length);
39
		}
40
		
41
		public void Replace(int offset, int length, string text)
42
		{
43
			Remove(offset, length);
44
			Insert(offset, text);
45
		}
46
		
47
		public string GetText(int offset, int length)
48
		{
49
			if (length == 0) {
50
				return "";
51
			}
52
			if (offset == 0 && length >= storedText.Length) {
53
				return storedText;
54
			}
55
			return storedText.Substring(offset, Math.Min(length, storedText.Length - offset));
56
		}
57
		
58
		public char GetCharAt(int offset)
59
		{
60
			if (offset == Length) {
61
				return '\0';
62
			}
63
			return storedText[offset];
64
		}
65
		
66
		public void SetContent(string text)
67
		{
68
			storedText = text;
69
		}
70
		
71
		public StringTextBufferStrategy()
72
		{
73
		}
74
		
75
		public static ITextBufferStrategy CreateTextBufferFromFile(string fileName)
76
		{
77
			if (!File.Exists(fileName)) {
78
				throw new System.IO.FileNotFoundException(fileName);
79
			}
80
			StringTextBufferStrategy s = new StringTextBufferStrategy();
81
			s.SetContent(Util.FileReader.ReadFileContent(fileName, Encoding.Default));
82
			return s;
83
		}
84
	}
85
}