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

@ -43,10 +43,15 @@ public:
/// </summary>
rich_text() = default;
/// <summary>
/// Constructs a rich text object with the given text and no font.
/// </summary>
rich_text(const std::string &plain_text);
/// <summary>
/// Constructs a rich text object with the given text and no font.
/// </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.
@ -89,7 +94,12 @@ public:
/// </summary>
void add_run(const rich_text_run &t);
/// <summary>
/// <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>
bool operator==(const rich_text &rhs) const;

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; });
}