File tree Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Expand file tree Collapse file tree 1 file changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -1393,10 +1393,24 @@ namespace pcs // i.e. "pythonic c++ strings"
13931393 }
13941394
13951395
1396- protected:
1397-
1396+ // --- zfill() -----------------------------------------
1397+ /* * \brief Returns a copy of the string left filled with ASCII '0' digits to make a string of length width.
1398+ *
1399+ * A leading sign prefix ('+'/'-') is handled by inserting the padding
1400+ * after the sign character rather than before. The original string is
1401+ * returned if width is less than or equal to len(s).
1402+ */
1403+ inline CppStringT zfill (const size_type width) const noexcept
1404+ {
1405+ if (this ->size () >= width)
1406+ return *this ;
13981407
1399- private:
1408+ const size_type padding_width = width - this ->size ();
1409+ if ((*this )[0 ] == ' +' || (*this )[0 ] == ' -' )
1410+ return (*this )[0 ] + this ->substr (1 , this ->size () - 1 ).ljust (padding_width, value_type (' 0' ));
1411+ else
1412+ return this ->ljust (padding_width, value_type (' 0' ));
1413+ }
14001414
14011415 };
14021416
You can’t perform that action at this time.
0 commit comments