本文整理汇总了C#中IDocument.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetText方法的具体用法?C# IDocument.GetText怎么用?C# IDocument.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetText方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DrawableLine
public DrawableLine(IDocument document, LineSegment line, Font monospacedFont, Font boldMonospacedFont)
{
this.monospacedFont = monospacedFont;
this.boldMonospacedFont = boldMonospacedFont;
if (line.Words != null)
{
foreach (TextWord word in line.Words)
{
if (word.Type == TextWordType.Space)
{
words.Add(SimpleTextWord.Space);
}
else if (word.Type == TextWordType.Tab)
{
words.Add(SimpleTextWord.Tab);
}
else
{
words.Add(new SimpleTextWord(TextWordType.Word, word.Word, word.Bold, word.Color));
}
}
}
else
{
words.Add(new SimpleTextWord(TextWordType.Word, document.GetText(line), false, Color.Black));
}
}
示例2: GenerateFoldMarkers
/// <summary>
/// Generates the foldings for our document.
/// </summary>
/// <param name="document">The current document.</param>
/// <param name="fileName">The filename of the document.</param>
/// <param name="parseInformation">Extra parse information, not used in this sample.</param>
/// <returns>A list of FoldMarkers.</returns>
public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
{
List<FoldMarker> list = new List<FoldMarker>();
Stack<int> startLines = new Stack<int>();
// Create foldmarkers for the whole document, enumerate through every line.
for (int i = 0; i < document.TotalNumberOfLines; i++)
{
LineSegment seg = document.GetLineSegment(i);
int offs, end = document.TextLength;
char c;
for (offs = seg.Offset; offs < end && ((c = document.GetCharAt(offs)) == ' ' || c == '\t'); offs++)
{ }
if (offs == end)
break;
int spaceCount = offs - seg.Offset;
// now offs points to the first non-whitespace char on the line
if (document.GetCharAt(offs) == '#')
{
string text = document.GetText(offs, seg.Length - spaceCount);
if (text.StartsWith("#region"))
startLines.Push(i);
if (text.StartsWith("#endregion") && startLines.Count > 0)
{
// Add a new FoldMarker to the list.
int start = startLines.Pop();
list.Add(new FoldMarker(document, start, document.GetLineSegment(start).Length, i, spaceCount + "#endregion".Length));
}
}
}
return list;
}
示例3: GenerateFoldMarkers
public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
{
List<FoldMarker> list = new List<FoldMarker>();
string name = string.Empty;
int start = 0;
int startindex = 0;
for (int i = 0; i < document.TotalNumberOfLines; i++)
{
string text = document.GetText(document.GetLineSegment(i));
Match startmatch = startrxp.Match(text);
if (startmatch.Success)
{
name = startmatch.Groups[gpname].Value;
startindex = startmatch.Groups[gpregion].Index - 1;
start = i;
}
else if (endrxp.IsMatch(text))
{
list.Add(new FoldMarker(document, start, startindex, i, document.GetLineSegment(i).Length, FoldType.Region, name, true));
}
}
return list;
}
示例4: GenerateFoldMarkers
/// <summary>
/// Generates the foldings for our document.
/// </summary>
/// <param name="document">The current document.</param>
/// <param name="fileNameEx">The filename of the document.</param>
/// <param name="parseInformation">Extra parse information, not used in this sample.</param>
/// <returns>A list of FoldMarkers.</returns>
public List<FoldMarker> GenerateFoldMarkers(IDocument document, string fileName, object parseInformation)
{
List<FoldMarker> list = new List<FoldMarker>();
int start = 0;
// Create foldmarkers for the whole document, enumerate through every line.
for (int i = 0; i < document.TotalNumberOfLines; i++)
{
// Get the text of current line.
string text = document.GetText(document.GetLineSegment(i));
if (text.StartsWith("#region")) // Look for method starts
start = i;
if (text.StartsWith("#endregion")) // Look for method endings
// Add a new FoldMarker to the list.
// document = the current document
// start = the start line for the FoldMarker
// document.GetLineSegment(start).Length = the ending of the current line = the start column of our foldmarker.
// i = The current line = end line of the FoldMarker.
// 7 = The end column
list.Add(new FoldMarker(document, start, document.GetLineSegment(start).Length, i, 7));
}
return list;
}
示例5: SortLines
public void SortLines(IDocument document, int startLine, int endLine, StringComparer comparer, bool removeDuplicates)
{
List<string> lines = new List<string>();
for (int i = startLine; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(i);
lines.Add(document.GetText(line.Offset, line.Length));
}
lines.Sort(comparer);
if (removeDuplicates) {
lines = lines.Distinct(comparer).ToList();
}
using (document.OpenUndoGroup()) {
for (int i = 0; i < lines.Count; ++i) {
IDocumentLine line = document.GetLine(startLine + i);
document.Replace(line.Offset, line.Length, lines[i]);
}
// remove removed duplicate lines
for (int i = startLine + lines.Count; i <= endLine; ++i) {
IDocumentLine line = document.GetLine(startLine + lines.Count);
document.Remove(line.Offset, line.TotalLength);
}
}
}
示例6: ConvertTextDocumentToBlock
/// <summary>
/// Converts a readonly TextDocument to a Block and applies the provided highlighter.
/// </summary>
public static Block ConvertTextDocumentToBlock(IDocument document, IHighlighter highlighter)
{
if (document == null)
throw new ArgumentNullException("document");
// Table table = new Table();
// table.Columns.Add(new TableColumn { Width = GridLength.Auto });
// table.Columns.Add(new TableColumn { Width = new GridLength(1, GridUnitType.Star) });
// TableRowGroup trg = new TableRowGroup();
// table.RowGroups.Add(trg);
Paragraph p = new Paragraph();
p.TextAlignment = TextAlignment.Left;
for (int lineNumber = 1; lineNumber <= document.LineCount; lineNumber++) {
if (lineNumber > 1)
p.Inlines.Add(new LineBreak());
var line = document.GetLineByNumber(lineNumber);
// TableRow row = new TableRow();
// trg.Rows.Add(row);
// row.Cells.Add(new TableCell(new Paragraph(new Run(lineNumber.ToString()))) { TextAlignment = TextAlignment.Right });
// Paragraph p = new Paragraph();
// row.Cells.Add(new TableCell(p));
if (highlighter != null) {
HighlightedLine highlightedLine = highlighter.HighlightLine(lineNumber);
p.Inlines.AddRange(highlightedLine.ToRichText().CreateRuns());
} else {
p.Inlines.Add(document.GetText(line));
}
}
return p;
}
示例7: IsBracketOnly
bool IsBracketOnly(IDocument document, IDocumentLine documentLine)
{
string lineText = document.GetText(documentLine).Trim();
return lineText == "{" || string.IsNullOrEmpty(lineText)
|| lineText.StartsWith("//", StringComparison.Ordinal)
|| lineText.StartsWith("/*", StringComparison.Ordinal)
|| lineText.StartsWith("*", StringComparison.Ordinal)
|| lineText.StartsWith("'", StringComparison.Ordinal);
}
示例8: CreateRefactoringWarningMessage
public static IRefactoringWarningMessage CreateRefactoringWarningMessage(IDocument document, CodeIssue issue, ICodeIssueComputer computer)
{
var instance = new RefactoringWarningMessage
{
File = document.Name,
Line = document.GetText().GetLineFromPosition(issue.TextSpan.Start).LineNumber,
Description = issue.Description,
CodeIssueComputer = computer
};
return instance;
}
示例9: Convert
protected override void Convert(IDocument document, int startOffset, int length)
{
StringBuilder what = new StringBuilder(document.GetText(startOffset, length));
for (int i = 0; i < what.Length; ++i) {
if (!Char.IsLetter(what[i]) && i < what.Length - 1) {
what[i + 1] = Char.ToUpper(what[i + 1]);
}
}
document.Replace(startOffset, length, what.ToString());
}
示例10: DocumentTextWriter
/// <summary>
/// Creates a new DocumentTextWriter that inserts into document, starting at insertionOffset.
/// </summary>
public DocumentTextWriter(IDocument document, int insertionOffset)
{
this.insertionOffset = insertionOffset;
if (document == null)
throw new ArgumentNullException("document");
this.document = document;
var line = document.GetLineByOffset(insertionOffset);
if (line.DelimiterLength == 0)
line = line.PreviousLine;
if (line != null)
this.NewLine = document.GetText(line.EndOffset, line.DelimiterLength);
}
示例11: AddFold
/// <summary>
/// Adds a fold for the specified tag spanning the specified lines.
/// </summary>
/// <remarks>
/// This method is called by the <see cref="XmlParser"/> whenever a complete tag is found.
/// </remarks>
/// <param name="p_docDocument">The document in which to make the fold.</param>
/// <param name="p_strTagName">The name of the tag being folded.</param>
/// <param name="p_tlcStart">The location of the start of the tag.</param>
/// <param name="p_tlcEnd">The location of the closing tag.</param>
protected void AddFold(IDocument p_docDocument, string p_strTagName, TextLocation p_tlcStart, TextLocation p_tlcEnd)
{
if (p_tlcStart.Line == p_tlcEnd.Line)
return;
string strStartLine = p_docDocument.GetText(p_docDocument.GetLineSegment(p_tlcStart.Line));
Int32 intStartFoldPos = strStartLine.IndexOf(">", p_tlcStart.Column);
if (intStartFoldPos < 0)
intStartFoldPos = strStartLine.Length;
else
intStartFoldPos++;
m_lstFolds.Add(new FoldMarker(p_docDocument, p_tlcStart.Line, intStartFoldPos, p_tlcEnd.Line, p_tlcEnd.Column - 1));
}
示例12: GetLineTerminator
/// <summary>
/// Gets the line terminator for the document around the specified line number.
/// </summary>
public static string GetLineTerminator(IDocument document, int lineNumber)
{
IDocumentLine line = document.GetLineByNumber(lineNumber);
if (line.DelimiterLength == 0) {
// at the end of the document, there's no line delimiter, so use the delimiter
// from the previous line
if (lineNumber == 1)
return Environment.NewLine;
line = document.GetLineByNumber(lineNumber - 1);
}
return document.GetText(line.Offset + line.Length, line.DelimiterLength);
}
示例13: GetAlignedText
public static string GetAlignedText(IDocument document, int startOffset, int endOffset, int maxLineCount = 15)
{
// This fixes SD-1394:
// Each line is checked for leading indentation whitespaces. If
// a line has the same or more indentation than the first line,
// it is reduced. If a line is less indented than the first line
// the indentation is removed completely.
//
// See the following example:
// line 1
// line 2
// line 3
// line 4
//
// is reduced to:
// line 1
// line 2
// line 3
// line 4
if (maxLineCount < 1)
maxLineCount = int.MaxValue;
IDocumentLine startLine = document.GetLineByOffset(startOffset);
IDocumentLine endLine = document.GetLineByOffset(endOffset);
StringBuilder builder = new StringBuilder();
IDocumentLine current = startLine;
ISegment startIndent = TextUtilities.GetWhitespaceAfter(document, startLine.Offset);
int lineCount = 0;
while (current != endLine.NextLine && lineCount < maxLineCount) {
ISegment currentIndent = TextUtilities.GetWhitespaceAfter(document, current.Offset);
if (current == startLine && current == endLine)
builder.Append(document.GetText(startOffset, endOffset - startOffset));
else if (current == startLine) {
if (current.EndOffset - startOffset > 0)
builder.AppendLine(document.GetText(startOffset, current.EndOffset - startOffset).TrimStart());
} else if (current == endLine) {
if (startIndent.Length <= currentIndent.Length)
builder.Append(document.GetText(current.Offset + startIndent.Length, endOffset - current.Offset - startIndent.Length));
else
builder.Append(document.GetText(current.Offset + currentIndent.Length, endOffset - current.Offset - currentIndent.Length));
} else {
if (startIndent.Length <= currentIndent.Length)
builder.AppendLine(document.GetText(current.Offset + startIndent.Length, current.Length - startIndent.Length));
else
builder.AppendLine(document.GetText(current.Offset + currentIndent.Length, current.Length - currentIndent.Length));
}
current = current.NextLine;
lineCount++;
}
if (current != endLine.NextLine)
builder.Append("...");
return builder.ToString();
}
示例14: HighlightLine
/// <summary>
/// Highlights the specified line in the specified document.
///
/// Before calling this method, <see cref="CurrentSpanStack"/> must be set to the proper
/// state for the beginning of this line. After highlighting has completed,
/// <see cref="CurrentSpanStack"/> will be updated to represent the state after the line.
/// </summary>
public HighlightedLine HighlightLine(IDocument document, IDocumentLine line)
{
this.lineStartOffset = line.Offset;
this.lineText = document.GetText(line);
try {
this.highlightedLine = new HighlightedLine(document, line);
HighlightLineInternal();
return this.highlightedLine;
} finally {
this.highlightedLine = null;
this.lineText = null;
this.lineStartOffset = 0;
}
}
示例15: DocumentSequence
public DocumentSequence(IDocument document, Dictionary<string, int> hashDict)
{
this.hashes = new int[document.LineCount];
// Construct a perfect hash for the document lines, and store the 'hash code'
// (really just a unique identifier for each line content) in our array.
for (int i = 1; i <= document.LineCount; i++) {
string text = document.GetText(document.GetLineByNumber(i));
int hash;
if (!hashDict.TryGetValue(text, out hash)) {
hash = hashDict.Count;
hashDict.Add(text, hash);
}
hashes[i - 1] = hash;
}
}