本文整理汇总了C#中ITextSource.GetCharAt方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSource.GetCharAt方法的具体用法?C# ITextSource.GetCharAt怎么用?C# ITextSource.GetCharAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITextSource
的用法示例。
在下文中一共展示了ITextSource.GetCharAt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: NextNewLine
/// <summary>
/// Gets the location of the next new line character, or SimpleSegment.Invalid
/// if none is found.
/// </summary>
internal static SimpleSegment NextNewLine(ITextSource text, int offset)
{
int textLength = text.TextLength;
int pos = text.IndexOfAny(newline, offset, textLength - offset);
if (pos >= 0) {
if (text.GetCharAt(pos) == '\r') {
if (pos + 1 < textLength && text.GetCharAt(pos + 1) == '\n')
return new SimpleSegment(pos, 2);
}
return new SimpleSegment(pos, 1);
}
return SimpleSegment.Invalid;
}
示例2: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding" />s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
var newFoldings = new List<NewFolding>();
var startOffsets = new Stack<int>();
var lastNewLineOffset = 0;
var openingBrace = OpeningBrace;
var closingBrace = ClosingBrace;
for (var i = 0; i < document.TextLength; i++)
{
var c = document.GetCharAt(i);
if (c == openingBrace)
startOffsets.Push(i);
else if (c == closingBrace && startOffsets.Count > 0)
{
var startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset)
newFoldings.Add(new NewFolding(startOffset, i + 1));
}
else if (c == '\n' || c == '\r')
lastNewLineOffset = i + 1;
}
newFoldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
return newFoldings;
}
示例3: getOffsets
protected IEnumerable<NewFolding> getOffsets(char opening, char closing, ITextSource document)
{
List<NewFolding> ret = new List<NewFolding>();
Stack<int> openings = new Stack<int>();
bool multiline = false; //flag of multiline braces
for(int pos = 0; pos < document.TextLength; ++pos)
{
char c = document.GetCharAt(pos);
if(c == opening) {
openings.Push(pos + 1);
multiline = false;
}
else if(char.IsControl(c)) {
multiline = true;
}
else if(openings.Count > 0 && c == closing)
{
int offset = openings.Pop();
if(multiline) {
ret.Add(new NewFolding(offset, pos));
}
}
}
return ret;
}
示例4: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding"/>s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
List<NewFolding> newFoldings = new List<NewFolding>();
Stack<int> startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
char openingBrace = this.OpeningBrace;
char closingBrace = this.ClosingBrace;
for (int i = 0; i < document.TextLength; i++)
{
char c = document.GetCharAt(i);
bool isFirstInLine = IsFirstInLine(document, i);
if (c == openingBrace && isFirstInLine)
startOffsets.Push(i);
else if (c == closingBrace && isFirstInLine && startOffsets.Count > 0)
{
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset)
newFoldings.Add(new NewFolding(startOffset, i + 1));
}
else if (c == '\n' || c == '\r')
{
lastNewLineOffset = i + 1;
}
}
newFoldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
return newFoldings;
}
示例5: FindNextNewLine
/// <summary>
/// Finds the next new line character starting at offset.
/// </summary>
/// <param name="text">The text source to search in.</param>
/// <param name="offset">The starting offset for the search.</param>
/// <param name="newLineType">The string representing the new line that was found, or null if no new line was found.</param>
/// <returns>The position of the first new line starting at or after <paramref name="offset"/>,
/// or -1 if no new line was found.</returns>
public static int FindNextNewLine(ITextSource text, int offset, out string newLineType)
{
if (text == null)
throw new ArgumentNullException(nameof(text));
if (offset < 0 || offset > text.TextLength)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "offset is outside of text source");
SimpleSegment s = NewLineFinder.NextNewLine(text, offset);
if (s == SimpleSegment.Invalid)
{
newLineType = null;
return -1;
}
else
{
if (s.Length == 2)
{
newLineType = "\r\n";
}
else if (text.GetCharAt(s.Offset) == '\n')
{
newLineType = "\n";
}
else
{
newLineType = "\r";
}
return s.Offset;
}
}
示例6: GetSingleIndentationSegment
/// <summary>
/// Gets a single indentation segment starting at <paramref name="offset" /> - at most one tab
/// or <paramref name="indentationSize" /> spaces.
/// </summary>
/// <param name="textSource">The text source.</param>
/// <param name="offset">The offset where the indentation segment starts.</param>
/// <param name="indentationSize">The size of an indentation unit. See <see cref="TextEditorOptions.IndentationSize" />.</param>
/// <returns>
/// The indentation segment.
/// If there is no indentation character at the specified <paramref name="offset" />,
/// an empty segment is returned.
/// </returns>
public static ISegment GetSingleIndentationSegment(ITextSource textSource, int offset, int indentationSize)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
var pos = offset;
while (pos < textSource.TextLength)
{
var c = textSource.GetCharAt(pos);
if (c == '\t')
{
if (pos == offset)
return new SimpleSegment(offset, 1);
break;
}
if (c == ' ')
{
if (pos - offset >= indentationSize)
break;
}
else
{
break;
}
// continue only if c==' ' and (pos-offset)<tabSize
pos++;
}
return new SimpleSegment(offset, pos - offset);
}
示例7: CreateNewFoldings
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
if (document == null)
throw new ArgumentNullException("document");
var newFoldings = new List<NewFolding>();
var startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
char openingBrace = OpeningBrace;
char closingBrace = ClosingBrace;
for (int i = 0; i < document.TextLength; i++)
{
char c = document.GetCharAt(i);
if (c == openingBrace)
{
startOffsets.Push(i);
}
else if (c == closingBrace && startOffsets.Count > 0)
{
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset)
{
newFoldings.Add(new NewFolding(startOffset, i + 1));
}
}
else if (c == '\n' || c == '\r')
{
lastNewLineOffset = i + 1;
}
}
newFoldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
return newFoldings;
}
示例8: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding"/>s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
List<NewFolding> newFoldings = new List<NewFolding>();
Stack<int> startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
for (int i = 0; i < document.TextLength-2; i++) {
char c = document.GetCharAt(i);
char c1 = document.GetCharAt(i+1);
char c2 = document.GetCharAt(i+2);
if ((c1 == '(' && (c == 'U' || c == 'O' || c == 'X')) || (c2 == '(' && c1=='N' && (c == 'U' || c == 'O' || c == 'X')))
{
startOffsets.Push(i);
} else if (c == ')' && startOffsets.Count > 0) {
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset) {
newFoldings.Add(new NewFolding(startOffset, i + 1));
}
} else if (c == '\n' || c == '\r') {
lastNewLineOffset = i + 1;
}
}
int wrt = document.Text.IndexOf("Netzwerk");
//try
{
while (wrt >= 0)
{
int old = wrt;
wrt = document.Text.IndexOf("Netzwerk", wrt + 1);
if (wrt > old)
newFoldings.Add(new NewFolding(old, wrt - 2));
else
{
newFoldings.Add(new NewFolding(old, document.Text.Length));
break;
}
}
}
//catch (Exception)
{}
newFoldings.Sort((a,b) => a.StartOffset.CompareTo(b.StartOffset));
return newFoldings;
}
示例9: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding"/>s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
List<NewFolding> newFoldings = new List<NewFolding>();
Stack<int> startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
char openingBrace = OpeningBrace;
char closingBrace = ClosingBrace;
foreach (var startKeyword in foldingKeywords.Keys)
{
int lastKeywordPos = 0;
int pos = 0;
while ((pos = document.Text.IndexOf(startKeyword, pos)) > lastKeywordPos)
{
int endOffset = document.Text.IndexOf(foldingKeywords[startKeyword], pos);
if (endOffset > pos)
{
var offset = document.Text.IndexOf("\r\n", pos);
var name = document.Text.Substring(pos + 8, offset - (pos + 8));
var folding = new NewFolding(pos, endOffset + 10);
folding.Name = name;
// Add the folding
newFoldings.Add(folding);
}
lastKeywordPos = pos;
}
}
for (int i = 0; i < document.TextLength; i++)
{
char c = document.GetCharAt(i);
if (c == openingBrace)
{
startOffsets.Push(i);
}
else if (c == closingBrace && startOffsets.Count > 0)
{
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset)
{
newFoldings.Add(new NewFolding(startOffset, i + 1));
}
}
else if (c == '\n' || c == '\r')
{
lastNewLineOffset = i + 1;
}
}
newFoldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
return newFoldings;
}
示例10: FindEndOfIdentifier
/// <summary>
/// Finds the end of the identifier at the given offset.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="offset">The offset.</param>
/// <returns>
/// The offset of the last character of the identifier; or -1 if there is no identifier at
/// the specified offset.
/// </returns>
/// <remarks>
/// <para>
/// An identifier is a single word consisting of letters, digits, or underscores. An
/// identifier must start with a letter or underscore.
/// </para>
/// <para>
/// <strong>Important:</strong> This method does not guarantee that the word at
/// <paramref name="offset"/> is an identifier - it could also be a number instead of an
/// identifier. To make sure that the current word is really an identifier, you should
/// search for the start of the identifier and check whether it starts with a letter or
/// underscore.
/// </para>
/// </remarks>
public static int FindEndOfIdentifier(ITextSource document, int offset)
{
if (offset < 0 || offset >= document.TextLength)
return -1;
if (!IsIdentifierPart(document.GetCharAt(offset)))
{
// Character at offset is does not belong to an identifier.
return -1;
}
// Search forward
while (offset + 1 < document.TextLength && IsIdentifierPart(document.GetCharAt(offset + 1)))
++offset;
return offset;
}
示例11: NextNewLine
/// <summary>
/// Gets the location of the next new line character, or SimpleSegment.Invalid
/// if none is found.
/// </summary>
internal static SimpleSegment NextNewLine(ITextSource text, int offset)
{
int textLength = text.TextLength;
for (int i = offset; i < textLength; i++) {
switch (text.GetCharAt(i)) {
case '\r':
if (i + 1 < textLength) {
if (text.GetCharAt(i + 1) == '\n') {
return new SimpleSegment(i, 2);
}
}
goto case '\n';
case '\n':
return new SimpleSegment(i, 1);
}
}
return SimpleSegment.Invalid;
}
示例12: ReadOnlyDocument
/// <summary>
/// Creates a new ReadOnlyDocument from the given text source.
/// </summary>
public ReadOnlyDocument(ITextSource textSource)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
// ensure that underlying buffer is immutable
this.textSource = textSource.CreateSnapshot();
List<int> lines = new List<int>();
lines.Add(0);
int offset = 0;
int textLength = textSource.TextLength;
while ((offset = textSource.IndexOfAny(newline, offset, textLength - offset)) >= 0) {
offset++;
if (textSource.GetCharAt(offset - 1) == '\r' && offset < textLength && textSource.GetCharAt(offset) == '\n') {
offset++;
}
lines.Add(offset);
}
this.lines = lines.ToArray();
}
示例13: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding"/>s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
Stack<int> startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
char openingBrace = this.OpeningBrace;
char closingBrace = this.ClosingBrace;
for (int i = 0; i < document.TextLength; i++) {
char c = document.GetCharAt(i);
if (c == openingBrace) {
startOffsets.Push(i);
} else if (c == closingBrace && startOffsets.Count > 0) {
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if (startOffset < lastNewLineOffset) {
yield return new NewFolding(startOffset, i + 1);
}
} else if (c == '\n' || c == '\r') {
lastNewLineOffset = i + 1;
}
}
}
示例14: QuickSearchBracketForward
private static int QuickSearchBracketForward(ITextSource document, int offset, char openBracket,
char closingBracket)
{
var num = 1;
int result;
for (var i = offset; i < document.TextLength; i++)
{
var charAt = document.GetCharAt(i);
if (charAt == openBracket)
{
num++;
}
else
{
if (charAt == closingBracket)
{
num--;
if (num == 0)
{
result = i;
return result;
}
}
else
{
if (charAt == '"')
{
break;
}
if (charAt == '\'')
{
break;
}
if (charAt == '/' && i > 0)
{
if (document.GetCharAt(i - 1) == '/')
{
break;
}
}
else
{
if (charAt == '*' && i > 0)
{
if (document.GetCharAt(i - 1) == '/')
{
break;
}
}
}
}
}
}
result = -1;
return result;
}
示例15: GetXmlIdentifierBeforeIndex
public static string GetXmlIdentifierBeforeIndex(ITextSource document, int index)
{
if (document == null)
throw new ArgumentNullException("document");
if (index < 0 || index > document.TextLength)
throw new ArgumentOutOfRangeException("index", index, "Value must be between 0 and " + document.TextLength);
int i = index - 1;
while (i >= 0 && IsXmlNameChar(document.GetCharAt(i)) && document.GetCharAt(i) != '/')
i--;
return document.GetText(i + 1, index - i - 1);
}