/// <summary>Ancillary function of NextContentUnit(). Create new chunk, taking _contextStack into /// account, and updating it if needed.</summary> private IndexingContentUnit BuildIndexingContentUnit(string text, uint lcid) { CHUNK_BREAKTYPE breakType = CHUNK_BREAKTYPE.CHUNK_NO_BREAK; // If a paragraph break is expected, reflect this in the new chunk. if (_expectingBlockStart) { breakType = CHUNK_BREAKTYPE.CHUNK_EOP; if (_returnCanonicalParagraphBreaks) { text = _paragraphSeparator + text; } } if (_indexingContentUnit == null) { _indexingContentUnit = new IndexingContentUnit(text, AllocateChunkID(), breakType, _propSpec, lcid); } else { // Optimization: reuse indexing content unit. _indexingContentUnit.InitIndexingContentUnit(text, AllocateChunkID(), breakType, _propSpec, lcid); } // Until proven separated (by the occurrence of a block tag), right neighbors are contiguous. _expectingBlockStart = false; return(_indexingContentUnit); }
// Token: 0x06006C4A RID: 27722 RVA: 0x001F3118 File Offset: 0x001F1318 private IndexingContentUnit HandleTextData() { ContentDescriptor contentDescriptor = this.TopOfStack(); if (contentDescriptor != null) { IndexingContentUnit result = this.BuildIndexingContentUnit(this._xamlReader.Value, this.GetCurrentLcid()); this._xamlReader.Read(); return(result); } this._xamlReader.Read(); return(null); }
///<summary> /// If current token is a text element, /// assume it can be part of its parent's content and return a chunk. ///</summary> ///<remarks> /// Ancillary function of NextContentUnit. ///</remarks> private IndexingContentUnit HandleTextData() { ContentDescriptor topOfStack = TopOfStack(); if (topOfStack != null) { // The descendants of elements with HasIndexableContent set to false get skipped. Debug.Assert(topOfStack.HasIndexableContent); // Return a chunk with appropriate block-break information. IndexingContentUnit result = BuildIndexingContentUnit(_xamlReader.Value, GetCurrentLcid()); _xamlReader.Read(); // Move past data just processed. return(result); } else { // Bad Xaml (no top-level element). The Xaml filter should at some point raise an exception. // Just to be safe, ignore all content when in this state. _xamlReader.Read(); // Skip data. return(null); } }
// Token: 0x06006C4B RID: 27723 RVA: 0x001F3164 File Offset: 0x001F1364 private IndexingContentUnit HandleElementStart() { ElementTableKey elementTableKey = new ElementTableKey(this._xamlReader.NamespaceURI, this._xamlReader.LocalName); string a; if (this.IsPrefixedPropertyName(elementTableKey.BaseName, out a)) { ContentDescriptor contentDescriptor = this.TopOfStack(); if (contentDescriptor == null) { this.SkipCurrentElement(); return(null); } bool flag = elementTableKey.XmlNamespace.Equals(ElementTableKey.XamlNamespace, StringComparison.Ordinal) && (a == contentDescriptor.ContentProp || a == contentDescriptor.TitleProp); if (!flag) { this.SkipCurrentElement(); return(null); } this.Push(new ContentDescriptor(flag, this.TopOfStack().IsInline, string.Empty, null)); this._xamlReader.Read(); return(null); } else { bool flag2; IndexingContentUnit indexingContentUnit = this.HandleFixedFormatTag(elementTableKey, out flag2); if (flag2) { return(indexingContentUnit); } Invariant.Assert(indexingContentUnit == null); ContentDescriptor contentDescriptor2 = (ContentDescriptor)this._xamlElementContentDescriptorDictionary[elementTableKey]; if (contentDescriptor2 == null) { if (elementTableKey.XmlNamespace.Equals(ElementTableKey.XamlNamespace, StringComparison.Ordinal)) { contentDescriptor2 = this._defaultContentDescriptor; } else if (elementTableKey.XmlNamespace.Equals("http://schemas.microsoft.com/winfx/2006/xaml", StringComparison.Ordinal)) { contentDescriptor2 = this._nonIndexableElementDescriptor; } else { contentDescriptor2 = this.GetContentInformationAboutCustomElement(elementTableKey); } this._xamlElementContentDescriptorDictionary.Add(elementTableKey, contentDescriptor2); } if (!contentDescriptor2.HasIndexableContent) { this.SkipCurrentElement(); return(null); } if (contentDescriptor2.TitleProp != null && (this._attributesToIgnore & XamlFilter.AttributesToIgnore.Title) == XamlFilter.AttributesToIgnore.None) { string propertyAsAttribute = this.GetPropertyAsAttribute(contentDescriptor2.TitleProp); if (propertyAsAttribute != null && propertyAsAttribute.Length > 0) { this._attributesToIgnore |= XamlFilter.AttributesToIgnore.Title; this._expectingBlockStart = true; IndexingContentUnit result = this.BuildIndexingContentUnit(propertyAsAttribute, this.GetCurrentLcid()); this._expectingBlockStart = true; return(result); } } if (contentDescriptor2.ContentProp != null && (this._attributesToIgnore & XamlFilter.AttributesToIgnore.Content) == XamlFilter.AttributesToIgnore.None) { string propertyAsAttribute2 = this.GetPropertyAsAttribute(contentDescriptor2.ContentProp); if (propertyAsAttribute2 != null && propertyAsAttribute2.Length > 0) { this._attributesToIgnore |= XamlFilter.AttributesToIgnore.Content; if (!contentDescriptor2.IsInline) { this._expectingBlockStart = true; } IndexingContentUnit result2 = this.BuildIndexingContentUnit(propertyAsAttribute2, this.GetCurrentLcid()); this._expectingBlockStart = !contentDescriptor2.IsInline; return(result2); } } this._attributesToIgnore = XamlFilter.AttributesToIgnore.None; if (this._xamlReader.IsEmptyElement) { if (!contentDescriptor2.IsInline) { this._expectingBlockStart = true; } this._xamlReader.Read(); return(null); } this.Push(contentDescriptor2); this._xamlReader.Read(); return(null); } }
// Token: 0x06006C46 RID: 27718 RVA: 0x001F2F6C File Offset: 0x001F116C internal IndexingContentUnit NextContentUnit() { IndexingContentUnit indexingContentUnit = null; while (indexingContentUnit == null) { if (this._filterState == XamlFilter.FilterState.UseContentExtractor) { if (!this._fixedPageContentExtractor.AtEndOfPage) { bool flag; uint lcid; string text = this._fixedPageContentExtractor.NextGlyphContent(out flag, out lcid); this._expectingBlockStart = !flag; return(this.BuildIndexingContentUnit(text, lcid)); } this._fixedPageContentExtractor = null; this._topLevelReader = this._xamlReader; this._xamlReader = new XmlNodeReader(this._fixedPageDomTree.DocumentElement); this._filterState = XamlFilter.FilterState.FindNextFlowUnit; } if (this._xamlReader.EOF) { XamlFilter.FilterState filterState = this._filterState; if (filterState == XamlFilter.FilterState.FindNextUnit) { this._filterState = XamlFilter.FilterState.EndOfStream; return(null); } if (filterState == XamlFilter.FilterState.FindNextFlowUnit) { this._xamlReader.Close(); this._xamlReader = this._topLevelReader; this._filterState = XamlFilter.FilterState.FindNextUnit; } } XmlNodeType nodeType = this._xamlReader.NodeType; if (nodeType <= XmlNodeType.CDATA) { if (nodeType == XmlNodeType.Element) { indexingContentUnit = this.HandleElementStart(); continue; } if (nodeType - XmlNodeType.Text > 1) { goto IL_103; } } else if (nodeType != XmlNodeType.SignificantWhitespace) { if (nodeType != XmlNodeType.EndElement) { goto IL_103; } indexingContentUnit = this.HandleElementEnd(); continue; } indexingContentUnit = this.HandleTextData(); continue; IL_103: this._xamlReader.Read(); } return(indexingContentUnit); }
/// <summary>Ancillary function of NextContentUnit(). Create new chunk, taking _contextStack into /// account, and updating it if needed.</summary> private IndexingContentUnit BuildIndexingContentUnit(string text, uint lcid) { CHUNK_BREAKTYPE breakType = CHUNK_BREAKTYPE.CHUNK_NO_BREAK; // If a paragraph break is expected, reflect this in the new chunk. if (_expectingBlockStart) { breakType = CHUNK_BREAKTYPE.CHUNK_EOP; if (_returnCanonicalParagraphBreaks) text = _paragraphSeparator + text; } if (_indexingContentUnit == null) { _indexingContentUnit = new IndexingContentUnit(text, AllocateChunkID(), breakType, _propSpec, lcid); } else { // Optimization: reuse indexing content unit. _indexingContentUnit.InitIndexingContentUnit(text, AllocateChunkID(), breakType, _propSpec, lcid); } // Until proven separated (by the occurrence of a block tag), right neighbors are contiguous. _expectingBlockStart = false; return _indexingContentUnit; }
///<summary> /// If current token is an element start, then, /// if appropriate, extract chunk text from an attribute /// else, record content information and recurse. ///</summary> ///<remarks> /// Ancillary function of NextContentUnit. ///</remarks> private IndexingContentUnit HandleElementStart() { ElementTableKey elementFullName = new ElementTableKey(_xamlReader.NamespaceURI, _xamlReader.LocalName); string propertyName; // Handle the case of a complex property (e.g. Button.Content). if (IsPrefixedPropertyName(elementFullName.BaseName, out propertyName)) { ContentDescriptor topOfStack = TopOfStack(); // Handle the semantically incorrect case of a compound property occurring at the root // by ignoring it totally. if (topOfStack == null) { SkipCurrentElement(); return(null); } // Index the text children of property elements only if they are content or title properties. bool elementIsIndexable = (elementFullName.XmlNamespace.Equals(ElementTableKey.XamlNamespace, StringComparison.Ordinal) && (propertyName == topOfStack.ContentProp || propertyName == topOfStack.TitleProp)); if (!elementIsIndexable) { // Skip element together with all its descendants. SkipCurrentElement(); return(null); } // Push descriptor, advance reader, and have caller look further. Push( new ContentDescriptor( elementIsIndexable, TopOfStack().IsInline, String.Empty, // has potential text content, but no content property null)); // no title property _xamlReader.Read(); return(null); } // Handle fixed-format markup in a special way (because assumptions for building // content descriptors don't work for these and they require actions beyond what // is stated in content descriptors). // Note: The elementFullyHandled boolean is required as the nextUnit returned can // be null in both cases - when element is fully handled and when its not. bool elementFullyHandled; IndexingContentUnit nextUnit = HandleFixedFormatTag(elementFullName, out elementFullyHandled); if (elementFullyHandled) { return(nextUnit); } else { // When HandleFixedFormatTag declines to handle a tag because it is not fixed-format, it // will return null. Invariant.Assert(nextUnit == null); } // Obtain a content descriptor for the current element. ContentDescriptor elementDescriptor = (ContentDescriptor)_xamlElementContentDescriptorDictionary[elementFullName]; if (elementDescriptor == null) { if (elementFullName.XmlNamespace.Equals(ElementTableKey.XamlNamespace, StringComparison.Ordinal)) { elementDescriptor = _defaultContentDescriptor; } else if (elementFullName.XmlNamespace.Equals(_inDocumentCodeURI, StringComparison.Ordinal)) { elementDescriptor = _nonIndexableElementDescriptor; } else { elementDescriptor = GetContentInformationAboutCustomElement(elementFullName); } _xamlElementContentDescriptorDictionary.Add(elementFullName, elementDescriptor); } // If the element has no indexable content, skip all its descendants. if (!elementDescriptor.HasIndexableContent) { SkipCurrentElement(); return(null); } // If appropriate, retrieve title from an attribute. string title = null; if (elementDescriptor.TitleProp != null && (_attributesToIgnore & AttributesToIgnore.Title) == 0) { title = GetPropertyAsAttribute(elementDescriptor.TitleProp); if (title != null && title.Length > 0) { // Leave the reader in its present state, but return the title as a block chunk, // and mark this attribute as processed. _attributesToIgnore |= AttributesToIgnore.Title; _expectingBlockStart = true; IndexingContentUnit titleContent = BuildIndexingContentUnit(title, GetCurrentLcid()); _expectingBlockStart = true; // Simulate a stack pop for a block element. return(titleContent); } } // If appropriate, retrieve content from an attribute. string content = null; if (elementDescriptor.ContentProp != null && (_attributesToIgnore & AttributesToIgnore.Content) == 0) { content = GetPropertyAsAttribute(elementDescriptor.ContentProp); if (content != null && content.Length > 0) { // Leave the reader in its present state, but mark the content attribute // as processed. _attributesToIgnore |= AttributesToIgnore.Content; // Create a new chunk with appropriate break data. if (!elementDescriptor.IsInline) { _expectingBlockStart = true; } IndexingContentUnit result = BuildIndexingContentUnit(content, GetCurrentLcid()); // Emulate a stack pop for the content attribute (which never gets pushed on the stack). _expectingBlockStart = !elementDescriptor.IsInline; return(result); } } // Reset the attribute flag, since we are going to change the reader's state. _attributesToIgnore = AttributesToIgnore.None; // Handle the special case of an empty element: no descendants, but a possible paragraph break. if (_xamlReader.IsEmptyElement) { if (!elementDescriptor.IsInline) { _expectingBlockStart = true; } // Have caller search for content past the tag. _xamlReader.Read(); return(null); } // Have caller look for content in descendants. Push(elementDescriptor); _xamlReader.Read(); // skip start-tag return(null); }
///<summary>Return the next text chunk, or null at end of stream.</summary> internal IndexingContentUnit NextContentUnit() { // Loop until we are able to return some content or encounter an end of file. IndexingContentUnit nextContentUnit = null; while (nextContentUnit == null) { // If we have a content extractor delivering content units for us, use it. if (_filterState == FilterState.UseContentExtractor) { Debug.Assert(_fixedPageContentExtractor != null); // If we've consumed all the glyph run info, switch to a mode in which only the flow content // of the fixed page just scanned will be returned. if (_fixedPageContentExtractor.AtEndOfPage) { // Discard extractor. _fixedPageContentExtractor = null; // Set up reader. _topLevelReader = _xamlReader; _xamlReader = new XmlNodeReader(_fixedPageDomTree.DocumentElement); // Transition to flow-only mode. _filterState = FilterState.FindNextFlowUnit; } else { bool chunkIsInline; uint lcid; string chunk = _fixedPageContentExtractor.NextGlyphContent(out chunkIsInline, out lcid); _expectingBlockStart = !chunkIsInline; return(BuildIndexingContentUnit(chunk, lcid)); } } if (_xamlReader.EOF) { switch (_filterState) { // If in standard mode, return a null chunk to signal the end of all chunks. case FilterState.FindNextUnit: // A non-empty stack at this point could only be attributable to an internal error, // for an early EOF would have been reported as an XML exception by the XML reader. Debug.Assert(_contextStack.Count == 0); _filterState = FilterState.EndOfStream; return(null); // If processing a fixed page, revert to top-level XML reader. case FilterState.FindNextFlowUnit: Debug.Assert(_topLevelReader != null); _xamlReader.Close(); _xamlReader = _topLevelReader; _filterState = FilterState.FindNextUnit; break; default: Debug.Assert(false); break; } } switch (_xamlReader.NodeType) { // If current token is a text element, // if it can be part of its parent's content, return a chunk; // else, skip. case XmlNodeType.Text: case XmlNodeType.SignificantWhitespace: case XmlNodeType.CDATA: nextContentUnit = HandleTextData(); continue; // If current token is an element start, then, // if appropriate, extract chunk text from an attribute // else, record content information and recurse. case XmlNodeType.Element: nextContentUnit = HandleElementStart(); continue; // On end of element, restore context data (pop, etc.) and look further. case XmlNodeType.EndElement: nextContentUnit = HandleElementEnd(); continue; // Default action is to ignore current token and look further. // Note that non-significant whitespace is handled here. default: _xamlReader.Read(); // Consume current token. continue; } } return(nextContentUnit); }