本文整理汇总了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;
}
示例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;
}
示例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)
{
//.........这里部分代码省略.........