#385 Add toArray method to mutable buffer class.

None
open
Classes (154)
5
2012-08-22
2009-11-03
Moritz Hoffmann
No

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.

Moritz

Discussion

  • 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,

     
  • 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.

    Moritz

     
  • 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.

     


Anonymous


Cancel   Add attachments