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


C# ITextSource.IndexOf方法代码示例

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


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

示例1: GetCurrentQuerySegment

    protected ISegment GetCurrentQuerySegment(ITextSource text, int offset)
    {
      var start = -1;
      var end = -1;
      var depth = 0;
      var result = new TextSegment() { StartOffset = 0, Length = text.TextLength };

      XmlUtils.ProcessFragment(text, (r, o, st) =>
      {
        switch (r.NodeType)
        {
          case XmlNodeType.Element:

            if (depth == 0)
            {
              start = o;
            }

            if (r.IsEmptyElement)
            {
              end = text.IndexOf("/>", o, text.TextLength - o, StringComparison.Ordinal) + 2;
              if (depth == 0 && offset >= start && offset < end)
              {
                result = new TextSegment() { StartOffset = start, EndOffset = end };
                return false;
              }
            }
            else
            {
              depth++;
            }
            break;
          case XmlNodeType.EndElement:
            depth--;
            if (depth == 0)
            {
              end = text.IndexOf('>', o, text.TextLength - o) + 1;
              if (offset >= start && offset < end)
              {
                result = new TextSegment() { StartOffset = start, EndOffset = end };
                return false;
              }
            }
            break;
        }
        return true;
      });

      return result;
    }
开发者ID:cornelius90,项目名称:InnovatorAdmin,代码行数:50,代码来源:XmlEditorHelper.cs

示例2: GetCurrentItem

    private EditorItemData GetCurrentItem(ITextSource text, int offset)
    {
      var result = new Stack<EditorItemData>();
      string lastElement = null;

      XmlUtils.ProcessFragment(text, (r, o, st) =>
      {
        if (o > offset)
          return false;

        switch (r.NodeType)
        {
          case XmlNodeType.Element:

            if (r.LocalName == "Item")
            {
              result.Push(new EditorItemData()
              {
                Action = r.GetAttribute("action"),
                Type = r.GetAttribute("type"),
                Id = r.GetAttribute("id")
              });

              if (r.IsEmptyElement)
              {
                var end = text.IndexOf("/>", o, text.TextLength - o, StringComparison.Ordinal) + 2;
                if (offset >= o && offset < end)
                {
                  return false;
                }
                else
                {
                  result.Pop();
                }
              }
            }
            else if (!r.IsEmptyElement)
            {
              lastElement = r.LocalName;
            }
            break;
          case XmlNodeType.Text:
          case XmlNodeType.CDATA:
            if (result.Any() && !string.IsNullOrEmpty(lastElement))
            {
              result.Peek().Property(lastElement, r.Value);
            }
            break;
          case XmlNodeType.EndElement:
            if (r.LocalName == "Item")
            {
              if (offset < (o + 6))
                return false;
              result.Pop();
            }
            else
            {
              lastElement = null;
            }
            break;
        }
        return true;
      });

      if (result.Any())
        return result.Pop();
      return null;
    }
开发者ID:rneuber1,项目名称:InnovatorAdmin,代码行数:68,代码来源:AmlSimpleEditorHelper.cs

示例3: 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


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