当前位置: 首页>>代码示例>>C#>>正文


C# ITextSource.GetText方法代码示例

本文整理汇总了C#中ITextSource.GetText方法的典型用法代码示例。如果您正苦于以下问题:C# ITextSource.GetText方法的具体用法?C# ITextSource.GetText怎么用?C# ITextSource.GetText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ITextSource的用法示例。


在下文中一共展示了ITextSource.GetText方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddTagComments

		void AddTagComments(AXmlDocument xmlDocument, ParseInformation parseInfo, ITextSource fileContent)
		{
			IDocument document = null;
			foreach (var tag in TreeTraversal.PreOrder<AXmlObject>(xmlDocument, node => node.Children).OfType<AXmlTag>().Where(t => t.IsComment)) {
				int matchLength;
				string commentText = fileContent.GetText(tag.StartOffset, tag.Length);
				int index = commentText.IndexOfAny(TaskListTokens, 0, out matchLength);
				if (index > -1) {
					if (document == null)
						document = fileContent as IDocument ?? new ReadOnlyDocument(fileContent, parseInfo.FileName);
					do {
						TextLocation startLocation = document.GetLocation(tag.StartOffset + index);
						int startOffset = index + tag.StartOffset;
						int endOffset = Math.Min(document.GetLineByOffset(startOffset).EndOffset, tag.EndOffset);
						string content = document.GetText(startOffset, endOffset - startOffset);
						parseInfo.TagComments.Add(new TagComment(content.Substring(0, matchLength), new DomRegion(parseInfo.FileName, startLocation.Line, startLocation.Column), content.Substring(matchLength)));
						index = commentText.IndexOfAny(TaskListTokens, endOffset - tag.StartOffset, out matchLength);
					} while (index > -1);
				}
			}
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:21,代码来源:XamlParser.cs

示例2: CreateRuns

		/// <summary>
		/// Creates WPF Run instances that can be used for TextBlock.Inlines.
		/// </summary>
		/// <param name="textSource">The text source that holds the text for this RichTextModel.</param>
		public Run[] CreateRuns(ITextSource textSource)
		{
			Run[] runs = new Run[stateChanges.Count];
			for (int i = 0; i < runs.Length; i++) {
				int startOffset = stateChangeOffsets[i];
				int endOffset = i + 1 < stateChangeOffsets.Count ? stateChangeOffsets[i + 1] : textSource.TextLength;
				Run r = new Run(textSource.GetText(startOffset, endOffset - startOffset));
				HighlightingColor state = stateChanges[i];
				RichText.ApplyColorToTextElement(r, state);
				runs[i] = r;
			}
			return runs;
		}
开发者ID:ratoy,项目名称:SharpDevelop,代码行数:17,代码来源:RichTextModel.cs

示例3: 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);
		}
开发者ID:Paccc,项目名称:SharpDevelop,代码行数:11,代码来源:XmlParser.cs

示例4: GetCurrentQuery

 public virtual string GetCurrentQuery(ITextSource text, int offset)
 {
   return text.GetText(GetCurrentQuerySegment(text, offset));
 }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:4,代码来源:XmlEditorHelper.cs

示例5: 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>();
            Stack<int> startRegionOffsets = 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 (i + BeginRegion.Length < document.TextLength
                    && BeginRegion.Equals(document.GetText(i, BeginRegion.Length)) == true)
                {
                    startRegionOffsets.Push(i);
                }
                else if (i + EndRegion.Length < document.TextLength
                    && EndRegion.Equals(document.GetText(i, EndRegion.Length))
                    && startRegionOffsets.Count > 0)
                {
                    int startOffset = startRegionOffsets.Pop();
                    int endOffset = i + 1;

                    //folding at the end of #region xxxxx
                    while (startOffset < document.TextLength
                        &&
                            (document.GetCharAt(startOffset) != '\n'
                            && document.GetCharAt(startOffset) != '\r'))
                    {
                        startOffset++;
                    }

                    //folding at the end of #endregion
                    while (endOffset < document.TextLength
                        &&
                            (document.GetCharAt(endOffset) != '\n'
                            && document.GetCharAt(endOffset) != '\r'))
                    {
                        endOffset++;
                    }

                    // don't fold if opening and closing brace are on the same line
                    //if (startOffset < lastNewLineOffset)
                    {
                        newFoldings.Add(new NewFolding(startOffset, endOffset));
                    }
                }
                else 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;
        }
