1.1 --- a/lib/__builtins__/str.py Sat Jan 28 13:27:31 2017 +0100
1.2 +++ b/lib/__builtins__/str.py Sat Jan 28 22:37:41 2017 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 String objects.
1.6
1.7 -Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015, 2016, 2017 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -102,8 +102,20 @@
1.13
1.14 return self._binary_op_rev(str_add, other)
1.15
1.16 - def __mul__(self, other): pass
1.17 - def __rmul__(self, other): pass
1.18 + def __mul__(self, other):
1.19 +
1.20 + "Multiply the string by 'other'."
1.21 +
1.22 + b = buffer()
1.23 +
1.24 + while other > 0:
1.25 + b.append(self)
1.26 + other -= 1
1.27 +
1.28 + return str(b)
1.29 +
1.30 + __rmul__ = __mul__
1.31 +
1.32 def __mod__(self, other): pass
1.33 def __rmod__(self, other): pass
1.34
2.1 --- a/tests/string.py Sat Jan 28 13:27:31 2017 +0100
2.2 +++ b/tests/string.py Sat Jan 28 22:37:41 2017 +0100
2.3 @@ -64,3 +64,15 @@
2.4 print hash(s4)
2.5 print "# hash(s5):",
2.6 print hash(s5)
2.7 +
2.8 +# Test multiplication of strings.
2.9 +
2.10 +s6 = "abc"
2.11 +print s6 * -1 #
2.12 +print s6 * 0 #
2.13 +print s6 * 1 # abc
2.14 +print s6 * 2 # abcabc
2.15 +print -1 * s6 #
2.16 +print 0 * s6 #
2.17 +print 1 * s6 # abc
2.18 +print 2 * s6 # abcabc