paul@6 | 1 | #!/usr/bin/env python |
paul@6 | 2 | |
paul@6 | 3 | """ |
paul@6 | 4 | String objects. |
paul@6 | 5 | |
paul@6 | 6 | Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk> |
paul@6 | 7 | |
paul@6 | 8 | This program is free software; you can redistribute it and/or modify it under |
paul@6 | 9 | the terms of the GNU General Public License as published by the Free Software |
paul@6 | 10 | Foundation; either version 3 of the License, or (at your option) any later |
paul@6 | 11 | version. |
paul@6 | 12 | |
paul@6 | 13 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@6 | 14 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@6 | 15 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@6 | 16 | details. |
paul@6 | 17 | |
paul@6 | 18 | You should have received a copy of the GNU General Public License along with |
paul@6 | 19 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@6 | 20 | """ |
paul@6 | 21 | |
paul@9 | 22 | from __builtins__.iterator import listiterator |
paul@9 | 23 | from __builtins__.operator import _binary_op, _negate |
paul@6 | 24 | import native |
paul@6 | 25 | |
paul@6 | 26 | class basestring(object): |
paul@6 | 27 | def __init__(self, data=None): |
paul@6 | 28 | # Note member. |
paul@135 | 29 | self.__data__ = "" |
paul@6 | 30 | |
paul@6 | 31 | def __contains__(self, value): pass |
paul@6 | 32 | |
paul@6 | 33 | def __getitem__(self, index): |
paul@6 | 34 | # Note usage. |
paul@6 | 35 | IndexError |
paul@6 | 36 | |
paul@6 | 37 | def __getslice__(self, start, end=None): pass |
paul@6 | 38 | |
paul@6 | 39 | def __iadd__(self, other): |
paul@6 | 40 | "Return a new string for the operation." |
paul@6 | 41 | return _binary_op(self, other, native._str_add) |
paul@6 | 42 | |
paul@6 | 43 | __add__ = __radd__ = __iadd__ |
paul@6 | 44 | |
paul@6 | 45 | def __mul__(self, other): pass |
paul@6 | 46 | def __rmul__(self, other): pass |
paul@6 | 47 | def __mod__(self, other): pass |
paul@6 | 48 | def __rmod__(self, other): pass |
paul@6 | 49 | |
paul@6 | 50 | def __lt__(self, other): |
paul@6 | 51 | "Return a new boolean for the comparison." |
paul@6 | 52 | return _binary_op(self, other, native._str_lt) |
paul@6 | 53 | |
paul@6 | 54 | def __gt__(self, other): |
paul@6 | 55 | "Return a new boolean for the comparison." |
paul@6 | 56 | return _binary_op(self, other, native._str_gt) |
paul@6 | 57 | |
paul@6 | 58 | def __le__(self, other): |
paul@6 | 59 | "Return a new boolean for the comparison." |
paul@6 | 60 | return _negate(self.__gt__(other)) |
paul@6 | 61 | |
paul@6 | 62 | def __ge__(self, other): |
paul@6 | 63 | "Return a new boolean for the comparison." |
paul@6 | 64 | return _negate(self.__lt__(other)) |
paul@6 | 65 | |
paul@6 | 66 | def __eq__(self, other): |
paul@6 | 67 | "Return a new boolean for the comparison." |
paul@6 | 68 | return _binary_op(self, other, native._str_eq) |
paul@6 | 69 | |
paul@6 | 70 | def __ne__(self, other): |
paul@6 | 71 | "Return a new boolean for the comparison." |
paul@6 | 72 | return _negate(self.__eq__(other)) |
paul@6 | 73 | |
paul@140 | 74 | def __len__(self): |
paul@140 | 75 | return native._str_len(self) |
paul@140 | 76 | |
paul@188 | 77 | def __str__(self): |
paul@222 | 78 | "Return a string representation." |
paul@188 | 79 | return self |
paul@6 | 80 | |
paul@222 | 81 | def __repr__(self): |
paul@222 | 82 | "Return a string literal representation." |
paul@222 | 83 | # NOTE: To be implemented with proper quoting. |
paul@222 | 84 | b = buffer(['"', self, '"']) |
paul@222 | 85 | return str(b) |
paul@222 | 86 | |
paul@6 | 87 | def __bool__(self): |
paul@140 | 88 | return native._str_nonempty(self) |
paul@6 | 89 | |
paul@6 | 90 | def endswith(self, s): pass |
paul@6 | 91 | def find(self, sub, start=None, end=None): pass |
paul@6 | 92 | def index(self, sub, start=None, end=None): pass |
paul@6 | 93 | def join(self, l): pass |
paul@6 | 94 | def lower(self): pass |
paul@6 | 95 | def lstrip(self, chars=None): pass |
paul@6 | 96 | def replace(self, old, new, count=None): pass |
paul@6 | 97 | def rfind(self, sub, start=None, end=None): pass |
paul@6 | 98 | def rsplit(self, sep=None, maxsplit=None): pass |
paul@6 | 99 | def rstrip(self, chars=None): pass |
paul@6 | 100 | def split(self, sep=None, maxsplit=None): pass |
paul@6 | 101 | def splitlines(self, keepends=False): pass |
paul@6 | 102 | def startswith(self, s): pass |
paul@6 | 103 | def strip(self, chars=None): pass |
paul@6 | 104 | def upper(self): pass |
paul@6 | 105 | |
paul@188 | 106 | class string(basestring): |
paul@6 | 107 | pass |
paul@6 | 108 | |
paul@6 | 109 | class unicode(basestring): |
paul@6 | 110 | def encode(self, encoding): pass |
paul@6 | 111 | |
paul@188 | 112 | def str(obj): |
paul@188 | 113 | |
paul@188 | 114 | "Return the string representation of 'obj'." |
paul@188 | 115 | |
paul@188 | 116 | return obj.__str__() |
paul@188 | 117 | |
paul@6 | 118 | # vim: tabstop=4 expandtab shiftwidth=4 |