Lichen

Changeset

586:3481d146208c
2017-02-13 Paul Boddie raw files shortlog changelog graph Merged changes from the attr-strvalue-without-size branch. method-wrapper-for-context
     1.1 --- a/lib/__builtins__/unicode.py	Mon Feb 13 21:26:38 2017 +0100
     1.2 +++ b/lib/__builtins__/unicode.py	Mon Feb 13 21:49:59 2017 +0100
     1.3 @@ -40,7 +40,7 @@
     1.4          self.encoding = encoding
     1.5          self.length = None
     1.6  
     1.7 -    def _binary_op(self, op, other):
     1.8 +    def _binary_op(self, op, other, sizes=False):
     1.9  
    1.10          "Perform 'op' on this object and 'other' if appropriate."
    1.11  
    1.12 @@ -51,16 +51,17 @@
    1.13  
    1.14          # Combining text with bytes.
    1.15  
    1.16 -        elif not _isinstance(other, utf8string):
    1.17 +        if not _isinstance(other, utf8string):
    1.18              s = self.encode()
    1.19 +        else:
    1.20 +            s = self
    1.21 +
    1.22 +        if sizes:
    1.23 +            return op(s.__data__, other.__data__, s.__size__, other.__size__)
    1.24 +        else:
    1.25              return op(s.__data__, other.__data__)
    1.26  
    1.27 -        # Otherwise, perform the operation on the operands' data.
    1.28 -
    1.29 -        else:
    1.30 -            return op(self.__data__, other.__data__)
    1.31 -
    1.32 -    def _binary_op_rev(self, op, other):
    1.33 +    def _binary_op_rev(self, op, other, sizes=False):
    1.34  
    1.35          "Perform 'op' on 'other' and this object if appropriate."
    1.36  
    1.37 @@ -71,14 +72,15 @@
    1.38  
    1.39          # Combining text with bytes.
    1.40  
    1.41 -        elif not _isinstance(other, utf8string):
    1.42 +        if not _isinstance(other, utf8string):
    1.43              s = self.encode()
    1.44 -            return op(other.__data__, s.__data__)
    1.45 +        else:
    1.46 +            s = self
    1.47  
    1.48 -        # Otherwise, perform the operation on the operands' data.
    1.49 -
    1.50 +        if sizes:
    1.51 +            return op(other.__data__, s.__data__, other.__size__, s.__size__)
    1.52          else:
    1.53 -            return op(other.__data__, self.__data__)
    1.54 +            return op(other.__data__, s.__data__)
    1.55  
    1.56      def _convert(self, result, other):
    1.57  
    1.58 @@ -118,7 +120,7 @@
    1.59  
    1.60          "Return a string combining this string with 'other'."
    1.61  
    1.62 -        return self._convert(self._binary_op(str_add, other), other)
    1.63 +        return self._convert(self._binary_op(str_add, other, True), other)
    1.64  
    1.65      __add__ = __iadd__
    1.66  
    1.67 @@ -126,7 +128,7 @@
    1.68  
    1.69          "Return a string combining this string with 'other'."
    1.70  
    1.71 -        return self._convert(self._binary_op_rev(str_add, other), other)
    1.72 +        return self._convert(self._binary_op_rev(str_add, other, True), other)
    1.73  
    1.74      def __len__(self):
    1.75