本文整理汇总了C#中Scanner.ScanUntil方法的典型用法代码示例。如果您正苦于以下问题:C# Scanner.ScanUntil方法的具体用法?C# Scanner.ScanUntil怎么用?C# Scanner.ScanUntil使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Scanner
的用法示例。
在下文中一共展示了Scanner.ScanUntil方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ScanUntil_Should_Return_String_Up_To_Index_When_Matched
public void ScanUntil_Should_Return_String_Up_To_Index_When_Matched()
{
var scanner = new Scanner("a b c");
var match = scanner.ScanUntil("b");
Assert.Equal(match, "a ");
Assert.Equal(scanner.Pos, 2);
}
示例2: ScanUntil_Should_Return_Whole_String_When_Not_Matched
public void ScanUntil_Should_Return_Whole_String_When_Not_Matched()
{
var scanner = new Scanner("a b c");
var match = scanner.ScanUntil("z");
Assert.Equal(match, scanner.Template);
Assert.True(scanner.EOS);
}
示例3: ScanUntil_Should_Return_Empty_When_Regex_Matches_At_Zero_Index
public void ScanUntil_Should_Return_Empty_When_Regex_Matches_At_Zero_Index()
{
var scanner = new Scanner("a b c");
var match = scanner.ScanUntil("a");
Assert.Equal(match, "");
Assert.Equal(scanner.Pos, 0);
}
示例4: ParseTemplate
/**
* Breaks up the given `template` string into a tree of tokens. If the `tags`
* argument is given here it must be an array with two string values: the
* opening and closing tags used in the template (e.g. [ "<%", "%>" ]). Of
* course, the default is to use mustaches (i.e. mustache.tags).
*
* A token is an array with at least 4 elements. The first element is the
* mustache symbol that was used inside the tag, e.g. "#" or "&". If the tag
* did not contain a symbol (i.e. {{myValue}}) this element is "Name". For
* all text that appears outside a symbol this element is "text".
*
* The second element of a token is its "Value". For mustache tags this is
* whatever else was inside the tag besides the opening symbol. For text tokens
* this is the text itself.
*
* The third and fourth elements of the token are the Start and End indices,
* respectively, of the token in the original template.
*
* Tokens that are the root node of a subtree contain two more elements: 1) an
* array of tokens in the subtree and 2) the index in the original template at
* which the closing tag for that section begins.
*/
private static List<Token> ParseTemplate(string template, Tags tags = null)
{
if (!template.Any())
return new List<Token>();
var sections = new Stack<Token>(); // Stack to hold section tokens
var tokens = new List<Token>(); // Buffer to hold the tokens
var spaces = new Stack<int>(); // Indices of whitespace tokens on the current line
var hasTag = false; // Is there a {{tag}} on the current line?
var nonSpace = false; // Is there a non-space char on the current line?
// Strips all whitespace tokens array for the current line
// if there was a {{#tag}} on it and otherwise only space.
Action stripSpace = () =>
{
if (hasTag && !nonSpace)
{
while (spaces.Any())
tokens.RemoveAt(spaces.Pop());
}
else
{
spaces.Clear();
}
hasTag = false;
nonSpace = false;
};
// TODO: this `= null` is to avoid "Use of unassigned local variable" C# compiler error.
Regex openingTagRe = null;
Regex closingTagRe = null;
Regex closingCurlyRe = null;
Action<Tags> compileTags = delegate(Tags tagsToCompile)
{
openingTagRe = new Regex(Regex.Escape(tagsToCompile.Opener) + "\\s*");
closingTagRe = new Regex("\\s*" + Regex.Escape(tagsToCompile.Closer));
closingCurlyRe = new Regex("\\s*" + Regex.Escape('}' + tagsToCompile.Closer));
};
if (tags == null)
compileTags(MustacheTags);
else
compileTags(tags);
//var Start, Type, Value, chr, token, openSection;
var scanner = new Scanner(template);
Token openSection = null;
while (!scanner.Eos())
{
var start = scanner._pos;
var value = scanner.ScanUntil(openingTagRe);
var valueLength = value.Length;
if (valueLength > 0)
{
for (var i = 0; i < valueLength; ++i)
{
string chr = "" + value[i];
if (IsWhitespace(chr))
{
spaces.Push(tokens.Count);
}
else
{
nonSpace = true;
}
tokens.Add(new Token {Type = "text", Value = chr, Start = start, End = start + 1});
start += 1;
// Check for whitespace on the current line.
if (chr == "\n")
stripSpace();
}
}
// Match the opening tag.
//.........这里部分代码省略.........