public IncreasePosition ( int increment ) : void | ||
increment | int | Increment |
Résultat | void |
/// <summary> /// Process a comments /// </summary> /// <returns>Result of processing (true - is processed; false - is not processed)</returns> protected bool ProcessComment() { bool isProcessed = false; string content = _innerContext.SourceCode; int commentStartPosition = _innerContext.Position; int commentEndPosition = content.IndexOf("-->", commentStartPosition, StringComparison.Ordinal); int commentPositionDifference = commentEndPosition - commentStartPosition; if (commentPositionDifference >= 4) { string commentText = commentPositionDifference > 4 ? content.Substring(commentStartPosition + 4, commentPositionDifference - 4) : string.Empty; switch (commentText) { case IGNORING_COMMENT_TAG_NAME: isProcessed = ProcessStartIgnoringCommentTag(); break; case "/" + IGNORING_COMMENT_TAG_NAME: isProcessed = ProcessEndIgnoringCommentTag(); break; default: CommonHandlers.Comment?.Invoke(_context, commentText); _innerContext.IncreasePosition(commentEndPosition + 3 - commentStartPosition); isProcessed = true; break; } } return(isProcessed); }
/// <summary> /// Process a doctype declaration /// </summary> /// <returns>Result of processing (true - is processed; false - is not processed)</returns> protected bool ProcessDoctype() { bool isProcessed = false; string content = _innerContext.SourceCode; int contentRemainderLength = _innerContext.RemainderLength; var match = _doctypeRegex.Match(content, _innerContext.Position, contentRemainderLength); if (match.Success) { string doctype = match.Value; var doctypeHandler = CommonHandlers.Doctype; if (doctypeHandler != null) { doctypeHandler(_context, doctype); } _innerContext.IncreasePosition(doctype.Length); isProcessed = true; } return(isProcessed); }
/// <summary> /// Parses a Knockout begin containerless comment /// </summary> /// <param name="commentText">Comment text</param> /// <param name="expressionHandler">Binding expression handler</param> public static void ParseBeginContainerlessComment(string commentText, ExpressionDelegate expressionHandler) { Match koBeginContainerlessCommentMatch = _koBeginContainerlessCommentRegex.Match(commentText); if (koBeginContainerlessCommentMatch.Success) { var innerContext = new InnerMarkupParsingContext(commentText); var context = new MarkupParsingContext(innerContext); Group expressionGroup = koBeginContainerlessCommentMatch.Groups["expression"]; int expressionPosition = expressionGroup.Index; string expression = expressionGroup.Value.TrimEnd(); innerContext.IncreasePosition(expressionPosition); if (expressionHandler != null) { expressionHandler(context, expression); } } }
/// <summary> /// Parses a Angular comment directive /// </summary> /// <param name="commentText">Comment text</param> /// <param name="directiveNameHandler">Directive name handler</param> /// <param name="expressionHandler">Binding expression handler</param> public static void ParseCommentDirective(string commentText, DirectiveNameDelegate directiveNameHandler, ExpressionDelegate expressionHandler) { Match ngCommentDirectiveMatch = _ngCommentDirectiveRegex.Match(commentText); if (ngCommentDirectiveMatch.Success) { var innerContext = new InnerMarkupParsingContext(commentText); var context = new MarkupParsingContext(innerContext); GroupCollection groups = ngCommentDirectiveMatch.Groups; Group directiveNameGroup = groups["directiveName"]; int directiveNamePosition = directiveNameGroup.Index; string originalDirectiveName = directiveNameGroup.Value; string normalizedDirectiveName = NormalizeDirectiveName(originalDirectiveName); innerContext.IncreasePosition(directiveNamePosition); if (directiveNameHandler != null) { directiveNameHandler(context, originalDirectiveName, normalizedDirectiveName); } Group expressionGroup = groups["expression"]; if (expressionGroup.Success) { int expressionPosition = expressionGroup.Index; string expression = expressionGroup.Value.Trim(); innerContext.IncreasePosition(expressionPosition - directiveNamePosition); if (expressionHandler != null) { expressionHandler(context, expression); } } } }
/// <summary> /// Parses a Angular class directive /// </summary> /// <param name="className">Class name</param> /// <param name="directiveNameHandler">Directive name handler</param> /// <param name="expressionHandler">Binding expression handler</param> /// <param name="semicolonHandler">Semicolon handler</param> public static void ParseClassDirective(string className, DirectiveNameDelegate directiveNameHandler, ExpressionDelegate expressionHandler, SemicolonDelegate semicolonHandler) { MatchCollection ngClassDirectiveMatches = _ngClassDirectiveRegex.Matches(className); if (ngClassDirectiveMatches.Count > 0) { var innerContext = new InnerMarkupParsingContext(className); var context = new MarkupParsingContext(innerContext); int currentPosition = 0; foreach (Match ngClassDirectiveMatch in ngClassDirectiveMatches) { GroupCollection groups = ngClassDirectiveMatch.Groups; Group directiveNameGroup = groups["directiveName"]; int directiveNamePosition = directiveNameGroup.Index; string originalDirectiveName = directiveNameGroup.Value; string normalizedDirectiveName = NormalizeDirectiveName(originalDirectiveName); innerContext.IncreasePosition(directiveNamePosition - currentPosition); currentPosition = directiveNamePosition; if (directiveNameHandler != null) { directiveNameHandler(context, originalDirectiveName, normalizedDirectiveName); } Group expressionGroup = groups["expression"]; if (expressionGroup.Success) { int expressionPosition = expressionGroup.Index; string expression = expressionGroup.Value.Trim(); innerContext.IncreasePosition(expressionPosition - currentPosition); currentPosition = expressionPosition; if (expressionHandler != null) { expressionHandler(context, expression); } } Group semicolonGroup = groups["semicolon"]; if (semicolonGroup.Success) { int semicolonPosition = semicolonGroup.Index; innerContext.IncreasePosition(semicolonPosition - currentPosition); currentPosition = semicolonPosition; if (semicolonHandler != null) { semicolonHandler(context); } } } } }
/// <summary> /// Parses a Mustache-style markup /// </summary> /// <param name="content">Mustache-style markup</param> /// <param name="mustacheStyleTagHandler">Mustache-style tags handler</param> /// <param name="textHandler">Text handler</param> public static void ParseMarkup(string content, MustacheStyleTagDelegate mustacheStyleTagHandler, TextDelegate textHandler) { var innerContext = new InnerMarkupParsingContext(content); var context = new MarkupParsingContext(innerContext); MatchCollection mustacheStyleTagMatches = _mustacheStyleTagRegex.Matches(content); if (mustacheStyleTagMatches.Count == 0) { if (textHandler != null) { textHandler(context, content); } innerContext.IncreasePosition(content.Length); return; } int currentPosition = 0; int endPosition = content.Length - 1; foreach (Match mustacheStyleTagMatch in mustacheStyleTagMatches) { int mustacheStyleTagPosition = mustacheStyleTagMatch.Index; int mustacheStyleTagLength = mustacheStyleTagMatch.Length; if (mustacheStyleTagPosition > currentPosition) { string text = content.Substring(currentPosition, mustacheStyleTagPosition - currentPosition); if (textHandler != null) { textHandler(context, text); } innerContext.IncreasePosition(text.Length); } GroupCollection mustacheStyleTagGroups = mustacheStyleTagMatch.Groups; string expression = mustacheStyleTagGroups["expression"].Value; string startDelimiter = mustacheStyleTagGroups["startDelimiter"].Value; string endDelimiter = mustacheStyleTagGroups["endDelimiter"].Value; if (expression.StartsWith("{") && expression.EndsWith("}")) { expression = expression.Substring(1, expression.Length - 2); startDelimiter = "{{{"; endDelimiter = "}}}"; } if (mustacheStyleTagHandler != null) { mustacheStyleTagHandler(context, expression, startDelimiter, endDelimiter); } innerContext.IncreasePosition(mustacheStyleTagLength); currentPosition = mustacheStyleTagPosition + mustacheStyleTagLength; } if (currentPosition > 0 && currentPosition <= endPosition) { string text = content.Substring(currentPosition, endPosition - currentPosition + 1); if (textHandler != null) { textHandler(context, text); } innerContext.IncreasePosition(text.Length); } }