本文整理汇总了C#中ITextSource类的典型用法代码示例。如果您正苦于以下问题:C# ITextSource类的具体用法?C# ITextSource怎么用?C# ITextSource使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ITextSource类属于命名空间,在下文中一共展示了ITextSource类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SimpleReadonlyDocument
SimpleReadonlyDocument (ITextSource readOnlyTextSource, string fileName, string mimeType)
{
textSource = readOnlyTextSource;
FileName = fileName;
MimeType = mimeType;
Initalize (readOnlyTextSource.Text);
}
示例2: 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>();
int lastNewLineOffset = 0;
int len = document.TextLength;
foreach(var segment in _tokenservice.GetSegments()) {
if(segment.Token == Token.BlockOpen || segment.Token == Token.BlockClosed) {
if(segment.Token == _openingBrace) {
startOffsets.Push(segment.Range.Offset);
} else if(segment.Token == _closingBrace && startOffsets.Count > 0) {
int startOffset = startOffsets.Pop();
// don't fold if opening and closing brace are on the same line
if(startOffset < lastNewLineOffset) {
int endoffset = segment.Range.Offset + 1;
if(startOffset < len && endoffset < len) {
newFoldings.Add(new NewFolding(startOffset, endoffset));
}
}
}
} else if(segment.Token == Token.NewLine) {
lastNewLineOffset = segment.Range.Offset;
}
}
newFoldings.Sort((a, b) => a.StartOffset.CompareTo(b.StartOffset));
return newFoldings;
}
示例3: CreateNewFoldings
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
if (document == null)
throw new ArgumentNullException("document");
var newFoldings = new List<NewFolding>();
var startOffsets = new Stack<int>();
int lastNewLineOffset = 0;
char openingBrace = OpeningBrace;
char closingBrace = ClosingBrace;
for (int i = 0; i < document.TextLength; i++)
{
char c = document.GetCharAt(i);
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;
}
示例4: GetSingleIndentationSegment
/// <summary>
/// Gets a single indentation segment starting at <paramref name="offset" /> - at most one tab
/// or <paramref name="indentationSize" /> spaces.
/// </summary>
/// <param name="textSource">The text source.</param>
/// <param name="offset">The offset where the indentation segment starts.</param>
/// <param name="indentationSize">The size of an indentation unit. See <see cref="TextEditorOptions.IndentationSize" />.</param>
/// <returns>
/// The indentation segment.
/// If there is no indentation character at the specified <paramref name="offset" />,
/// an empty segment is returned.
/// </returns>
public static ISegment GetSingleIndentationSegment(ITextSource textSource, int offset, int indentationSize)
{
if (textSource == null)
throw new ArgumentNullException("textSource");
var pos = offset;
while (pos < textSource.TextLength)
{
var c = textSource.GetCharAt(pos);
if (c == '\t')
{
if (pos == offset)
return new SimpleSegment(offset, 1);
break;
}
if (c == ' ')
{
if (pos - offset >= indentationSize)
break;
}
else
{
break;
}
// continue only if c==' ' and (pos-offset)<tabSize
pos++;
}
return new SimpleSegment(offset, pos - offset);
}
示例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>();
int lastNewLineOffset = 0;
char openingBrace = this.OpeningBrace;
char closingBrace = this.ClosingBrace;
for (int i = 0; i < document.TextLength; i++)
{
char c = document.GetCharAt(i);
bool isFirstInLine = IsFirstInLine(document, i);
if (c == openingBrace && isFirstInLine)
startOffsets.Push(i);
else if (c == closingBrace && isFirstInLine && 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;
}
示例6: CreateNewFoldings
/// <summary>
/// Create <see cref="NewFolding" />s for the specified document.
/// </summary>
public IEnumerable<NewFolding> CreateNewFoldings(ITextSource document)
{
var newFoldings = new List<NewFolding>();
var startOffsets = new Stack<int>();
var lastNewLineOffset = 0;
var openingBrace = OpeningBrace;
var closingBrace = ClosingBrace;
for (var i = 0; i < document.TextLength; i++)
{
var c = document.GetCharAt(i);
if (c == openingBrace)
startOffsets.Push(i);
else if (c == closingBrace && startOffsets.Count > 0)
{
var 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;
}
示例7: FindNextNewLine
/// <summary>
/// Finds the next new line character starting at offset.
/// </summary>
/// <param name="text">The text source to search in.</param>
/// <param name="offset">The starting offset for the search.</param>
/// <param name="newLineType">The string representing the new line that was found, or null if no new line was found.</param>
/// <returns>The position of the first new line starting at or after <paramref name="offset"/>,
/// or -1 if no new line was found.</returns>
public static int FindNextNewLine(ITextSource text, int offset, out string newLineType)
{
if (text == null)
throw new ArgumentNullException(nameof(text));
if (offset < 0 || offset > text.TextLength)
throw new ArgumentOutOfRangeException(nameof(offset), offset, "offset is outside of text source");
SimpleSegment s = NewLineFinder.NextNewLine(text, offset);
if (s == SimpleSegment.Invalid)
{
newLineType = null;
return -1;
}
else
{
if (s.Length == 2)
{
newLineType = "\r\n";
}
else if (text.GetCharAt(s.Offset) == '\n')
{
newLineType = "\n";
}
else
{
newLineType = "\r";
}
return s.Offset;
}
}
示例8: MenuText
public MenuText(ContentManager content, Vector2 position, ITextSource textSource)
{
this.position = position;
this.textSource = textSource;
font = content.Load<SpriteFont>("Fonts/Menu_Font");
}
示例9: HtmlTokenizer
/// <summary>
/// See 8.2.4 Tokenization
/// </summary>
/// <param name="source">The source code manager.</param>
public HtmlTokenizer(ITextSource source)
: base(source)
{
_state = HtmlParseMode.PCData;
_acceptsCharacterData = false;
_buffer = new StringBuilder();
}
示例10: TagReader
public TagReader(AXmlParser tagSoupParser, ITextSource input, bool collapseProperlyNestedElements)
: base(input)
{
this.tagSoupParser = tagSoupParser;
if (collapseProperlyNestedElements)
elementNameStack = new Stack<string>();
}
示例11: Parse
public ParseInformation Parse(
FileName fileName,
ITextSource fileContent,
TypeScriptProject project,
IEnumerable<TypeScriptFile> files)
{
try {
using (TypeScriptContext context = contextFactory.CreateContext()) {
context.AddFile(fileName, fileContent.Text);
context.RunInitialisationScript();
NavigationBarItem[] navigation = context.GetNavigationInfo(fileName);
var unresolvedFile = new TypeScriptUnresolvedFile(fileName);
unresolvedFile.AddNavigation(navigation, fileContent);
if (project != null) {
context.AddFiles(files);
var document = new TextDocument(fileContent);
Diagnostic[] diagnostics = context.GetDiagnostics(fileName, project.GetOptions());
TypeScriptService.TaskService.Update(diagnostics, fileName);
}
return new ParseInformation(unresolvedFile, fileContent.Version, true);
}
} catch (Exception ex) {
Console.WriteLine(ex.ToString());
LoggingService.Debug(ex.ToString());
}
return new ParseInformation(
new TypeScriptUnresolvedFile(fileName),
fileContent.Version,
true);
}
示例12: DocumentViewModel
public DocumentViewModel(ITextSource document)
{
Ensure.ArgumentNotNull(document, "document");
Document = document;
Document.TextChanged += OnTextChanged;
}
示例13: getOffsets
protected IEnumerable<NewFolding> getOffsets(char opening, char closing, ITextSource document)
{
List<NewFolding> ret = new List<NewFolding>();
Stack<int> openings = new Stack<int>();
bool multiline = false; //flag of multiline braces
for(int pos = 0; pos < document.TextLength; ++pos)
{
char c = document.GetCharAt(pos);
if(c == opening) {
openings.Push(pos + 1);
multiline = false;
}
else if(char.IsControl(c)) {
multiline = true;
}
else if(openings.Count > 0 && c == closing)
{
int offset = openings.Pop();
if(multiline) {
ret.Add(new NewFolding(offset, pos));
}
}
}
return ret;
}
示例14: FindAllValidating
public IEnumerable<ISearchResult> FindAllValidating(ITextSource document, int offset, int length)
{
using (var stream = document.CreateReader())
{
var doc = (IDocument)document;
var xmlDoc = new XPathDocument(stream); ;
var navigator = xmlDoc.CreateNavigator();
XPathExpression expr = null;
XPathNodeIterator iterator;
try
{
expr = navigator.Compile(_xPath);
iterator = navigator.Select(expr);
}
catch (System.Xml.XPath.XPathException)
{
yield break;
}
while (iterator.MoveNext())
{
var current = iterator.Current;
var segment = XmlSegment(doc, ((IXmlLineInfo)current).LineNumber, ((IXmlLineInfo)current).LinePosition);
if (segment != null && segment.Offset >= offset && segment.EndOffset <= (offset + length))
{
yield return new XPathSearchResult()
{
StartOffset = segment.Offset,
Length = segment.Length
};
}
}
}
}
示例15: Parse
public ParseInformation Parse(FileName fileName, ITextSource fileContent, bool fullParseInformationRequested,
IProject parentProject, CancellationToken cancellationToken)
{
var csharpProject = parentProject as CSharpProject;
CSharpParser parser = new CSharpParser(csharpProject != null ? csharpProject.CompilerSettings : null);
parser.GenerateTypeSystemMode = !fullParseInformationRequested;
SyntaxTree cu = parser.Parse(fileContent, fileName);
cu.Freeze();
CSharpUnresolvedFile file = cu.ToTypeSystem();
ParseInformation parseInfo;
if (fullParseInformationRequested)
parseInfo = new CSharpFullParseInformation(file, fileContent.Version, cu);
else
parseInfo = new ParseInformation(file, fileContent.Version, fullParseInformationRequested);
IDocument document = fileContent as IDocument;
AddCommentTags(cu, parseInfo.TagComments, fileContent, parseInfo.FileName, ref document);
if (fullParseInformationRequested) {
if (document == null)
document = new ReadOnlyDocument(fileContent, parseInfo.FileName);
((CSharpFullParseInformation)parseInfo).newFoldings = CreateNewFoldings(cu, document);
}
return parseInfo;
}