xlnt. rich_text copy constructor.

This commit is contained in:
Andrii Tkachenko 2018-02-08 07:24:58 +01:00
parent f460bb2678
commit 55cf7a2bed
2 changed files with 30 additions and 5 deletions

View File

@ -48,6 +48,11 @@ public:
/// </summary>
rich_text(const std::string &plain_text);
/// <summary>
/// Constructs a rich text object from other
/// </summary>
rich_text(const rich_text &other);
/// <summary>
/// Constructs a rich text object with the given text and font.
/// </summary>
@ -89,6 +94,11 @@ public:
/// </summary>
void add_run(const rich_text_run &t);
/// <summary>
/// Copies rich text object from other
/// </summary>
rich_text& operator=(const rich_text &rhs);
/// <summary>
/// Returns true if the runs that make up this text are identical to those in rhs.
/// </summary>

View File

@ -38,6 +38,18 @@ rich_text::rich_text(const std::string &plain_text, const class font &text_font)
{
}
rich_text::rich_text(const rich_text &other)
{
(*this) = other;
}
rich_text& rich_text::operator=(const rich_text &rhs)
{
runs_.clear();
runs_ = rhs.runs_;
return (*this);
}
rich_text::rich_text(const rich_text_run &single_run)
{
add_run(single_run);
@ -56,6 +68,9 @@ void rich_text::plain_text(const std::string &s)
std::string rich_text::plain_text() const
{
if (runs_.size() == 1)
return runs_.begin()->first;
return std::accumulate(runs_.begin(), runs_.end(), std::string(),
[](const std::string &a, const rich_text_run &run) { return a + run.first; });
}