#385 Add toArray method to mutable buffer class.

Classes (154)

Sometimes it can be required to convert the contents of a buffer into an array. It would be handy to allow a start offset to be specified. This would especially helpful to implement a mutable buffer input stream. The arrayIn method should not start at the buffer start but at the current read position.

The method is similar to makearray only that it accepts a second (optional) integer argument (-1 < x <= mb~length):

RexxArray RexxMutableBuffer::toarray(RexxString div, RexxInteger pstart)
+/ Function: Split string into an array /
+ stringsize_t _start = optionalPositionArgument(pstart, 0, ARG_TWO);
+ // the start position must be within the string bounds
+ if (_start > getLength())
+ {
+ reportException(Error_Incorrect_method_position, pstart);
+ }
+ return StringUtil::makearray(getStringData() + _start, getLength(), div);

I will commit a change if there are no concerns.



  • Rick McGuire

    Rick McGuire - 2009-11-03

    I have a concern about the meaning of the range being -1 < x <= mb~length. For any other method that takes a position argument the lower bound is normally 1,

  • Moritz Hoffmann

    Moritz Hoffmann - 2009-11-03

    Right, we're using 1 as the lower index bound everywhere. Then, the method needs to substract one on the StringUtil invocation, but that seems OK. I will change and commit it.


  • Rick McGuire

    Rick McGuire - 2011-02-03

    I think if you are going to do this, then it should support both a position and a length so sub pieces can be picked up from the buffer. This really should also be added to the String class as well.



Cancel  Add attachments

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.

No, thanks