本文整理汇总了C#中TextDocument.GetCharAt方法的典型用法代码示例。如果您正苦于以下问题:C# TextDocument.GetCharAt方法的具体用法?C# TextDocument.GetCharAt怎么用?C# TextDocument.GetCharAt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TextDocument
的用法示例。
在下文中一共展示了TextDocument.GetCharAt方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindNextWordOffset
/// <summary>
/// Move past next whitespace group.
/// </summary>
public override int FindNextWordOffset (TextDocument doc, int offset)
{
int myoffset = offset;
if (0 > myoffset || doc.TextLength-1 <= myoffset){ return myoffset; }
for (char c = doc.GetCharAt (myoffset);
!char.IsWhiteSpace (c) && 0 <= myoffset && doc.TextLength-1 > myoffset;
c = doc.GetCharAt (++myoffset));
for (char c = doc.GetCharAt (myoffset);
char.IsWhiteSpace (c) && 0 <= myoffset && doc.TextLength-1 > myoffset;
c = doc.GetCharAt (++myoffset));
return (myoffset == offset)? myoffset+1: myoffset;
}
示例2: BreakLinesIntoWords
/// <summary>
/// Breaks the lines into words in the form of a list of <see cref="TextSegment">TextSegments</see>. A 'word' is defined as an identifier (a series of letters, digits or underscores)
/// or a single non-identifier character (including white space characters)
/// </summary>
/// <returns>
/// The list of segments representing the 'words' in the lines
/// </returns>
/// <param name='document'>
/// The document to get the words from
/// </param>
/// <param name='startLine'>
/// The first line in the documents to get the words from
/// </param>
/// <param name='lineCount'>
/// The number of lines to get words from
/// </param>
public static List<TextSegment> BreakLinesIntoWords (TextDocument document, int startLine, int lineCount, bool includeDelimiter = true)
{
var result = new List<TextSegment> ();
for (int line = startLine; line < startLine + lineCount; line++) {
var lineSegment = document.GetLine (line);
int offset = lineSegment.Offset;
bool wasIdentifierPart = false;
int lastWordEnd = 0;
for (int i = 0; i < lineSegment.Length; i++) {
char ch = document.GetCharAt (offset + i);
bool isIdentifierPart = char.IsLetterOrDigit (ch) || ch == '_';
if (!isIdentifierPart) {
if (wasIdentifierPart) {
result.Add (new TextSegment (offset + lastWordEnd, i - lastWordEnd));
}
result.Add (new TextSegment (offset + i, 1));
lastWordEnd = i + 1;
}
wasIdentifierPart = isIdentifierPart;
}
if (lastWordEnd != lineSegment.Length) {
result.Add (new TextSegment (offset + lastWordEnd, lineSegment.Length - lastWordEnd));
}
if (includeDelimiter && lineSegment.DelimiterLength > 0)
result.Add (new TextSegment (lineSegment.Offset + lineSegment.Length, lineSegment.DelimiterLength));
}
return result;
}
示例3: AppendHtmlText
static void AppendHtmlText (StringBuilder htmlText, TextDocument doc, ITextEditorOptions options, int start, int end)
{
for (int i = start; i < end; i++) {
char ch = doc.GetCharAt (i);
switch (ch) {
case ' ':
htmlText.Append (" ");
break;
case '\t':
for (int i2 = 0; i2 < options.TabSize; i2++)
htmlText.Append (" ");
break;
case '<':
htmlText.Append ("<");
break;
case '>':
htmlText.Append (">");
break;
case '&':
htmlText.Append ("&");
break;
case '"':
htmlText.Append (""");
break;
default:
htmlText.Append (ch);
break;
}
}
}
示例4: AppendRtfText
static void AppendRtfText (StringBuilder rtfText, TextDocument doc, int start, int end, ref bool appendSpace)
{
for (int i = start; i < end; i++) {
char ch = doc.GetCharAt (i);
switch (ch) {
case '\\':
rtfText.Append (@"\\");
break;
case '{':
rtfText.Append (@"\{");
break;
case '}':
rtfText.Append (@"\}");
break;
case '\t':
rtfText.Append (@"\tab");
appendSpace = true;
break;
default:
if (appendSpace) {
rtfText.Append (' ');
appendSpace = false;
}
rtfText.Append (ch);
break;
}
}
}
示例5: FindNextSubwordOffset
/// <summary>
/// Move to next non-whitespace change in character class.
/// </summary>
public override int FindNextSubwordOffset (TextDocument doc, int offset)
{
int myoffset = offset;
if (0 > myoffset || doc.TextLength-1 <= myoffset){ return myoffset; }
char c = doc.GetCharAt (myoffset);
CharacterClass initialClass = GetCharacterClass (c);
while (GetCharacterClass (c) == initialClass && 0 <= myoffset && doc.TextLength-1 > myoffset) {
c = doc.GetCharAt (++myoffset);
}
for (c = doc.GetCharAt (myoffset);
char.IsWhiteSpace (c) && 0 <= myoffset && doc.TextLength-1 > myoffset;
c = doc.GetCharAt (++myoffset));
return (myoffset == offset)? myoffset+1: myoffset;
}
示例6: GetFoldSegments
static List<FoldSegment> GetFoldSegments (TextDocument doc)
{
List<FoldSegment> result = new List<FoldSegment> ();
Stack<FoldSegment> foldSegments = new Stack<FoldSegment> ();
for (int i = 0; i < doc.TextLength - 1; ++i) {
char ch = doc.GetCharAt (i);
if ((ch == '+' || ch == '-') && doc.GetCharAt(i + 1) == '[') {
FoldSegment segment = new FoldSegment (doc, "...", i, 0, FoldingType.None);
segment.IsFolded = ch == '+';
foldSegments.Push (segment);
} else if (ch == ']' && foldSegments.Count > 0) {
FoldSegment segment = foldSegments.Pop ();
segment.Length = i - segment.Offset;
result.Add (segment);
}
}
return result;
}
示例7: AppendRtfText
static void AppendRtfText (StringBuilder rtfText, TextDocument doc, int start, int end, ref bool appendSpace)
{
for (int i = start; i < end; i++) {
char ch = doc.GetCharAt (i);
switch (ch) {
case '\\':
rtfText.Append (@"\\");
break;
case '{':
rtfText.Append (@"\{");
break;
case '}':
rtfText.Append (@"\}");
break;
case '\t':
rtfText.Append (@"\tab");
appendSpace = true;
break;
default:
if (appendSpace) {
rtfText.Append (' ');
appendSpace = false;
}
int unicodeCh = (int)ch;
if (0x7F < unicodeCh && unicodeCh <= 0xFF) {
rtfText.Append(@"\u" + unicodeCh);
} else if (0xFF < unicodeCh && unicodeCh <= 0x8000) {
rtfText.Append(@"\uc1\u" + unicodeCh + "*");
} else if (0x8000 < unicodeCh && unicodeCh <= 0xFFFF) {
rtfText.Append(@"\uc1\u" + (unicodeCh - 0x10000) + "*");
} else {
rtfText.Append (ch);
}
break;
}
}
}
示例8: GetIndentation
/// <summary>
/// This method gets the line indentation.
/// </summary>
/// <param name="doc">
/// The <see cref="TextDocument"/> the line belongs to.
/// </param>
/// <returns>
/// The indentation of the line (all whitespace chars up to the first non ws char).
/// </returns>
public string GetIndentation(TextDocument doc)
{
var result = new StringBuilder();
int offset = Offset;
int max = System.Math.Min(offset + LengthIncludingDelimiter, doc.TextLength);
for (int i = offset; i < max; i++)
{
char ch = doc.GetCharAt(i);
if (ch != ' ' && ch != '\t')
break;
result.Append(ch);
}
return result.ToString();
}
示例9: FindPrevSubwordOffset
/// <summary>
/// Move to previous non-whitespace change in character class.
/// </summary>
public override int FindPrevSubwordOffset (TextDocument doc, int offset)
{
int myoffset = offset-1;
char c;
if (0 > myoffset || doc.TextLength-1 <= myoffset){ return myoffset; }
for (c = doc.GetCharAt (myoffset);
char.IsWhiteSpace (c) && 0 <= myoffset && doc.TextLength-1 > myoffset;
c = doc.GetCharAt (--myoffset));
CharacterClass initialClass = GetCharacterClass (c);
for (; GetCharacterClass (c) == initialClass &&
0 <= myoffset && doc.TextLength-1 > myoffset;
c = doc.GetCharAt (--myoffset));
return (0 == myoffset)? myoffset: myoffset+1;
}
示例10: FindNextWordEndOffset
public static int FindNextWordEndOffset (TextDocument doc, int offset)
{
int myoffset = offset + 1;
if (!OffsetIsWithinBounds (doc, myoffset)) {
return myoffset;
}
char c = doc.GetCharAt (myoffset);
// skip whitespace
while (char.IsWhiteSpace (c)) {
if (OffsetIsWithinBounds (doc, ++myoffset)) {
c = doc.GetCharAt (myoffset);
} else {
return offset;
}
}
while (!char.IsWhiteSpace (c) && 0 <= myoffset && doc.TextLength-1 > myoffset) {
c = doc.GetCharAt (++myoffset);
}
return System.Math.Max (offset, myoffset - 1);
}
示例11: FindNextSubwordEndOffset
public static int FindNextSubwordEndOffset (TextDocument doc, int offset)
{
int myoffset = offset + 1;
if (!OffsetIsWithinBounds (doc, myoffset)) {
return myoffset;
}
char c = doc.GetCharAt (myoffset);
// skip whitespace
while (char.IsWhiteSpace (c)) {
if (OffsetIsWithinBounds (doc, ++myoffset)) {
c = doc.GetCharAt (myoffset);
} else {
return offset;
}
}
var initialClass = ViWordFindStrategy.GetCharacterClass (c);
while (ViWordFindStrategy.GetCharacterClass (c) == initialClass && 0 <= myoffset && doc.TextLength-1 > myoffset) {
c = doc.GetCharAt (++myoffset);
}
return System.Math.Max (offset, myoffset - 1);
}
示例12: FindPrevWordOffset
/// <summary>
/// Move to end of previous whitespace group.
/// </summary>
public override int FindPrevWordOffset (TextDocument doc, int offset)
{
--offset;
if (0 > offset || doc.TextLength-1 <= offset){ return offset; }
for (char c = doc.GetCharAt (offset);
char.IsWhiteSpace (c) && 0 < offset && doc.TextLength > offset;
c = doc.GetCharAt (--offset));
for (char c = doc.GetCharAt (offset);
!char.IsWhiteSpace (c) && 0 < offset && doc.TextLength > offset;
c = doc.GetCharAt (--offset));
return (0 == offset)? offset: offset+1;
}
示例13: GenerateRtf
public static string GenerateRtf (TextDocument doc, Mono.TextEditor.Highlighting.ISyntaxMode mode, Mono.TextEditor.Highlighting.ColorScheme style, ITextEditorOptions options)
{
var rtfText = new StringBuilder ();
var colorList = new List<Gdk.Color> ();
var selection = new TextSegment (0, doc.TextLength);
int startLineNumber = doc.OffsetToLineNumber (selection.Offset);
int endLineNumber = doc.OffsetToLineNumber (selection.EndOffset);
bool isItalic = false;
bool isBold = false;
int curColor = -1;
foreach (var line in doc.GetLinesBetween (startLineNumber, endLineNumber)) {
bool appendSpace = false;
foreach (var chunk in mode.GetChunks (style, line, line.Offset, line.Length)) {
int start = System.Math.Max (selection.Offset, chunk.Offset);
int end = System.Math.Min (chunk.EndOffset, selection.EndOffset);
var chunkStyle = style.GetChunkStyle (chunk);
if (start < end) {
if (isBold != chunkStyle.Bold) {
rtfText.Append (chunkStyle.Bold ? @"\b" : @"\b0");
isBold = chunkStyle.Bold;
appendSpace = true;
}
if (isItalic != chunkStyle.Italic) {
rtfText.Append (chunkStyle.Italic ? @"\i" : @"\i0");
isItalic = chunkStyle.Italic;
appendSpace = true;
}
if (!colorList.Contains (chunkStyle.Color))
colorList.Add (chunkStyle.Color);
int color = colorList.IndexOf (chunkStyle.Color);
if (curColor != color) {
curColor = color;
rtfText.Append (@"\cf" + (curColor + 1));
appendSpace = true;
}
for (int i = start; i < end; i++) {
char ch = doc.GetCharAt (i);
switch (ch) {
case '\\':
rtfText.Append (@"\\");
break;
case '{':
rtfText.Append (@"\{");
break;
case '}':
rtfText.Append (@"\}");
break;
case '\t':
rtfText.Append (@"\tab");
appendSpace = true;
break;
default:
if (appendSpace) {
rtfText.Append (' ');
appendSpace = false;
}
rtfText.Append (ch);
break;
}
}
}
}
rtfText.Append (@"\par");
rtfText.AppendLine ();
}
var rtf = new StringBuilder();
rtf.Append (@"{\rtf1\ansi\deff0\adeflang1025");
// font table
rtf.Append (@"{\fonttbl");
rtf.Append (@"{\f0\fnil\fprq1\fcharset128 " + options.Font.Family + ";}");
rtf.Append ("}");
rtf.Append (CreateColorTable (colorList));
rtf.Append (@"\viewkind4\uc1\pard");
rtf.Append (@"\f0");
try {
string fontName = options.Font.ToString ();
double fontSize = Double.Parse (fontName.Substring (fontName.LastIndexOf (' ') + 1), System.Globalization.CultureInfo.InvariantCulture) * 2;
rtf.Append (@"\fs");
rtf.Append (fontSize);
} catch (Exception) {};
rtf.Append (@"\cf1");
rtf.Append (rtfText.ToString ());
rtf.Append("}");
return rtf.ToString ();
}