public static string GetWord(TextPair p, byte side, int pos) { char c; StringBuilder word = new StringBuilder(); int length = p.GetLength(side); while (pos < length) { c = p.GetChar(side, pos); if (c == ' ' || c == '\t') if (word.Length == 0) { pos++; continue; } else break; if (c == '\n' || c == '\r') break; if (IsEasternCharacter(c)) return c.ToString(); word.Append(c); pos++; } return word.ToString(); }
void ProcessTextFromPair(TextPair p, byte side, ref int occLength, Collection<CommonWordInfo> words, ref int height, ref int MaxWidth, int requiredHeight) { if ((side == 1) ? p.AllLinesComputed1 : p.AllLinesComputed2) return; int pos; int wordPos; if (height == -1) { pos = 0; height = 0; if (side == 1) p.ContinueFromNewLine1 = false; else p.ContinueFromNewLine2 = false; } else { if (side == 1) { pos = p.CurrentPos1; if (p.ContinueFromNewLine1) { occLength = indentLength; p.ContinueFromNewLine1 = false; } } else { pos = p.CurrentPos2; if (p.ContinueFromNewLine2) { occLength = indentLength; p.ContinueFromNewLine2 = false; } } } wordPos = -1; char c; StringBuilder word = new StringBuilder(); int textLength = p.GetLength(side); while (pos < textLength) { // Must be slow c = p.GetChar(side, pos); if (c == ' ' || c == '\t' || c == '\r') { if (word.Length == 0) { pos++; continue; } ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false); if (requiredHeight != -1 && requiredHeight == height) goto CommonExit; wordPos = -1; } else if (c == '\n') { if (word.Length > 0) { ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false); if (requiredHeight != -1 && requiredHeight == height) { wordPos = pos; goto CommonExit; } wordPos = -1; } ParallelText.InsertWords(words, 0); height++; occLength = indentLength; if (requiredHeight != -1 && requiredHeight == height) { //height--; wordPos = ++pos; if (side == 1) p.ContinueFromNewLine1 = true; else p.ContinueFromNewLine2 = true; goto CommonExit; } } else if (IsEasternCharacter(c)) { if (word.Length != 0) { ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false); if (requiredHeight != -1 && requiredHeight == height) goto CommonExit; } word.Append(c); ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref pos, true); if (requiredHeight != -1 && requiredHeight == height) { wordPos = pos; goto CommonExit; } wordPos = -1; } else { if (wordPos == -1) wordPos = pos; word.Append(c); } pos++; } // Reached the end, process current Word (if there is any) if (word.Length > 0) { ProcessCurrentWord(word, ref occLength, words, ref height, p, side, ref MaxWidth, ref wordPos, false); if (requiredHeight != -1 && requiredHeight == height) goto CommonExit; } if (side == 1) p.AllLinesComputed1 = true; else p.AllLinesComputed2 = true; return; // Get here when the Height is reached CommonExit: if (side == 1) { p.CurrentPos1 = wordPos; } else { p.CurrentPos2 = wordPos; } }