// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt) // This code is distributed under MIT license (for details please see \doc\license.txt) using System; using System.IO; namespace ICSharpCode.Editor { /// /// Implements the ITextSource interface using a string. /// [Serializable] public class StringTextSource : ITextSource { readonly string text; /// /// Creates a new StringTextSource with the given text. /// public StringTextSource(string text) { if (text == null) throw new ArgumentNullException("text"); this.text = text; } ITextSourceVersion ITextSource.Version { get { return null; } } /// public int TextLength { get { return text.Length; } } /// public string Text { get { return text; } } /// public ITextSource CreateSnapshot() { return this; // StringTextBuffer is immutable } /// public ITextSource CreateSnapshot(int offset, int length) { return new StringTextSource(text.Substring(offset, length)); } /// public TextReader CreateReader() { return new StringReader(text); } /// public TextReader CreateReader(int offset, int length) { return new StringReader(text.Substring(offset, length)); } /// public char GetCharAt(int offset) { return text[offset]; } /// public string GetText(int offset, int length) { return text.Substring(offset, length); } /// public string GetText(ISegment segment) { if (segment == null) throw new ArgumentNullException("segment"); return text.Substring(segment.Offset, segment.Length); } /// public int IndexOfAny(char[] anyOf, int startIndex, int count) { return text.IndexOfAny(anyOf, startIndex, count); } } }