Skip to content

Commit faaa942

Browse files
committed
#44 - Implement method CppStringT::rjust()
Completed.
1 parent f788380 commit faaa942

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

cpp-strings/cppstrings.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ namespace pcs // i.e. "pythonic c++ strings"
591591
if (this->size() >= width)
592592
return *this;
593593
else
594-
return CppStringT(width - this->size(), fillch) + *this;
594+
return *this + CppStringT(width - this->size(), fillch);
595595
}
596596

597597

@@ -850,6 +850,22 @@ namespace pcs // i.e. "pythonic c++ strings"
850850
}
851851

852852

853+
//--- rjust() -----------------------------------------
854+
/** \brief Returns the string right justified in a string of length width.
855+
*
856+
* Padding is done using the specified fillchar (default is an ASCII space).
857+
* The original string is returned if width is less than or equal to len(s).
858+
*/
859+
inline CppStringT rjust(const size_type width, const value_type fillch = value_type(' ')) const noexcept
860+
{
861+
if (this->size() >= width)
862+
return *this;
863+
else
864+
return CppStringT(width - this->size(), fillch) + *this;
865+
}
866+
867+
868+
853869
//--- title() -----------------------------------------
854870
/** \brief Returns a titlecased copy of the string where words start with an uppercase character and the remaining characters are lowercase. */
855871
inline CppStringT title() const noexcept

0 commit comments

Comments
 (0)