public ComplexAttributeValueToken(IHtmlToken token, char openQuote, char closeQuote) : base(token) { _tokenType = token.TokenType; _openQuote = openQuote; _closeQuote = closeQuote; }
public static AttributeValueToken Create(IHtmlToken token, char openQuote, char closeQuote) { if ((openQuote != '"') || (closeQuote != '"')) { return new ComplexAttributeValueToken(token, openQuote, closeQuote); } return new AttributeValueToken(token); }
public CompositeAttributeValueToken(IHtmlToken[] tokens, char openQuote, char closeQuote, bool isScript) : base(tokens) { Debug.Assert(tokens.Length > 1, "Use AttributeValueToken for token count less than 2"); IsScript = isScript; OpenQuote = openQuote; CloseQuote = closeQuote; }
public override IReadOnlyList <T> ItemsInRange(ITextRange range) { IReadOnlyList <T> list = base.ItemsInRange(range); if (Count > 0) { IHtmlToken lastItem = this[Count - 1] as IHtmlToken; if (lastItem != null && !lastItem.IsWellFormed) { if (range.Contains(lastItem.End)) { // Underlying method returs static readonly collection if nothing was found // in the range so we need to create a new collection here. List <T> modifiedList = new List <T>(list.Count + 1); modifiedList.AddRange(list); modifiedList.Add(this[Count - 1]); list = modifiedList; } } } return(list); }
void AppendToken(string prefix, IHtmlToken t, bool isGhost = false) { if (t != null) { var text = _parser.Text; Debug.Assert(t.Start >= 0 && t.End >= 0); if (isGhost) { Log.AppendFormat("{0}: {1}: @[{2} ... {3}] <<ghost>>\r\n\r\n", prefix, TokenTypeAsString(t.TokenType), t.Start, t.End); } else { Log.AppendFormat("{0}: {1}: @[{2} ... {3}] '{4}'\r\n\r\n", prefix, TokenTypeAsString(t.TokenType), t.Start, t.End, text.GetText(t)); } } else { Log.AppendFormat("{0} <<null>>\r\n\r\n", prefix); } }
public CommentToken(IHtmlToken[] tokens) : base(tokens) { }
public AttributeToken(IHtmlToken nameToken) : this(nameToken, -1, null) { }
public AttributeToken(IHtmlToken nameToken, int equalsPosition) : this(nameToken, equalsPosition, null) { }
public AttributeToken(IHtmlToken nameToken, int equalsPosition, IHtmlAttributeValueToken value) { NameToken = nameToken; EqualsSign = equalsPosition; ValueToken = value; }
protected AttributeValueToken(IHtmlToken token) : base(token.Start, token.Length) { }
public ScriptAttributeValueToken(IHtmlToken token, char openQuote, char closeQuote) : base(token, openQuote, closeQuote) { }
private bool IsDestructiveChangeForSeparator(ISensitiveFragmentSeparatorsInfo separatorInfo, IReadOnlyList <T> itemsInRange, int start, int oldLength, int newLength, ITextProvider oldText, ITextProvider newText) { if (separatorInfo == null) { return(false); } if (separatorInfo.LeftSeparator.Length == 0 && separatorInfo.RightSeparator.Length == 0) { return(false); } // Find out if one of the existing fragments contains position // and if change damages fragment start or end separators string leftSeparator = separatorInfo.LeftSeparator; string rightSeparator = separatorInfo.RightSeparator; // If no items are affected, change is unsafe only if new region contains left side separators. if (itemsInRange.Count == 0) { // Simple optimization for whitespace insertion if (oldLength == 0 && String.IsNullOrWhiteSpace(newText.GetText(new TextRange(start, newLength)))) { return(false); } int fragmentStart = Math.Max(0, start - leftSeparator.Length + 1); int fragmentEnd; // Take into account that user could have deleted space between existing // <! and -- or added - to the existing <!- so extend search range accordingly. fragmentEnd = Math.Min(newText.Length, start + newLength + leftSeparator.Length - 1); int fragmentStartPosition = newText.IndexOf(leftSeparator, TextRange.FromBounds(fragmentStart, fragmentEnd), true); if (fragmentStartPosition >= 0) { // We could've found the left separator only in the newly inserted text since we extended the range we examined // by one less than the separator length. Return true, no further checks necessary. return(true); } return(false); } // Is change completely inside an existing item? if (itemsInRange.Count == 1 && (itemsInRange[0].Contains(start) && itemsInRange[0].Contains(start + oldLength))) { // Check that change does not affect item left separator if (TextRange.Contains(itemsInRange[0].Start, leftSeparator.Length, start)) { return(true); } // Check that change does not affect item right separator. Note that we should not be using // TextRange.Intersect since in case oldLength is zero (like when user is typing right before %> or ?>) // TextRange.Intersect will determine that zero-length range intersects with the right separator // which is incorrect. Typing at position 10 does not change separator at position 10. Similarly, // deleting text right before %> or ?> does not make change destructive. IHtmlToken htmlToken = itemsInRange[0] as IHtmlToken; if (htmlToken == null || htmlToken.IsWellFormed) { int rightSeparatorStart = itemsInRange[0].End - rightSeparator.Length; if (start + oldLength > rightSeparatorStart) { if (TextRange.Intersect(rightSeparatorStart, rightSeparator.Length, start, oldLength)) { return(true); } } } // Touching left separator is destructive too, like when changing <% to <%@ // Check that change does not affect item left separator (whitespace is fine) if (itemsInRange[0].Start + leftSeparator.Length == start) { if (oldLength == 0) { string text = newText.GetText(new TextRange(start, newLength)); if (String.IsNullOrWhiteSpace(text)) { return(false); } } return(true); } int fragmentStart = itemsInRange[0].Start + separatorInfo.LeftSeparator.Length; fragmentStart = Math.Max(fragmentStart, start - separatorInfo.RightSeparator.Length + 1); int changeLength = newLength - oldLength; int fragmentEnd = itemsInRange[0].End + changeLength; fragmentEnd = Math.Min(fragmentEnd, start + newLength + separatorInfo.RightSeparator.Length - 1); if (newText.IndexOf(separatorInfo.RightSeparator, TextRange.FromBounds(fragmentStart, fragmentEnd), true) >= 0) { return(true); } return(false); } return(true); }
void AppendToken(string prefix, IHtmlToken t, bool isGhost = false) { if (t != null) { var text = _parser.Text; Debug.Assert(t.Start >= 0 && t.End >= 0); if (isGhost) { Log.AppendFormat("{0}: {1}: @[{2} ... {3}] <<ghost>>\r\n\r\n", prefix, TokenTypeAsString(t.TokenType), t.Start, t.End); } else { Log.AppendFormat("{0}: {1}: @[{2} ... {3}] '{4}'\r\n\r\n", prefix, TokenTypeAsString(t.TokenType), t.Start, t.End, text.GetText(t)); } } else { Log.AppendFormat("{0} <<null>>\r\n\r\n", prefix); } }
public ComplexAttributeValueToken(IHtmlToken token, char openQuote, char closeQuote) : base(token) { _tokenType = token.TokenType; _openQuote = openQuote; _closeQuote = closeQuote; }