本文整理汇总了C#中IDocument.GetLineSegmentForOffset方法的典型用法代码示例。如果您正苦于以下问题:C# IDocument.GetLineSegmentForOffset方法的具体用法?C# IDocument.GetLineSegmentForOffset怎么用?C# IDocument.GetLineSegmentForOffset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IDocument
的用法示例。
在下文中一共展示了IDocument.GetLineSegmentForOffset方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindWordEnd
static int FindWordEnd(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
offset = Math.Min(offset, endPos - 1);
if (IsSelectableChar(document.GetCharAt(offset)))
{
while (offset < endPos && IsSelectableChar(document.GetCharAt(offset)))
{
++offset;
}
}
else if (Char.IsWhiteSpace(document.GetCharAt(offset)))
{
if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)))
{
while (offset < endPos && Char.IsWhiteSpace(document.GetCharAt(offset)))
{
++offset;
}
}
}
else
{
return Math.Max(0, offset + 1);
}
return offset;
}
示例2: FindWordEnd
public static int FindWordEnd(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
while (offset < endPos && IsLetterDigitOrUnderscore(document.GetCharAt(offset))) {
++offset;
}
return offset;
}
示例3: FindNext
static int FindNext(IDocument document, int offset, char ch)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
while (offset < endPos && document.GetCharAt(offset) != ch)
++offset;
return offset;
}
示例4: FindNextWordStart
// go forward to the start of the next word
// if the cursor is at the start or in the middle of a word we move to the end of the word
// and then past any whitespace that follows it
// if the cursor is at the start or in the middle of some whitespace we move to the start of the
// next word
public static int FindNextWordStart(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
// lets go to the end of the word, whitespace or operator
CharacterType t = GetCharacterType(document.GetCharAt(offset));
while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == t) {
++offset;
}
// now we're at the end of the word, lets find the start of the next one by skipping whitespace
while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == CharacterType.WhiteSpace) {
++offset;
}
return offset;
}
示例5: FindPrevWordStart
// go back to the start of the word we are on
// if we are already at the start of a word or if we are in whitespace, then go back
// to the start of the previous word
public static int FindPrevWordStart(IDocument document, int offset)
{
if (offset > 0) {
LineSegment line = document.GetLineSegmentForOffset(offset);
CharacterType t = GetCharacterType(document.GetCharAt(offset - 1));
while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t) {
--offset;
}
// if we were in whitespace, and now we're at the end of a word or operator, go back to the beginning of it
if(t == CharacterType.WhiteSpace && offset > line.Offset) {
t = GetCharacterType(document.GetCharAt(offset - 1));
while (offset > line.Offset && GetCharacterType(document.GetCharAt(offset - 1)) == t) {
--offset;
}
}
}
return offset;
}
示例6: FindWordStart
int FindWordStart(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
if (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && Char.IsWhiteSpace(document.GetCharAt(offset))) {
while (offset > line.Offset && Char.IsWhiteSpace(document.GetCharAt(offset - 1))) {
--offset;
}
} else if (IsSelectableChar(document.GetCharAt(offset)) || (offset > 0 && Char.IsWhiteSpace(document.GetCharAt(offset)) && IsSelectableChar(document.GetCharAt(offset - 1)))) {
while (offset > line.Offset && IsSelectableChar(document.GetCharAt(offset - 1))) {
--offset;
}
} else {
if (offset > 0 && !Char.IsWhiteSpace(document.GetCharAt(offset - 1)) && !IsSelectableChar(document.GetCharAt(offset - 1)) ) {
return Math.Max(0, offset - 1);
}
}
return offset;
}
示例7: FindWordStart
public static int FindWordStart(IDocument document, int offset)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
int lineOffset = line.Offset;
while (offset > lineOffset && IsLetterDigitOrUnderscore(document.GetCharAt(offset - 1))) {
--offset;
}
return offset;
}
示例8: FindNextWordStart
/// <summary>
/// Finds the offset where the next word starts.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="offset">The offset.</param>
/// <returns>The start of the next word after <paramref name="offset"/>.</returns>
public static int FindNextWordStart(IDocument document, int offset)
{
// go forward to the start of the next word
// if the cursor is at the start or in the middle of a word we move to the end of the word
// and then past any whitespace that follows it
// if the cursor is at the start or in the middle of some whitespace we move to the start of the
// next word
int originalOffset = offset;
LineSegment line = document.GetLineSegmentForOffset(offset);
int endPos = line.Offset + line.Length;
// lets go to the end of the word, whitespace or operator
CharacterType t = GetCharacterType(document.GetCharAt(offset));
while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == t)
{
++offset;
}
// now we're at the end of the word, lets find the start of the next one by skipping whitespace
while (offset < endPos && GetCharacterType(document.GetCharAt(offset)) == CharacterType.WhiteSpace)
{
++offset;
}
return offset;
}
示例9: SkipComment
/// <summary>
/// Skips any comments that start at the current offset.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="offset">The offset.</param>
/// <returns>The index of the next character after the comments.</returns>
private static int SkipComment(IDocument document, int offset)
{
if (offset >= document.TextLength - 1)
return offset + 1;
char current = document.GetCharAt(offset);
char next = document.GetCharAt(offset + 1);
if (current == '/' && next == '/')
{
// Skip line comment "//"
LineSegment line = document.GetLineSegmentForOffset(offset);
int offsetOfNextLine = line.Offset + line.TotalLength;
return offsetOfNextLine;
}
else if (current == '/' && next == '*')
{
// Skip block comment "/* ... */"
offset += 2;
while (offset + 1 < document.TextLength)
{
if (document.GetCharAt(offset) == '*' && document.GetCharAt(offset + 1) == '/')
{
offset = offset + 2;
break;
}
offset++;
}
return offset;
}
else
{
return offset + 1;
}
}
示例10: MarkRegion
/// <summary>
/// Marks the region that starts at the given offset.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="offset">The offset.</param>
/// <param name="folds">The fold markers.</param>
/// <returns>The index of the next character after the region.</returns>
private static int MarkRegion(IDocument document, int offset, List<Fold> folds)
{
if (offset >= document.TextLength)
return offset;
if (document.GetCharAt(offset) == '#')
{
int startOffset = offset;
offset++;
string word = TextHelper.GetIdentifierAt(document, offset);
if (word == "region")
{
offset += "region".Length;
// Find label
LineSegment line = document.GetLineSegmentForOffset(offset);
int lineEnd = line.Offset + line.Length;
int labelLength = lineEnd - offset;
string label = document.GetText(offset, labelLength);
label = label.Trim();
if (label.Length == 0)
label = "#region";
// Find and mark subregions
offset = FindAndMarkRegions(document, lineEnd, folds);
if (offset <= document.TextLength)
{
int length = offset - startOffset;
folds.Add(new Fold(document, startOffset, length, label, true));
offset++;
}
}
}
else
{
offset++;
}
return offset;
}
示例11: FindPrevWordStart
/// <summary>
/// Finds the start offset the word at or before the specified offset.
/// </summary>
/// <param name="document">The document.</param>
/// <param name="offset">The offset.</param>
/// <returns>The start of the word before <paramref name="offset"/>.</returns>
public static int FindPrevWordStart(IDocument document, int offset)
{
// go back to the start of the word we are on
// if we are already at the start of a word or if we are in whitespace, then go back
// to the start of the previous word
if (offset > 0)
{
LineSegment line = document.GetLineSegmentForOffset(offset);
CharacterType charType = GetCharacterType(document.GetCharAt(offset - 1));
int lineOffset = line.Offset;
while (offset > lineOffset && GetCharacterType(document.GetCharAt(offset - 1)) == charType)
--offset;
// if we were in whitespace, and now we're at the end of a word or operator, go back to the beginning of it
if (charType == CharacterType.WhiteSpace && offset > lineOffset)
{
charType = GetCharacterType(document.GetCharAt(offset - 1));
while (offset > lineOffset && GetCharacterType(document.GetCharAt(offset - 1)) == charType)
--offset;
}
}
return offset;
}
示例12: 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(IDocument document, int offset)
{
if (!IsPartOfIdentifier(document.GetCharAt(offset)))
{
// Character at offset is does not belong to an identifier.
return -1;
}
// Search forward
LineSegment line = document.GetLineSegmentForOffset(offset);
int lineEnd = line.Offset + line.Length;
while (offset + 1 < lineEnd && IsPartOfIdentifier(document.GetCharAt(offset + 1)))
++offset;
return offset;
}
示例13: FindStartOfIdentifier
/// <summary>
/// Finds the start 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 first 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>
/// </remarks>
public static int FindStartOfIdentifier(IDocument document, int offset)
{
if (offset < 0 || document.TextLength <= offset)
return -1;
if (!IsPartOfIdentifier(document.GetCharAt(offset)))
{
// Character at offset is does not belong to an identifier.
return -1;
}
// Search backwards
LineSegment line = document.GetLineSegmentForOffset(offset);
int lineOffset = line.Offset;
while (offset > lineOffset && IsPartOfIdentifier(document.GetCharAt(offset - 1)))
--offset;
// Check if first character is the start of an identifier.
// (We need to make sure that it is not a number.)
char startCharacter = document.GetCharAt(offset);
if (Char.IsLetter(startCharacter) || startCharacter == '_')
return offset;
else
return -1;
}