# HG changeset patch # User Paul Boddie # Date 1480609030 -3600 # Node ID 9f7b491d750c71afb1886ee09e2e97e2c6dd4dcc # Parent fff09c70f4894f2983e588bbe0b7896b2502aad5 Tidied up the string class. diff -r fff09c70f489 -r 9f7b491d750c lib/__builtins__/str.py --- a/lib/__builtins__/str.py Wed Nov 30 18:44:58 2016 +0100 +++ b/lib/__builtins__/str.py Thu Dec 01 17:17:10 2016 +0100 @@ -19,26 +19,27 @@ this program. If not, see . """ -from __builtins__.identity import isclass -from __builtins__.iterator import listiterator from __builtins__.operator import _binary_op, _negate import native -class basestring(object): - def __init__(self, data=None): - # Note member. - self.__data__ = "" +class basestring: + + "The base class for all strings." + + def __init__(self): - def __contains__(self, value): pass + "Initialise the string." - def __getitem__(self, index): - # Note usage. - IndexError + # Note the __data__ member. Since strings are either initialised from + # literals or converted using routines defined for other types, no form + # of actual initialisation is performed here. - def __getslice__(self, start, end=None): pass + self.__data__ = None def __iadd__(self, other): + "Return a new string for the operation." + return _binary_op(self, other, native._str_add) __add__ = __radd__ = __iadd__ @@ -49,38 +50,54 @@ def __rmod__(self, other): pass def __lt__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._str_lt) def __gt__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._str_gt) def __le__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__gt__(other)) def __ge__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__lt__(other)) def __eq__(self, other): + "Return a new boolean for the comparison." + return _binary_op(self, other, native._str_eq) def __ne__(self, other): + "Return a new boolean for the comparison." + return _negate(self.__eq__(other)) def __len__(self): return native._str_len(self) def __str__(self): + "Return a string representation." + return self def __repr__(self): + "Return a program representation." + # NOTE: To be implemented with proper quoting. b = buffer(['"', self, '"']) return str(b)