1.1 --- a/lib/__builtins__/unicode.py Mon Dec 19 00:26:49 2016 +0100
1.2 +++ b/lib/__builtins__/unicode.py Fri Jan 06 22:23:52 2017 +0100
1.3 @@ -20,8 +20,10 @@
1.4 """
1.5
1.6 from __builtins__.str import basestring
1.7 +from __builtins__.types import check_int
1.8 from posix.iconv import Converter
1.9 -from native import str_add, unicode_len, isinstance as _isinstance
1.10 +from native import str_add, unicode_len, unicode_substr, \
1.11 + isinstance as _isinstance
1.12
1.13 class utf8string(basestring):
1.14
1.15 @@ -161,6 +163,34 @@
1.16 s.encoding = encoding
1.17 return s
1.18
1.19 + # Special implementation methods.
1.20 +
1.21 + def __get_single_item__(self, index):
1.22 +
1.23 + "Return the item at the normalised (positive) 'index'."
1.24 +
1.25 + self._check_index(index)
1.26 + return utf8string(unicode_substr(self.__data__, index, index + 1, 1), self.encoding)
1.27 +
1.28 + def __get_multiple_items__(self, start, end, step):
1.29 +
1.30 + """
1.31 + Return items from 'start' until (but excluding) 'end', at 'step'
1.32 + intervals.
1.33 + """
1.34 +
1.35 + self._check_index(start)
1.36 + self._check_end_index(end)
1.37 + check_int(step)
1.38 +
1.39 + if step == 0:
1.40 + raise ValueError(step)
1.41 +
1.42 + if start == end:
1.43 + return ""
1.44 +
1.45 + return utf8string(unicode_substr(self.__data__, start, end, step), self.encoding)
1.46 +
1.47 def unicode(s, encoding):
1.48
1.49 "Convert 's' to a Unicode object, interpreting 's' as using 'encoding'."