public void FlushBlock()
{
if (inBody == 0) {
if (inBody == 0 && Sharpen.Runtime.EqualsIgnoreCase ("TITLE", lastStartTag))
SetTitle (tokenBuilder.ToString ().Trim ());
textBuilder.Length = 0;
tokenBuilder.Length = 0;
return;
}
int length = tokenBuilder.Length;
if (length == 0) {
return;
} else if (length == 1) {
if (sbLastWasWhitespace) {
textBuilder.Length = 0;
tokenBuilder.Length = 0;
return;
}
}
string[] tokens = UnicodeTokenizer.Tokenize (tokenBuilder);
int numWords = 0;
int numLinkedWords = 0;
int numWrappedLines = 0;
int currentLineLength = -1; // don't count the first space
int maxLineLength = 80;
int numTokens = 0;
int numWordsCurrentLine = 0;
foreach (string token in tokens) {
if (token == ANCHOR_TEXT_START) {
inAnchorText = true;
} else {
if (token == ANCHOR_TEXT_END) {
inAnchorText = false;
} else {
if (IsWord (token)) {
numTokens++;
numWords++;
numWordsCurrentLine++;
if (inAnchorText) {
numLinkedWords++;
}
int tokenLength = token.Length;
currentLineLength += tokenLength + 1;
if (currentLineLength > maxLineLength) {
numWrappedLines++;
currentLineLength = tokenLength;
numWordsCurrentLine = 1;
}
} else {
numTokens++;
}
}
}
}
if (numTokens == 0) {
return;
}
int numWordsInWrappedLines;
if (numWrappedLines == 0) {
numWordsInWrappedLines = numWords;
numWrappedLines = 1;
} else {
numWordsInWrappedLines = numWords - numWordsCurrentLine;
}
TextBlock tb = new TextBlock (textBuilder.ToString ().Trim (), currentContainedTextElements
, numWords, numLinkedWords, numWordsInWrappedLines, numWrappedLines, offsetBlocks
);
currentContainedTextElements = new BitSet ();
offsetBlocks++;
textBuilder.Length = 0;
tokenBuilder.Length = 0;
tb.SetTagLevel (blockTagLevel);
AddTextBlock (tb);
blockTagLevel = -1;
}