开发者ID:xcasadio,项目名称:FlowGraph,代码行数:74,代码来源:BraceFoldingStrategy.cs

示例6: Run

        public static void Run(ITextSource originalXmlFile)
        {
            int seed;
            lock (sharedRnd) {
                seed = sharedRnd.Next();
            }
            Console.WriteLine(seed);
            Random rnd = new Random(seed);

            AXmlParser parser = new AXmlParser();
            StringBuilder b = new StringBuilder(originalXmlFile.Text);
            IncrementalParserState parserState = null;
            var versionProvider = new TextSourceVersionProvider();
            int totalCharactersParsed = 0;
            int totalCharactersChanged = originalXmlFile.TextLength;
            TimeSpan incrementalParseTime = TimeSpan.Zero;
            TimeSpan nonIncrementalParseTime = TimeSpan.Zero;
            Stopwatch w = new Stopwatch();
            for (int iteration = 0; iteration < 100; iteration++) {
                totalCharactersParsed += b.Length;
                var textSource = new StringTextSource(b.ToString(), versionProvider.CurrentVersion);
                w.Restart();
                var incrementalResult = parser.ParseIncremental(parserState, textSource, out parserState);
                w.Stop();
                incrementalParseTime += w.Elapsed;
                w.Restart();
                var nonIncrementalResult = parser.Parse(textSource);
                w.Stop();
                nonIncrementalParseTime += w.Elapsed;
                CompareResults(incrementalResult, nonIncrementalResult);

                incrementalResult.AcceptVisitor(new ValidationVisitor(textSource));

                // Randomly mutate the file:

                List<TextChangeEventArgs> changes = new List<TextChangeEventArgs>();
                int modifications = rnd.Next(0, 25);
                int offset = 0;
                for (int i = 0; i < modifications; i++) {
                    if (i == 0 || rnd.Next(0, 10) == 0)
                        offset = rnd.Next(0, b.Length);
                    else
                        offset += rnd.Next(0, Math.Min(10, b.Length - offset));
                    int originalOffset = rnd.Next(0, originalXmlFile.TextLength);
                    int insertionLength;
                    int removalLength;
                    switch (rnd.Next(0, 21) / 10) {
                        case 0:
                            removalLength = 0;
                            insertionLength = rnd.Next(0, Math.Min(50, originalXmlFile.TextLength - originalOffset));
                            break;
                        case 1:
                            removalLength = rnd.Next(0, Math.Min(20, b.Length - offset));
                            insertionLength = rnd.Next(0, Math.Min(20, originalXmlFile.TextLength - originalOffset));
                            break;
                        default:
                            removalLength = rnd.Next(0, b.Length - offset);
                            insertionLength = rnd.Next(0, originalXmlFile.TextLength - originalOffset);
                            break;
                    }
                    string removedText = b.ToString(offset, removalLength);
                    b.Remove(offset, removalLength);
                    string insertedText = originalXmlFile.GetText(originalOffset, insertionLength);
                    b.Insert(offset, insertedText);
                    versionProvider.AppendChange(new TextChangeEventArgs(offset, removedText, insertedText));
                    totalCharactersChanged += insertionLength;
                }
            }
            Console.WriteLine("Incremental parse time:     " + incrementalParseTime + " for " + totalCharactersChanged + " characters changed");
            Console.WriteLine("Non-Incremental parse time: " + nonIncrementalParseTime + " for " + totalCharactersParsed + " characters");
        }
开发者ID:segaman,项目名称:NRefactory,代码行数:71,代码来源:IncrementalXmlParserTests.cs

