Editable strings anyone?

Jason Orendorff jason at jorendorff.com
Mon Feb 18 00:38:01 EST 2002


Paul Rubin wrote:
> Jason Orendorff wrote:
> > There's no gap in arrays.
>
> OK.  I guess the simplest approach to editable strings is to have
> a new type of array
> that has multiple segments and implements the buffer interface.
> Then the re module can be extended to handle the buffer interface,
> if it doesn't handle it already.

Someone may have mentioned this before, but I think you would have
to sneakily close the gap whenever the re module asks you for your
buffer pointer, because re needs a contiguous buffer.  See:

http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/python/python/dist/src/Module
s/_sre.c

About halfway down, you'll see a function getstring() which returns
a pointer to the searchable data in an object.  This is where the
requirement of a *contiguous* buffer is enforced.

  if (... buffer->bf_getsegcount(string, NULL) != 1)
          ... then raise an exception.

## Jason Orendorff    http://www.jorendorff.com/





More information about the Python-list mailing list