• Kirill Smelkov's avatar
    golang_str: bstr/ustr support for + and * · bbbb58f0
    Kirill Smelkov authored
    Add support for +, *, += and *= operators to bstr and ustr.
    
    For * rhs should be integer and the result, similarly to std strings, is
    repetition of rhs times.
    
    For + the other argument could be any supported string - bstr/ustr /
    unicode/bytes/bytearray. And the result is always bstr or ustr:
    
        u()   +     *     ->  u()
        b()   +     *     ->  b()
        u''   +  u()/b()  ->  u()
        u''   +  u''      ->  u''
        b''   +  u()/b()  ->  b()
        b''   +      b''  ->  b''
        barr  +  u()/b()  ->  barr
    
    in particular if lhs is bstr or ustr, the result will remain exactly of
    original lhs type. This should be handy when one has e.g. bstr at hand
    and wants to incrementally append something to it.
    
    And if lhs is bytes/unicode, but we append bstr/ustr to it, we "upgrade"
    the result to bstr/ustr correspondingly. Only if lhs is bytearray it
    remains to stay that way because it is logical for appended object to
    remain mutable if it was mutable in the beginning.
    
    As before bytearray.__add__ and friends need to patched a bit for
    bytearray not to reject ustr.
    bbbb58f0
golang_str_test.py 29.1 KB