示例7: GetWhitespaceBefore

 /// <summary>
 /// Gets all indentation before the offset.
 /// </summary>
 /// <param name="document">The document.</param>
 /// <param name="offset">The offset where the indentation ends.</param>
 /// <returns>The indentation text.</returns>
 public static string GetWhitespaceBefore(ITextSource textSource, int offset)
 {
     ISegment segment = TextUtilities.GetWhitespaceBefore(textSource, offset);
     return textSource.GetText(segment.Offset, segment.Length);
 }
开发者ID:hazama-yuinyan,项目名称:BVEEditor,代码行数:11,代码来源:DocumentUtilities.cs

示例8: HandleTextEntered

    public virtual IEnumerable<ICompletionData> HandleTextEntered(ITextSource source, int caret, string insertText = null)
    {
      insertText = insertText ?? source.GetText(caret - 1, 1);
      var text = source.GetText(0, caret);
      ICompletionData[] result = null;
      IEnumerable<XmlElementPath> parentPaths;
      switch (insertText)
      {
        case "=":
          // Namespace intellisense.
          if (XmlParser.IsNamespaceDeclaration(text, text.Length))
          {
            result = schemaCompletionDataItems.GetNamespaceCompletionData();
          }
          break;
        case "<":
          // Child element intellisense.
          parentPaths = XmlParser.GetParentElementPaths(text);
          if (parentPaths.Any())
          {
            foreach (var path in parentPaths)
            {
              result = GetChildElementCompletionData(path);
              if (result.Any()) break;
            }
          }
          else if (defaultSchemaCompletionData != null)
          {
            result = defaultSchemaCompletionData.GetElementCompletionData(defaultNamespacePrefix).ToArray();
          }
          break;

        case " ":
          // Attribute intellisense.
          if (!XmlParser.IsInsideAttributeValue(text, text.Length))
          {
            XmlElementPath path = XmlParser.GetActiveElementStartPath(text, text.Length);
            if (path.Elements.Count > 0)
            {
              result = GetAttributeCompletionData(path);
            }
          }
          break;
        default:

          // Attribute value intellisense.
          if (XmlParser.IsAttributeValueChar(insertText[0]))
          {
            string attributeName = XmlParser.GetAttributeName(text, text.Length);
            if (attributeName.Length > 0)
            {
              XmlElementPath elementPath = XmlParser.GetActiveElementStartPath(text, text.Length);
              if (elementPath.Elements.Count > 0)
              {
                //preSelection = insertText.ToString();
                result = GetAttributeValueCompletionData(elementPath, attributeName);
              }
            }
          }
          break;
      }

      if (result != null)
        return result.OrderBy(x => x.Text);

      return Enumerable.Empty<ICompletionData>();
    }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:67,代码来源:XmlCompletionDataProvider.cs

示例9: ElementStartsWith

 bool ElementStartsWith(string text, int elementStartIndex, ITextSource document)
 {
     int textLength = Math.Min(text.Length, document.TextLength - elementStartIndex);
     return document.GetText(elementStartIndex, textLength).Equals(text, StringComparison.OrdinalIgnoreCase);
 }
开发者ID:2594636985,项目名称:SharpDevelop,代码行数:5,代码来源:XmlCodeCompletionBinding.cs

