Skip to content

Commit fad6641

Browse files
committed
#34 - Implement method CppStringT::ljust()
Completed.
1 parent e0f0489 commit fad6641

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

cpp-strings/cppstrings.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ namespace pcs // i.e. "pythonic c++ strings"
566566
return first + *this + this->join(others...);
567567
}
568568

569-
/** \brief A single parameter signature. Returns a copy of this parameter. */
569+
/** \brief Single parameter signature. Returns a copy of this parameter. */
570570
inline const CppStringT join(const CppStringT& s) const noexcept
571571
{
572572
return s;
@@ -579,6 +579,21 @@ namespace pcs // i.e. "pythonic c++ strings"
579579
}
580580

581581

582+
//--- ljust() -----------------------------------------
583+
/** \brief Returns the string left justified in a string of length width.
584+
*
585+
* Padding is done using the specified fillchar (default is an ASCII space).
586+
* The original string is returned if width is less than or equal to len(s).
587+
*/
588+
inline CppStringT ljust(const size_type width, const value_type fillch = value_type(' ')) const noexcept
589+
{
590+
if (this->size() >= width)
591+
return *this;
592+
else
593+
return CppStringT(width - this->size(), fillch) + *this;
594+
}
595+
596+
582597
//--- lower () -----------------------------------------
583598
/** \brief In-place replaces all characters of the string with their lowercase conversion. Returns a reference to string.
584599
*

0 commit comments

Comments
 (0)