(self, start, num, val)
return self
Modify a string in an existing buffer.
Modify a string in an existing buffer.
Modify a string in an existing buffer .
def midset(self, start, num, val):
        """Modify a string in an existing buffer."""
        # we need to decrement basic offset by 1 to get python offset
        offset = start - 1
        # don't overwrite more of the old string than the length of the new string
        num = min(num, val.length())
        # ensure the length of source string matches target
        length = self.length()
        if offset + num > length:
            num = length - offset
        if num <= 0:
            return self
        # make a copy only if not in a writeable location
        target = self._stringspace.check_modify(*self.to_pointer())
        self.from_pointer(*target)
        source = val.to_pointer()
        if source != target:
            self._stringspace.view(*target)[offset:offset+num] = (
                self._stringspace.view(*source)[:num]
            )
        else:
            # copy byte by byte from left to right
            # to conform to GW overwriting of source string on overlap
            for i in range(num):
                self._stringspace.view(*target)[i+offset:i+offset+1] = (
                    self._stringspace.view(*source)[i:i+1]
                )
        return self
def midset ( self , start , num , val ) : # we need to decrement basic offset by 1 to get python offset offset = start - 1 # don't overwrite more of the old string than the length of the new string num = min ( num , val . length ( ) ) # ensure the length of source string matches target length = self . length ( ) if offset + num > length : num = length - offset if num <= 0 : return self # make a copy only if not in a writeable location target = self . _stringspace . check_modify ( * self . to_pointer ( ) ) self . from_pointer ( * target ) source = val . to_pointer ( ) if source != target : self . _stringspace . view ( * target ) [ offset : offset + num ] = ( self . _stringspace . view ( * source ) [ : num ] ) else : # copy byte by byte from left to right # to conform to GW overwriting of source string on overlap for i in range ( num ) : self . _stringspace . view ( * target ) [ i + offset : i + offset + 1 ] = ( self . _stringspace . view ( * source ) [ i : i + 1 ] ) return self