示例10: Completions

    public IPromise<CompletionContext> Completions(string prefix, ITextSource all, int caret, string termCharacter
      , bool tableNameColumnPrefix = false)
    {
      try
      {
        _tableNameColumnPrefix = tableNameColumnPrefix;
        var lastIndex = string.IsNullOrEmpty(termCharacter) ? -1 : all.IndexOf(termCharacter, caret, all.TextLength - caret, StringComparison.Ordinal);
        var sql = prefix + (lastIndex < 0 ? all.GetText(caret, all.TextLength - caret) : all.GetText(caret, lastIndex - caret));
        if (sql.StartsWith("(") && sql.EndsWith(")"))
          sql = sql.Substring(1, sql.Length - 2);
        var parseTree = new SqlTokenizer(sql).Parse();
        if (!parseTree.Any())
          return Promises.Resolved(new CompletionContext());

        var currNode = parseTree.NodeByOffset(prefix.Length);
        var literal = currNode as SqlLiteral;

        if (literal != null)
        {
          var parGroup = literal.Parent as SqlGroup;
          if (_overloadWin != null && (parGroup == null || !parGroup.First().TextEquals(_overloadName)))
            _overloadWin.Close();

          if (SqlTokenizer.KeywordPrecedesTable(literal))
          {
            var context = new SqlContext(parGroup);
            return ContextFromData(Tables(null).Concat(Schemas())
              .Concat(context.Definitions.Select(d => new SqlGeneralCompletionData() {
                Text = d,
                Description = "Locally defined table",
                Image = WpfImages.Class16
              }))
              .OrderBy(i => i.Text));
          }
          else if (literal.Text == "(")
          {

            var prev = literal.PreviousLiteral();

            if (prev != null)
            {
              if (CurrentTextArea != null)
              {
                var overloads = from f in _coreFunctions
                                where string.Equals(f.Name, prev.Text, StringComparison.OrdinalIgnoreCase)
                                select new Overload(f.Usage, f.Description);
                if (overloads.Any())
                {
                  _overloadWin = new OverloadInsightWindow(CurrentTextArea);
                  _overloadWin.StartOffset = caret;
                  _overloadWin.EndOffset = caret + 1;
                  _overloadWin.Provider = new OverloadList().AddRange(overloads);
                  _overloadWin.Show();
                  _overloadWin.Closed += (s, e) => {
                    _overloadWin = null;
                    _overloadName = null;
                  };
                  _overloadName = prev.Text;
                }
              }

              switch (prev.Text.ToUpperInvariant())
              {
                case "DATEADD":
                case "DATEDIFF":
                case "DATEDIFF_BIG":
                case "DATEFROMPARTS":
                case "DATENAME":
                case "DATEPART":
                  return ContextFromData(_datePartNames.Select(n => new SqlGeneralCompletionData()
                    {
                      Text = n[0] + (n[1] == n[0] ? "" : " (" + n[1] + ")"),
                      Description = n[1],
                      Image = WpfImages.EnumValue16,
                      Action = () => n[0]
                    })
                    .OrderBy(i => i.Text));
              }
            }
          }
          else if (literal.Text == ".")
          {
            var name = literal.Parent as SqlName;
            if (name != null)
            {
              if (name.IsTable)
              {
                var idx = name.IndexOf(literal);
                var schema = name[idx - 1].Text;
                if (_provider.GetSchemaNames().Contains(schema, StringComparer.OrdinalIgnoreCase))
                {
                  return ContextFromData(Tables(schema).Concat(Functions(true, schema))
                    .OrderBy(i => i.Text));
                }
              }
              else
              {
                var group = name.Parent as SqlGroup;
                if (group != null)
                {
//.........这里部分代码省略.........
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:101,代码来源:SqlCompletionHelper.cs

示例11: GetIdentifierAt

        /// <summary>
        /// Gets the identifier at the given offset in the document.
        /// </summary>
        /// <param name="document">The document.</param>
        /// <param name="offset">The offset.</param>
        /// <returns>The identifier at <paramref name="offset"/>.</returns>
        /// <remarks>
        /// An identifier is a single word consisting of letters, digits, or underscores.
        /// An identifier must start with a letter or underscore.
        /// </remarks>
        public static string GetIdentifierAt(ITextSource document, int offset)
        {
            if (offset < 0 || offset >= document.TextLength || !IsIdentifierPart(document.GetCharAt(offset)))
                return string.Empty;

            int startOffset = FindStartOfIdentifier(document, offset);
            if (startOffset == -1)
                return string.Empty;

            int endOffset = FindEndOfIdentifier(document, offset);

            Debug.Assert(endOffset != -1);
            Debug.Assert(endOffset >= startOffset);

            return document.GetText(startOffset, endOffset - startOffset + 1);
        }
开发者ID:Zolniu,项目名称:DigitalRune,代码行数:26,代码来源:TextUtilities.cs


注:本文中的ITextSource.GetText方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。