/// <summary> /// Find the last position of one array in another, if possible /// </summary> public static bool LastPosition(this byte[] stack, byte?[] needle, out int position, int start = 0, int end = -1) { var matcher = new ContentMatch(needle, start, end); (bool found, int foundPosition) = matcher.Match(stack, true); position = foundPosition; return(found); }
private ContentMatch CreateRegexMatch(MatchRule rule, Match startTagMatch, int index, ContentMatch.TagType tagType) { var regexMatch = new ContentMatch { Type = tagType, Value = startTagMatch.Value, Index = index, MatchRule = rule }; return(regexMatch); }
private void AddOpenTagContainer(ContentMatch match) { if (match.MatchRule.IsContentTranslatable) { ITagPair tagPair = CreateTagPair(match); _currentContainer.Add(tagPair); _currentContainer = tagPair; } else { //treat non-translatable content as locked ILockedContent lockedContent = CreateLockedContent(); _currentContainer.Add(lockedContent); _currentContainer = lockedContent.Content; } }
private IAbstractMarkupData CreatePlaceholderTag(ContentMatch match) { var placeholderProps = _itemFactory.PropertiesFactory.CreatePlaceholderTagProperties(match.Value); placeholderProps.CanHide = match.MatchRule.CanHide; placeholderProps.IsSoftBreak = match.MatchRule.IsSoftBreak; placeholderProps.IsWordStop = match.MatchRule.IsWordStop; placeholderProps.DisplayText = GetDisplayName(match.Value); placeholderProps.SegmentationHint = match.MatchRule.SegmentationHint; placeholderProps.TagContent = match.Value; if (!string.IsNullOrEmpty(match.MatchRule.TextEquivalent)) { placeholderProps.TextEquivalent = match.MatchRule.TextEquivalent; } placeholderProps.SetMetaData(EmbeddedContentMetaKey, match.Value); return(_itemFactory.CreatePlaceholderTag(placeholderProps)); }
private ITagPair CreateTagPair(ContentMatch match) { IStartTagProperties startProperties = _itemFactory.PropertiesFactory.CreateStartTagProperties(match.Value); startProperties.CanHide = match.MatchRule.CanHide; startProperties.IsSoftBreak = match.MatchRule.IsSoftBreak; startProperties.IsWordStop = match.MatchRule.IsWordStop; startProperties.DisplayText = GetDisplayName(match.Value); startProperties.Formatting = FormattingInflator.InflateFormatting(match.MatchRule.Formatting); startProperties.SegmentationHint = match.MatchRule.SegmentationHint; startProperties.SetMetaData(EmbeddedContentMetaKey, match.Value); IEndTagProperties endProperties = _itemFactory.PropertiesFactory.CreateEndTagProperties(match.Value); endProperties.CanHide = match.MatchRule.CanHide; endProperties.IsSoftBreak = match.MatchRule.IsSoftBreak; endProperties.IsWordStop = match.MatchRule.IsWordStop; endProperties.DisplayText = GetDisplayName(match.Value); endProperties.SetMetaData(EmbeddedContentMetaKey, match.Value); return(_itemFactory.CreateTagPair(startProperties, endProperties)); }
/// <summary> /// Find all positions of one array in another, if possible, if possible /// </summary> public static List <int> FindAllPositions(this byte[] stack, byte?[] needle, int start = 0, int end = -1) { // Get the outgoing list List <int> positions = new List <int>(); // Initialize the loop variables bool found = true; int lastPosition = start; var matcher = new ContentMatch(needle, end: end); // Loop over and get all positions while (found) { matcher.Start = lastPosition; (found, lastPosition) = matcher.Match(stack, false); if (found) { positions.Add(lastPosition); } } return(positions); }