File tree Expand file tree Collapse file tree 2 files changed +25
-1
lines changed
Expand file tree Collapse file tree 2 files changed +25
-1
lines changed Original file line number Diff line number Diff line change 3737#include < cctype>
3838#include < cstring>
3939#include < iostream>
40+ #include < sstream>
4041
4142namespace pystring
4243{
@@ -1048,7 +1049,24 @@ namespace pystring
10481049
10491050 return str.substr ( startp, endp - startp );
10501051 }
1051-
1052+
1053+
1054+ // ////////////////////////////////////////////////////////////////////////////////////////////
1055+ // /
1056+ // /
1057+ std::string mul ( const std::string & str, int n )
1058+ {
1059+ // Early exits
1060+ if (n <= 0 ) return " " ;
1061+ if (n == 1 ) return str;
1062+
1063+ std::ostringstream os;
1064+ for (int i=0 ; i<n; ++i)
1065+ {
1066+ os << str;
1067+ }
1068+ return os.str ();
1069+ }
10521070
10531071
10541072}// namespace pystring
Original file line number Diff line number Diff line change @@ -165,6 +165,12 @@ namespace pystring
165165 // /
166166 std::string lstrip ( const std::string & str, const std::string & chars = " " );
167167
168+ // ////////////////////////////////////////////////////////////////////////////////////////////
169+ // / @brief Return a copy of the string, concatenated N times, together.
170+ // / Corresponds to the __mul__ operator.
171+ // /
172+ std::string mul ( const std::string & str, int n);
173+
168174 // ////////////////////////////////////////////////////////////////////////////////////////////
169175 // / @brief Split the string around first occurance of sep.
170176 // / Three strings will always placed into result. If sep is found, the strings will
You can’t perform that action at this time.
0 commit comments