/// <summary>Convert string into a list of words/whitespace with contiguous formatting</summary> /// <param name="str">string.</param> /// <returns>List of words/whitespace with contiguous formatting</returns> PhraseList RichTextRenderer::GetWords(const RichParagraph& para) { RichCharList chars; // Flatten paragraph into list of characters chars += para.Characters; // Abort if empty string if (chars.empty()) return PhraseList(); // Get first char PhraseList phrases; phrases += RichPhrase(*chars.front()); // Transform into blocks of contiguous characters for_each(++chars.begin(), chars.end(), [&](const RichCharacter* ch) { RichPhrase& current = phrases.back(); // Create new word on colour/formatting change if (ch->Colour != current.Colour || ch->Format != current.Format) phrases += RichPhrase(*ch); // Create new word line-break and word-break else if (ch->Char == '\n' || iswspace(ch->Char) != iswspace(current.Text.front())) phrases += RichPhrase(*ch); // TODO: Prevent lines starting with punctuation else // Otherwise append to last phrase current += ch->Char; }); // return words return phrases; }
PhraseList PhraseList::operator |(PhraseList &other) { return PhraseList(this, &other); }
PhraseList PhraseList::operator |(const AbstractFieldPhrase &other) { return PhraseList(this, &other); }