Browse Source

Add WriteTextTo() method to ITextSource.

newNRvisualizers
Daniel Grunwald 13 years ago
parent
commit
7a3b25b4dc
  1. 10
      ICSharpCode.NRefactory/Editor/ITextSource.cs
  2. 12
      ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs
  3. 34
      ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs
  4. 12
      ICSharpCode.NRefactory/Editor/StringTextSource.cs

10
ICSharpCode.NRefactory/Editor/ITextSource.cs

@ -94,6 +94,16 @@ namespace ICSharpCode.NRefactory.Editor @@ -94,6 +94,16 @@ namespace ICSharpCode.NRefactory.Editor
/// <exception cref="ArgumentOutOfRangeException">offset or length is outside the valid range.</exception>
string GetText(ISegment segment);
/// <summary>
/// Writes the text from this document into the TextWriter.
/// </summary>
void WriteTextTo(TextWriter writer);
/// <summary>
/// Writes the text from this document into the TextWriter.
/// </summary>
void WriteTextTo(TextWriter writer, int offset, int length);
/// <summary>
/// Gets the index of the first occurrence of the character in the specified array.
/// </summary>

12
ICSharpCode.NRefactory/Editor/ReadOnlyDocument.cs

@ -359,6 +359,18 @@ namespace ICSharpCode.NRefactory.Editor @@ -359,6 +359,18 @@ namespace ICSharpCode.NRefactory.Editor
return textSource.CreateReader(offset, length);
}
/// <inheritdoc/>
public void WriteTextTo(System.IO.TextWriter writer)
{
textSource.WriteTextTo(writer);
}
/// <inheritdoc/>
public void WriteTextTo(System.IO.TextWriter writer, int offset, int length)
{
textSource.WriteTextTo(writer, offset, length);
}
/// <inheritdoc/>
public char GetCharAt(int offset)
{

34
ICSharpCode.NRefactory/Editor/StringBuilderDocument.cs

@ -41,11 +41,27 @@ namespace ICSharpCode.NRefactory.Editor @@ -41,11 +41,27 @@ namespace ICSharpCode.NRefactory.Editor
b = new StringBuilder();
}
/// <summary>
/// Creates a new StringBuilderDocument with the specified initial text.
/// </summary>
public StringBuilderDocument(string text)
{
if (text == null)
throw new ArgumentNullException("text");
b = new StringBuilder(text);
}
/// <summary>
/// Creates a new StringBuilderDocument with the initial text copied from the specified text source.
/// </summary>
public StringBuilderDocument(ITextSource textSource)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
b = new StringBuilder(textSource.TextLength);
textSource.WriteTextTo(new StringWriter(b));
}
/// <inheritdoc/>
public event EventHandler<TextChangeEventArgs> TextChanging;
@ -273,6 +289,22 @@ namespace ICSharpCode.NRefactory.Editor @@ -273,6 +289,22 @@ namespace ICSharpCode.NRefactory.Editor
{
return new StringReader(GetText(offset, length));
}
/// <inheritdoc/>
public void WriteTextTo(TextWriter writer)
{
if (writer == null)
throw new ArgumentNullException("writer");
writer.Write(this.Text);
}
/// <inheritdoc/>
public void WriteTextTo(TextWriter writer, int offset, int length)
{
if (writer == null)
throw new ArgumentNullException("writer");
writer.Write(GetText(offset, length));
}
#endregion
#region GetText / IndexOf
@ -310,6 +342,8 @@ namespace ICSharpCode.NRefactory.Editor @@ -310,6 +342,8 @@ namespace ICSharpCode.NRefactory.Editor
/// <inheritdoc/>
public string GetText(ISegment segment)
{
if (segment == null)
throw new ArgumentNullException("segment");
return b.ToString(segment.Offset, segment.Length);
}

12
ICSharpCode.NRefactory/Editor/StringTextSource.cs

@ -95,6 +95,18 @@ namespace ICSharpCode.NRefactory.Editor @@ -95,6 +95,18 @@ namespace ICSharpCode.NRefactory.Editor
return new StringReader(text.Substring(offset, length));
}
/// <inheritdoc/>
public void WriteTextTo(TextWriter writer)
{
writer.Write(text);
}
/// <inheritdoc/>
public void WriteTextTo(TextWriter writer, int offset, int length)
{
writer.Write(text.Substring(offset, length));
}
/// <inheritdoc/>
public char GetCharAt(int offset)
{

Loading…
Cancel
Save