protected internal void StripLeadingWhitespace(ref Fragment fragment) { int run = fragment.head; if (run != fragment.tail) { int runOffset = fragment.headOffset; CharClass charClass; if (this.runList[run].Type < RunType.Normal) { this.SkipNonTextRuns(ref run, ref runOffset, fragment.tail); } if (run == fragment.tail) { return; } do { InternalDebug.Assert(this.runList[run].Type >= RunType.Normal); if (this.runList[run].Type == RunType.Literal) { if (this.runList[run].Value > 0xFFFF) { break; } charClass = ParseSupport.GetCharClass((char)this.runList[run].Value); if (!ParseSupport.WhitespaceCharacter(charClass)) { break; } } else { int offset = runOffset; while (offset < runOffset + this.runList[run].Length) { charClass = ParseSupport.GetCharClass(this.buffer[offset]); if (!ParseSupport.WhitespaceCharacter(charClass)) { break; } offset++; } if (offset < runOffset + this.runList[run].Length) { this.runList[run].Length -= (offset - runOffset); runOffset = offset; break; } } runOffset += this.runList[run].Length; run++; if (run != fragment.tail && this.runList[run].Type < RunType.Normal) { this.SkipNonTextRuns(ref run, ref runOffset, fragment.tail); } }while (run != fragment.tail); fragment.head = run; fragment.headOffset = runOffset; } }
public override bool ReadMore(ref char[] buffer, ref int start, ref int current, ref int end) { InternalDebug.Assert((buffer == null && start == 0 && current == 0 && end == 0) || (buffer == this.parseBuffer && start == this.parseStart && end <= this.parseEnd && start <= current)); int charactersProduced = this.parseEnd - end; if (this.parseBuffer.Length - this.parseEnd <= 1 && !this.EnsureFreeSpace() && charactersProduced == 0) { return(true); } while (!this.endOfFile) { if (this.parseBuffer.Length - this.parseEnd <= 1) { InternalDebug.Assert(charactersProduced != 0); break; } if (this.pushSource != null) { if (this.pushChunkCount == 0) { InternalDebug.Assert(this.pushChunkUsed == 0); if (!this.pushSource.GetInputChunk(out this.pushChunkBuffer, out this.pushChunkStart, out this.pushChunkCount, out this.endOfFile)) { InternalDebug.Assert(0 == this.pushChunkCount); break; } InternalDebug.Assert((this.pushChunkCount != 0) != this.endOfFile); } InternalDebug.Assert(this.pushChunkCount - this.pushChunkUsed != 0 || this.endOfFile); if (this.pushChunkCount - this.pushChunkUsed != 0) { int charactersToAppend = Math.Min(this.pushChunkCount - this.pushChunkUsed, this.parseBuffer.Length - this.parseEnd - 1); Buffer.BlockCopy(this.pushChunkBuffer, (this.pushChunkStart + this.pushChunkUsed) * 2, this.parseBuffer, this.parseEnd * 2, charactersToAppend * 2); this.pushChunkUsed += charactersToAppend; this.parseEnd += charactersToAppend; this.parseBuffer[this.parseEnd] = '\0'; charactersProduced += charactersToAppend; if (this.pushChunkCount - this.pushChunkUsed == 0) { this.pushSource.ReportRead(this.pushChunkCount); this.pushChunkStart = 0; this.pushChunkCount = 0; this.pushChunkUsed = 0; this.pushChunkBuffer = null; } } } else { int readCharactersCount = this.pullSource.Read(this.parseBuffer, this.parseEnd, this.parseBuffer.Length - this.parseEnd - 1); if (readCharactersCount == 0) { this.endOfFile = true; } else { this.parseEnd += readCharactersCount; this.parseBuffer[this.parseEnd] = '\0'; charactersProduced += readCharactersCount; } if (this.progressMonitor != null) { this.progressMonitor.ReportProgress(); } } } buffer = this.parseBuffer; if (start != this.parseStart) { current = this.parseStart + (current - start); start = this.parseStart; } end = this.parseEnd; return(charactersProduced != 0 || this.endOfFile); }
private void AssertCurrent() { #if DEBUG InternalDebug.Assert(this.position.SameAs(this.token.unstructuredPosition)); #endif }
public bool CanAddProperty() { InternalDebug.Assert(this.state == BuildStateBeforeProperty); return(this.cssToken.propertyTail - this.cssToken.propertyHead < this.maxProperties); }
internal static int ExtractIndex(int attributeIndexAndCookie) { InternalDebug.Assert((attributeIndexAndCookie & 0x00FFFFFF) - 1 >= -1); return((attributeIndexAndCookie & 0x00FFFFFF) - 1); }
public void Inject(bool head, HtmlWriter writer) { if (head) { if (injectHead != null && !headInjected) { if (injectionFormat == HeaderFooterFormat.Text) { writer.WriteStartTag(HtmlNameIndex.TT); writer.WriteStartTag(HtmlNameIndex.Pre); writer.WriteNewLine(); } CreateHtmlToHtmlConverter(injectHead, writer); while (!fragmentToHtmlConverter.Flush()) { } headInjected = true; if (injectTail == null) { ((IDisposable)fragmentToHtmlConverter).Dispose(); fragmentToHtmlConverter = null; } if (injectionFormat == HeaderFooterFormat.Text) { writer.WriteEndTag(HtmlNameIndex.Pre); writer.WriteEndTag(HtmlNameIndex.TT); } } } else { if (injectHead != null && !headInjected) { InternalDebug.Assert(false); headInjected = true; } if (injectTail != null && !tailInjected) { if (injectionFormat == HeaderFooterFormat.Text) { writer.WriteStartTag(HtmlNameIndex.TT); writer.WriteStartTag(HtmlNameIndex.Pre); writer.WriteNewLine(); } if (fragmentToHtmlConverter == null) { CreateHtmlToHtmlConverter(injectTail, writer); } else { fragmentToHtmlConverter.Initialize( injectTail, (injectionFormat == HeaderFooterFormat.Text)); } while (!fragmentToHtmlConverter.Flush()) { } ((IDisposable)fragmentToHtmlConverter).Dispose(); fragmentToHtmlConverter = null; tailInjected = true; if (injectionFormat == HeaderFooterFormat.Text) { writer.WriteEndTag(HtmlNameIndex.Pre); writer.WriteEndTag(HtmlNameIndex.TT); } } } }
public IHtmlParser Push(bool head, IHtmlParser documentParser) { if (head) { if (injectHead != null && !headInjected) { this.documentParser = documentParser; if (fragmentParser == null) { fragmentParser = new HtmlParser( new ConverterBufferInput(injectHead, progressMonitor), false, (injectionFormat == HeaderFooterFormat.Text), 64, 8, testBoundaryConditions); } else { fragmentParser.Initialize( injectHead, (injectionFormat == HeaderFooterFormat.Text)); } injectingHead = true; return(fragmentParser); } } else { if (injectHead != null && !headInjected) { InternalDebug.Assert(false); headInjected = true; } if (injectTail != null && !tailInjected) { this.documentParser = documentParser; if (fragmentParser == null) { fragmentParser = new HtmlParser( new ConverterBufferInput(injectTail, progressMonitor), false, (injectionFormat == HeaderFooterFormat.Text), 64, 8, testBoundaryConditions); } else { fragmentParser.Initialize( injectTail, (injectionFormat == HeaderFooterFormat.Text)); } injectingHead = false; return(fragmentParser); } } return(documentParser); }
public void OutputFragment(FormatNode beginNode, uint beginTextPosition, FormatNode endNode, uint endTextPosition) { Restart(rootNode); var node = beginNode; var countStartLevels = 0; while (node != rootNode) { countStartLevels++; node = node.Parent; } if (outputStack == null) { InternalDebug.Assert(outputStackTop == 0 && formatStore != null); outputStack = new OutputStackEntry[Math.Max(32, countStartLevels)]; } else if (outputStack.Length < countStartLevels) { if (outputStackTop >= HtmlSupport.HtmlNestingLimit) { throw new TextConvertersException(Strings.InputDocumentTooComplex); } outputStack = new OutputStackEntry[Math.Max(outputStack.Length * 2, countStartLevels)]; } node = beginNode; var level = countStartLevels - 1; while (node != rootNode) { outputStack[level--].node = node; node = node.Parent; } InternalDebug.Assert(level == -1); for (level = 0; level < countStartLevels; level++) { if (!StartCurrentLevel()) { PopPushNextSibling(); break; } currentOutputLevel.state = OutputState.Started; Push(outputStack[level].node); } var endReached = false; while (currentOutputLevel.state != OutputState.Ended) { if (currentOutputLevel.state == OutputState.NotStarted) { if (StartCurrentLevel()) { PushFirstChild(); } else { PopPushNextSibling(); } } else if (currentOutputLevel.state == OutputState.Started) { InternalDebug.Assert(currentOutputLevel.node.NodeType == FormatContainerType.Text); var nodeBeginTextPosition = currentOutputLevel.node == beginNode ? beginTextPosition : currentOutputLevel.node.BeginTextPosition; var nodeEndTextPosition = currentOutputLevel.node == endNode ? endTextPosition : currentOutputLevel.node.EndTextPosition; if (nodeBeginTextPosition <= nodeEndTextPosition) { ContinueText(nodeBeginTextPosition, nodeEndTextPosition); } currentOutputLevel.state = OutputState.EndPending; } else { InternalDebug.Assert(currentOutputLevel.state == OutputState.EndPending); EndCurrentLevel(); currentOutputLevel.state = OutputState.Ended; if (outputStackTop != 0) { if (!endReached && currentOutputLevel.node != endNode && (currentOutputLevel.node.NextSibling.IsNull || currentOutputLevel.node.NextSibling != endNode || (currentOutputLevel.node.NextSibling.NodeType == FormatContainerType.Text && currentOutputLevel.node.NextSibling.BeginTextPosition < endTextPosition))) { PopPushNextSibling(); } else { Pop(); currentOutputLevel.state = OutputState.EndPending; endReached = true; } } } } InternalDebug.Assert(outputStackTop == 0); InternalDebug.Assert(propertyState.UndoStackTop == 0); }
private bool StartCurrentLevel() { switch (currentOutputLevel.node.NodeType) { case FormatContainerType.Root: return(StartRoot()); case FormatContainerType.Document: return(StartDocument()); case FormatContainerType.Fragment: return(StartFragment()); case FormatContainerType.BaseFont: StartEndBaseFont(); return(false); case FormatContainerType.Block: return(StartBlock()); case FormatContainerType.BlockQuote: return(StartBlockQuote()); case FormatContainerType.TableContainer: return(StartTableContainer()); case FormatContainerType.TableDefinition: return(StartTableDefinition()); case FormatContainerType.TableColumnGroup: return(StartTableColumnGroup()); case FormatContainerType.TableColumn: StartEndTableColumn(); return(false); case FormatContainerType.TableCaption: return(StartTableCaption()); case FormatContainerType.TableExtraContent: return(StartTableExtraContent()); case FormatContainerType.Table: return(StartTable()); case FormatContainerType.TableRow: return(StartTableRow()); case FormatContainerType.TableCell: return(StartTableCell()); case FormatContainerType.List: return(StartList()); case FormatContainerType.ListItem: return(StartListItem()); case FormatContainerType.HyperLink: return(StartHyperLink()); case FormatContainerType.Bookmark: return(StartBookmark()); case FormatContainerType.Image: StartEndImage(); return(false); case FormatContainerType.HorizontalLine: StartEndHorizontalLine(); return(false); case FormatContainerType.Inline: return(StartInline()); case FormatContainerType.Map: return(StartMap()); case FormatContainerType.Area: StartEndArea(); return(false); case FormatContainerType.Form: return(StartForm()); case FormatContainerType.FieldSet: return(StartFieldSet()); case FormatContainerType.Label: return(StartLabel()); case FormatContainerType.Input: return(StartInput()); case FormatContainerType.Button: return(StartButton()); case FormatContainerType.Legend: return(StartLegend()); case FormatContainerType.TextArea: return(StartTextArea()); case FormatContainerType.Select: return(StartSelect()); case FormatContainerType.OptionGroup: return(StartOptionGroup()); case FormatContainerType.Option: return(StartOption()); case FormatContainerType.Text: return(StartText()); } InternalDebug.Assert(false); return(true); }
public ConverterDecodingInput( Stream source, bool push, Encoding encoding, bool detectEncodingFromByteOrderMark, int maxParseToken, int restartMax, int inputBufferSize, bool testBoundaryConditions, IResultsFeedback resultFeedback, IProgressMonitor progressMonitor) : base(progressMonitor) { this.resultFeedback = resultFeedback; this.restartMax = restartMax; if (push) { InternalDebug.Assert(source is ConverterStream); pushSource = source as ConverterStream; } else { InternalDebug.Assert(source.CanRead); pullSource = source; } this.detectEncodingFromByteOrderMark = detectEncodingFromByteOrderMark; minDecodeBytes = testBoundaryConditions ? 1 : 64; originalEncoding = encoding; SetNewEncoding(encoding); InternalDebug.Assert(minDecodeBytes == 1 || minDecodeBytes >= Math.Max(4, preamble.Length)); maxTokenSize = (maxParseToken == Int32.MaxValue) ? maxParseToken : testBoundaryConditions ? maxParseToken : (maxParseToken + 1023) / 1024 * 1024; parseBuffer = new char[testBoundaryConditions ? 55 : Math.Min(4096, (long)maxTokenSize + (minDecodeChars + 1))]; if (pushSource != null) { readBuffer = new byte[Math.Max(minDecodeBytes * 2, 8)]; } else { var size = Math.Max(CalculateMaxBytes(parseBuffer.Length), inputBufferSize); readBuffer = new byte[size]; } }
private bool EnsureFreeSpace() { InternalDebug.Assert(parseBuffer.Length - parseEnd <= minDecodeChars); if (parseBuffer.Length - (parseEnd - parseStart) < (minDecodeChars + 1) || (parseStart < minDecodeChars && (long)parseBuffer.Length < (long)maxTokenSize + (minDecodeChars + 1))) { if ((long)parseBuffer.Length >= (long)maxTokenSize + (minDecodeChars + 1)) { return(false); } long newSize = parseBuffer.Length * 2; if (newSize > (long)maxTokenSize + (minDecodeChars + 1)) { newSize = (long)maxTokenSize + (minDecodeChars + 1); } if (newSize > (long)Int32.MaxValue) { newSize = (long)Int32.MaxValue; } if (newSize - (parseEnd - parseStart) < (minDecodeChars + 1)) { return(false); } char[] newBuffer; try { newBuffer = new char[(int)newSize]; } catch (OutOfMemoryException e) { throw new TextConvertersException(Strings.TagTooLong, e); } Buffer.BlockCopy(parseBuffer, parseStart * 2, newBuffer, 0, (parseEnd - parseStart + 1) * 2); parseBuffer = newBuffer; parseEnd = (parseEnd - parseStart); parseStart = 0; } else { Buffer.BlockCopy(parseBuffer, parseStart * 2, parseBuffer, 0, (parseEnd - parseStart + 1) * 2); parseEnd = (parseEnd - parseStart); parseStart = 0; } return(true); }
private int DecodeFromBuffer(byte[] buffer, ref int start, int end, int fileOffset, bool flush) { var preambleLength = 0; if (fileOffset == 0) { if (detectEncodingFromByteOrderMark) { DetectEncoding(buffer, start, end); } InternalDebug.Assert(preamble != null); if (preamble.Length != 0 && end - start >= preamble.Length) { int i; for (i = 0; i < preamble.Length; i++) { if (preamble[i] != buffer[start + i]) { break; } } if (i == preamble.Length) { start += preamble.Length; preambleLength = preamble.Length; if (restartConsumer != null) { restartConsumer.DisableRestart(); restartConsumer = null; } } } encodingChanged = true; preamble = null; } var bytesToDecode = end - start; if (GetMaxCharCount(bytesToDecode) >= parseBuffer.Length - parseEnd) { bytesToDecode = CalculateMaxBytes(parseBuffer.Length - parseEnd - 1); InternalDebug.Assert(bytesToDecode < end - start); } var charsDecoded = decoder.GetChars(buffer, start, bytesToDecode, parseBuffer, parseEnd); InternalDebug.Assert(charsDecoded <= parseBuffer.Length - parseEnd - 1); parseEnd += charsDecoded; parseBuffer[parseEnd] = '\0'; start += bytesToDecode; return(bytesToDecode + preambleLength); }
public override bool ReadMore(ref char[] buffer, ref int start, ref int current, ref int end) { InternalDebug.Assert((buffer == null && start == 0 && current == 0 && end == 0) || (buffer == parseBuffer && start == parseStart && end == parseEnd && start <= current && current <= end)); if (parseBuffer.Length - parseEnd <= minDecodeChars && !EnsureFreeSpace()) { return(true); } var charactersProduced = 0; while (!rawEndOfFile || readEnd - readCurrent != 0 || restarting) { if (parseBuffer.Length - parseEnd <= minDecodeChars) { InternalDebug.Assert(charactersProduced != 0); break; } if (readEnd - readCurrent >= (readFileOffset == 0 ? Math.Max(4, minDecodeBytes) : minDecodeBytes) || (rawEndOfFile && !restarting)) { InternalDebug.Assert(readEnd - readCurrent != 0); charactersProduced += DecodeFromBuffer(readBuffer, ref readCurrent, readEnd, readFileOffset + readCurrent, rawEndOfFile); } else { if (restarting) { InternalDebug.Assert(readEnd - readCurrent == 0); byte[] restartChunk; int restartStart, restartStartSave; int restartEnd; if (!GetRestartChunk(out restartChunk, out restartStart, out restartEnd)) { restarting = false; continue; } restartStartSave = restartStart; charactersProduced += DecodeFromBuffer(restartChunk, ref restartStart, restartEnd, readFileOffset, false); readFileOffset += (restartStart - restartStartSave); ReportRestartChunkUsed(restartStart - restartStartSave); } else if (pushSource != null) { if (pushChunkCount == 0) { InternalDebug.Assert(pushChunkUsed == 0); if (!pushSource.GetInputChunk(out pushChunkBuffer, out pushChunkStart, out pushChunkCount, out rawEndOfFile)) { InternalDebug.Assert(0 == pushChunkCount); break; } InternalDebug.Assert((pushChunkCount != 0) != rawEndOfFile); } else if (pushChunkCount - pushChunkUsed == 0) { if (restartConsumer != null) { BackupForRestart(pushChunkBuffer, pushChunkStart, pushChunkCount, readFileOffset, false); } pushSource.ReportRead(pushChunkCount); readFileOffset += pushChunkCount; pushChunkCount = 0; pushChunkUsed = 0; InternalDebug.Assert(!pushSource.GetInputChunk(out pushChunkBuffer, out pushChunkStart, out pushChunkCount, out rawEndOfFile) && pushChunkCount == 0 && !rawEndOfFile); break; } if (pushChunkCount - pushChunkUsed < (readFileOffset == 0 ? Math.Max(4, minDecodeBytes) : minDecodeBytes)) { if (pushChunkCount - pushChunkUsed != 0) { InternalDebug.Assert(readEnd - readCurrent + (pushChunkCount - pushChunkUsed) <= readBuffer.Length); if (readBuffer.Length - readEnd < (pushChunkCount - pushChunkUsed)) { if (restartConsumer != null) { BackupForRestart(readBuffer, 0, readCurrent, readFileOffset, false); } Buffer.BlockCopy(readBuffer, readCurrent, readBuffer, 0, readEnd - readCurrent); readFileOffset += readCurrent; readEnd = readEnd - readCurrent; readCurrent = 0; } if (pushChunkUsed != 0) { InternalDebug.Assert(readEnd == 0); if (restartConsumer != null) { BackupForRestart(pushChunkBuffer, pushChunkStart, pushChunkUsed, readFileOffset + readEnd, false); } readFileOffset += pushChunkUsed; } Buffer.BlockCopy(pushChunkBuffer, pushChunkStart + pushChunkUsed, readBuffer, readEnd, pushChunkCount - pushChunkUsed); readEnd += pushChunkCount - pushChunkUsed; pushSource.ReportRead(pushChunkCount); pushChunkCount = 0; pushChunkUsed = 0; if (readEnd - readCurrent < (readFileOffset == 0 ? Math.Max(4, minDecodeBytes) : minDecodeBytes)) { break; } } charactersProduced += DecodeFromBuffer(readBuffer, ref readCurrent, readEnd, readFileOffset + readCurrent, rawEndOfFile); } else if (readEnd - readCurrent != 0) { if (readFileOffset == 0 && readCurrent == 0) { InternalDebug.Assert(pushChunkUsed == 0); InternalDebug.Assert(readEnd - readCurrent < Math.Max(4, minDecodeBytes)); InternalDebug.Assert(pushChunkCount - pushChunkUsed >= Math.Max(4, minDecodeBytes)); var bytesToAppend = Math.Max(4, minDecodeBytes) - (readEnd - readCurrent); Buffer.BlockCopy(pushChunkBuffer, pushChunkStart + pushChunkUsed, readBuffer, readEnd, bytesToAppend); readEnd += bytesToAppend; pushSource.ReportRead(bytesToAppend); pushChunkCount -= bytesToAppend; pushChunkStart += bytesToAppend; } charactersProduced += DecodeFromBuffer(readBuffer, ref readCurrent, readEnd, readFileOffset + readCurrent, false); } if (parseBuffer.Length - parseEnd > minDecodeChars && pushChunkCount - pushChunkUsed != 0 && readEnd - readCurrent == 0) { InternalDebug.Assert(!rawEndOfFile); if (readEnd != 0) { if (restartConsumer != null) { BackupForRestart(readBuffer, 0, readCurrent, readFileOffset, false); } readFileOffset += readCurrent; readEnd = 0; readCurrent = 0; } var chunkUnusedStart = pushChunkStart + pushChunkUsed; charactersProduced += DecodeFromBuffer(pushChunkBuffer, ref chunkUnusedStart, pushChunkStart + pushChunkCount, readFileOffset + pushChunkUsed, false); pushChunkUsed = chunkUnusedStart - pushChunkStart; } } else { if (readBuffer.Length - readEnd < minDecodeBytes) { InternalDebug.Assert(readEnd - readCurrent < (readFileOffset == 0 ? Math.Max(4, minDecodeBytes) : minDecodeBytes)); if (restartConsumer != null) { BackupForRestart(readBuffer, 0, readCurrent, readFileOffset, false); } Buffer.BlockCopy(readBuffer, readCurrent, readBuffer, 0, readEnd - readCurrent); readFileOffset += readCurrent; readEnd = readEnd - readCurrent; readCurrent = 0; } var readCount = pullSource.Read(readBuffer, readEnd, readBuffer.Length - readEnd); if (readCount == 0) { rawEndOfFile = true; } else { readEnd += readCount; if (progressMonitor != null) { progressMonitor.ReportProgress(); } } charactersProduced += DecodeFromBuffer(readBuffer, ref readCurrent, readEnd, readFileOffset + readCurrent, rawEndOfFile); } } } if (rawEndOfFile && readEnd - readCurrent == 0) { endOfFile = true; } if (buffer != parseBuffer) { buffer = parseBuffer; } if (start != parseStart) { current = parseStart + (current - start); start = parseStart; } end = parseEnd; return(charactersProduced != 0 || endOfFile || encodingChanged); }
public bool IsUnsafeExtendedCharacter(char ch) { if (ranges == null) { InternalDebug.Assert(false); return false; } if (ch <= lastRange.last) { if (ch >= lastRange.first) { return lastRange.offset != 0xFFFFu && (bitmap[lastRange.offset + (ch - lastRange.first)] & lastRange.mask) == 0; } else { var i = lastRangeIndex; while (--i >= 0) { if (ch >= ranges[i].first) { if (ch <= ranges[i].last) { if (ch == ranges[i].first) { return false; } lastRangeIndex = i; lastRange = ranges[i]; return lastRange.offset != 0xFFFFu && (bitmap[lastRange.offset + (ch - lastRange.first)] & lastRange.mask) == 0; } break; } } } } else { var i = lastRangeIndex; while (++ i < ranges.Length) { if (ch <= ranges[i].last) { if (ch >= ranges[i].first) { if (ch == ranges[i].first) { return false; } lastRangeIndex = i; lastRange = ranges[i]; return lastRange.offset != 0xFFFFu && (bitmap[lastRange.offset + (ch - lastRange.first)] & lastRange.mask) == 0; } break; } } } return true; }
public void AddSpecialRun(RunKind kind, int startEnd, int value) { InternalDebug.Assert(startEnd == tailOffset); AddRun(RunType.Special, RunTextType.Unknown, (uint)kind, tailOffset, startEnd, value); }
private void EndCurrentLevel() { switch (currentOutputLevel.node.NodeType) { #if DEBUG default: case FormatContainerType.BaseFont: case FormatContainerType.Image: case FormatContainerType.HorizontalLine: case FormatContainerType.Area: case FormatContainerType.TableColumn: InternalDebug.Assert(false); break; #endif case FormatContainerType.Root: EndRoot(); break; case FormatContainerType.Document: EndDocument(); break; case FormatContainerType.Fragment: EndFragment(); break; case FormatContainerType.Block: EndBlock(); break; case FormatContainerType.BlockQuote: EndBlockQuote(); break; case FormatContainerType.TableContainer: EndTableContainer(); break; case FormatContainerType.TableDefinition: EndTableDefinition(); break; case FormatContainerType.TableColumnGroup: EndTableColumnGroup(); break; case FormatContainerType.TableCaption: EndTableCaption(); break; case FormatContainerType.TableExtraContent: EndTableExtraContent(); break; case FormatContainerType.Table: EndTable(); break; case FormatContainerType.TableRow: EndTableRow(); break; case FormatContainerType.TableCell: EndTableCell(); break; case FormatContainerType.List: EndList(); break; case FormatContainerType.ListItem: EndListItem(); break; case FormatContainerType.HyperLink: EndHyperLink(); break; case FormatContainerType.Bookmark: EndBookmark(); break; case FormatContainerType.Inline: EndInline(); break; case FormatContainerType.Map: EndMap(); break; case FormatContainerType.Form: EndForm(); break; case FormatContainerType.FieldSet: EndFieldSet(); break; case FormatContainerType.Label: EndLabel(); break; case FormatContainerType.Input: EndInput(); break; case FormatContainerType.Button: EndButton(); break; case FormatContainerType.Legend: EndLegend(); break; case FormatContainerType.TextArea: EndTextArea(); break; case FormatContainerType.Select: EndSelect(); break; case FormatContainerType.OptionGroup: EndOptionGroup(); break; case FormatContainerType.Option: EndOption(); break; case FormatContainerType.Text: EndText(); break; } }
internal void AddSentinelRun() { InternalDebug.Assert(token.whole.tail + 1 <= token.runList.Length); token.runList[token.whole.tail].InitializeSentinel(); }
public override void ReportProcessed(int processedSize) { InternalDebug.Assert(processedSize >= 0); this.progressMonitor.ReportProgress(); }
public override void Inject(bool head, TextOutput output) { HtmlParser parser; if (head) { if (injectHead != null && !headInjected) { parser = new HtmlParser( new ConverterBufferInput(injectHead, progressMonitor), false, (injectionFormat == HeaderFooterFormat.Text), 64, 8, testBoundaryConditions); fragmentToTextConverter = new HtmlToTextConverter( parser, output, null, true, injectionFormat == HeaderFooterFormat.Text, false, traceStream, true, 0); while (!fragmentToTextConverter.Flush()) { } headInjected = true; if (injectTail == null) { ((IDisposable)fragmentToTextConverter).Dispose(); fragmentToTextConverter = null; } } } else { if (injectHead != null && !headInjected) { InternalDebug.Assert(false); headInjected = true; } if (injectTail != null && !tailInjected) { if (fragmentToTextConverter == null) { parser = new HtmlParser( new ConverterBufferInput(injectTail, progressMonitor), false, (injectionFormat == HeaderFooterFormat.Text), 64, 8, testBoundaryConditions); fragmentToTextConverter = new HtmlToTextConverter( parser, output, null, true, injectionFormat == HeaderFooterFormat.Text, false, traceStream, true, 0); } else { fragmentToTextConverter.Initialize( injectTail, (injectionFormat == HeaderFooterFormat.Text)); } while (!fragmentToTextConverter.Flush()) { } ((IDisposable)fragmentToTextConverter).Dispose(); fragmentToTextConverter = null; tailInjected = true; } } }
public void AssertPreparedToAddMoreRuns(int numRuns) { #if DEBUG InternalDebug.Assert(numRuns <= preparedForNumRuns); #endif }
public int GetBestWindowsCodePage(bool allowCommonFallbackExceptions, bool allowAnyFallbackExceptions, int preferredCodePage) { uint mask; var totalCount = 0; if (codePageList == null) { codePageList = new int[CodePageDetectData.codePages.Length + 1]; } else { for (var j = 0; j < codePageList.Length; j++) { codePageList[j] = 0; } } for (var i = 0; i < maskMap.Length; i++) { if (maskMap[i] != 0) { mask = CodePageDetectData.codePageMask[i]; if (allowAnyFallbackExceptions || (allowCommonFallbackExceptions && (CodePageDetectData.fallbackMask[i] & CodePageDetectData.commonFallbackMask) != 0)) { mask |= CodePageDetectData.fallbackMask[i] & ~CodePageDetectData.commonFallbackMask; } mask &= CodePageDetectData.windowsCodePagesMask; if (0 != mask) { for (var j = 0; mask != 0; j++, mask >>= 1) { if (0 != (mask & 1u)) { codePageList[j] += maskMap[i]; } } } totalCount += maskMap[i]; } } var maximumCount = 0; var maximumCodePageIndex = 0; mask = CodePageDetectData.windowsCodePagesMask; for (var j = 0; mask != 0; j++) { if (CodePageDetectData.codePages[j].windowsCodePage && codePageList[j] > maximumCount) { maximumCount = codePageList[j]; maximumCodePageIndex = j; } else if (codePageList[j] == maximumCount && ((CodePageDetectData.codePages[j].cpid == 1252) || (CodePageDetectData.codePages[j].cpid == preferredCodePage))) { maximumCodePageIndex = j; } mask &= ~CodePageDetectData.codePages[j].mask; } InternalDebug.Assert(maximumCodePageIndex > 0 && maximumCodePageIndex < CodePageDetectData.codePages.Length); return(CodePageDetectData.codePages[maximumCodePageIndex].cpid); }
public void AssertCanAddMoreRuns(int numRuns) { InternalDebug.Assert(token.whole.tail + numRuns <= token.runList.Length); }
/// <summary> /// Decides if an extended chracter is unsafe for the current codepage. /// </summary> /// <param name="ch">The character to check.</param> /// <returns>True if the character is unsafe, otherwise false.</returns> public bool IsUnsafeExtendedCharacter(char ch) { if (this.ranges == null) { InternalDebug.Assert(false); return(false); } if (ch <= this.lastRange.Last) { if (ch >= this.lastRange.First) { return(this.lastRange.Offset != 0xFFFFu && (Bitmap[this.lastRange.Offset + (ch - this.lastRange.First)] & this.lastRange.Mask) == 0); } int i = this.lastRangeIndex; while (--i >= 0) { if (ch < this.ranges[i].First) { continue; } if (ch <= this.ranges[i].Last) { if (ch == this.ranges[i].First) { return(false); } this.lastRangeIndex = i; this.lastRange = this.ranges[i]; return(this.lastRange.Offset != 0xFFFFu && (Bitmap[this.lastRange.Offset + (ch - this.lastRange.First)] & this.lastRange.Mask) == 0); } break; } } else { int i = this.lastRangeIndex; while (++i < this.ranges.Length) { if (ch > this.ranges[i].Last) { continue; } if (ch >= this.ranges[i].First) { if (ch == this.ranges[i].First) { return(false); } this.lastRangeIndex = i; this.lastRange = this.ranges[i]; return(this.lastRange.Offset != 0xFFFFu && (Bitmap[this.lastRange.Offset + (ch - this.lastRange.First)] & this.lastRange.Mask) == 0); } break; } } return(true); }
public void AssertCurrentRunPosition(int position) { InternalDebug.Assert(position == tailOffset); }
internal static int ComposeIndexAndCookie(byte cookie, int attributeIndex) { InternalDebug.Assert(attributeIndex >= -1); return(((int)cookie << 24) + (attributeIndex + 1)); }
public void AddTextRun(RunTextType textType, int start, int end) { InternalDebug.Assert(start == tailOffset); AddRun(RunType.Normal, textType, (uint)RunKind.Text, start, end, 0); }
private void AssertCurrent() { #if DEBUG InternalDebug.Assert(this.token.currentAttribute == this.index); #endif }
public void AddLiteralTextRun(RunTextType textType, int start, int end, int literal) { InternalDebug.Assert(start == tailOffset); AddRun(RunType.Literal, textType, (uint)RunKind.Text, start, end, literal); }
private void AssertCurrent() { #if DEBUG InternalDebug.Assert(this.position.SameAs(this.token.attrNamePosition)); #endif }
protected internal int Read(LexicalUnit unit, ref FragmentPosition position, char[] buffer, int offset, int count) { InternalDebug.Assert(count != 0); int startOffset = offset; if (unit.head != -1) { uint kind = this.runList[unit.head].MajorKind; int run = position.run; if (run == unit.head - 1) { run = position.run = unit.head; } RunEntry runEntry = this.runList[run]; if (run == unit.head || runEntry.MajorKindPlusStartFlag == kind) { int runOffset = position.runOffset; int runDeltaOffset = position.runDeltaOffset; do { InternalDebug.Assert(count != 0); if (runEntry.Type == RunType.Literal) { int literalLength = Token.LiteralLength(runEntry.Value); if (runDeltaOffset != literalLength) { if (literalLength == 1) { InternalDebug.Assert(runDeltaOffset == 0); buffer[offset++] = (char)runEntry.Value; count--; } else { InternalDebug.Assert(literalLength == 2); if (runDeltaOffset != 0) { InternalDebug.Assert(runDeltaOffset == 1); buffer[offset++] = Token.LiteralLastChar(runEntry.Value); count--; } else { buffer[offset++] = Token.LiteralFirstChar(runEntry.Value); count--; if (count == 0) { runDeltaOffset = 1; break; } buffer[offset++] = Token.LiteralLastChar(runEntry.Value); count--; } } } } else if (runEntry.Type == RunType.Normal) { InternalDebug.Assert(runDeltaOffset >= 0 && runDeltaOffset < runEntry.Length); int copyCount = Math.Min(count, runEntry.Length - runDeltaOffset); InternalDebug.Assert(copyCount != 0); { Buffer.BlockCopy(this.buffer, (runOffset + runDeltaOffset) * 2, buffer, offset * 2, copyCount * 2); offset += copyCount; count -= copyCount; if (runDeltaOffset + copyCount != runEntry.Length) { runDeltaOffset += copyCount; break; } } } runOffset += runEntry.Length; runDeltaOffset = 0; runEntry = this.runList[++run]; }while (runEntry.MajorKindPlusStartFlag == kind && count != 0); position.run = run; position.runOffset = runOffset; position.runDeltaOffset = runDeltaOffset; } } return(offset - startOffset); }