1.1 --- a/lib/__builtins__/buffer.py Mon Nov 21 22:56:52 2016 +0100
1.2 +++ b/lib/__builtins__/buffer.py Tue Nov 22 01:28:58 2016 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Buffer object.
1.6
1.7 -Copyright (C) 2015 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2015, 2016 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 @@ -19,9 +19,39 @@
1.13 this program. If not, see <http://www.gnu.org/licenses/>.
1.14 """
1.15
1.16 +from native import _list_init, _list_append, _list_concat, _buffer_str
1.17 +
1.18 class buffer(object):
1.19 - def __init__(self, size): pass
1.20 - def append(self, s): pass
1.21 - def __str__(self): pass
1.22 +
1.23 + "A buffer, used to build strings."
1.24 +
1.25 + def __init__(self, args=None, size=None):
1.26 +
1.27 + "Initialise a buffer from the given 'args' or the given 'size'."
1.28 +
1.29 + self.__data__ = _list_init(len(args) or size or 0)
1.30 +
1.31 + # Append all arguments in string form to the buffer.
1.32 +
1.33 + if args:
1.34 + for arg in args:
1.35 + _list_append(self, str(arg))
1.36 +
1.37 + def append(self, s):
1.38 +
1.39 + "Append 's' to the buffer."
1.40 +
1.41 + if isinstance(s, buffer):
1.42 + _list_concat(self, s)
1.43 + elif isinstance(s, string):
1.44 + _list_append(self, s)
1.45 + else:
1.46 + raise TypeError(s)
1.47 +
1.48 + def __str__(self):
1.49 +
1.50 + "Return a string representation."
1.51 +
1.52 + return _buffer_str(self)
1.53
1.54 # vim: tabstop=4 expandtab shiftwidth=4