* ReByteBuffer.cpp
  *
  *  Created on: 06.05.2010
- *      Author: wk
  */
 
 #include "base/rebase.hpp"
 /** @brief Constructor.
  *
  * @param delta                If a new storage must be allocated the size
- *                                     is incremented by at least this count of bytes.
+ *                                     is incremented by at least this count of bytes
  */
-ReByteBuffer::ReByteBuffer(size_t delta)
-       :
+ReByteBuffer::ReByteBuffer(size_t delta) :
        m_delta(delta),
        // m_primaryBuffer
        m_buffer(m_primaryBuffer),
 }
 /** @brief Constructor.
  *
- * @param source       The instance to copy (C string).
+ * @param source       the instance to copy (C string)
  */
 ReByteBuffer::ReByteBuffer(const char* source) :
        m_delta(PRIMARY_BUFFER_SIZE),
 }
 /** @brief Copy constructor.
  *
- * @param source       The instance to copy.
+ * @param source       the instance to copy
  */
-ReByteBuffer::ReByteBuffer(const ReByteBuffer& source)
-       :
+ReByteBuffer::ReByteBuffer(const ReByteBuffer& source) :
        m_delta(source.delta()),
        // m_primaryBuffer
        m_buffer(m_primaryBuffer),
 
 /** @brief The assignment operator.
  *
- * @param source       The instance to copy.
+ * @param source       the instance to copy
  *
- * @return The instance itself.
+ * @return the instance itself
  */
 ReByteBuffer& ReByteBuffer::operator =(const ReByteBuffer& source){
        m_delta = source.delta();
  * assert(4 == buf.append("abc", 3).append("x").getLength());
  * </code></pre>
  *
- * @param source               The sequence to append.
- * @param length               The length of the sequence.
+ * @param source               the sequence to append
+ * @param length               the length of the sequence
  *
- * @return *this (for chaining).
+ * @return *this (for chaining)
  */
 ReByteBuffer&  ReByteBuffer::append(const Byte* source, size_t length){
        if (length == (size_t) -1)
  * assert(strcmp("33  ", buf.getBuffer()) == 0);
  * </code></pre>
  *
- * @param number               The number to append.
- * @param format               The format of the number used by <code>sprintf()</code>.
+ * @param number               the number to append
+ * @param format               the format of the number used by <code>sprintf()</code>
  *
- * @return *this (for chaining).
+ * @return *this (for chaining)
  */
 ReByteBuffer&  ReByteBuffer::appendInt(int number, const char* format){
        char buffer [128];
  * assert("mydoc.txt", name.getBuffer());
  * </code></pre>
  *
- * @return *this (for chaining).
+ * @return *this (for chaining)
  */
 ReByteBuffer& ReByteBuffer::append(const ReByteBuffer& source){
        return append(source.str(), source.length());
  * assert(12 == buf.atoi(3, 3 + 2));
  * </code></pre>
  *
- * @param start                The first index to convert.
- * @param end          -1: all found digits will be converted.
- *                                     Otherwise: The maximal number of digits to convert.
+ * @param start                the first index to convert
+ * @param end          -1: all found digits will be converted
+ *                                     Otherwise: the maximal number of digits to convert
  */
 int ReByteBuffer::atoi(size_t start, int end) const{
        int rc = 0;
  *
  * @param toCount                              the byte sequence to count
  * @param lengthOfToCount      -1: length is <code>strlen(toCount)</count><br>
- *                                                             otherwise: length of <code>toCount</count>.
+ *                                                             otherwise: length of <code>toCount</count>
  */
 int ReByteBuffer::count(const char* toCount, size_t lengthToCount){
        int rc = 0;
 
 /** @brief Ensures that there is enough space.
  *
- * <p>If not it will be allocated and the old value will be copied.
- * </p>
- * <p>A new allocation will be use at least <code>m_delta</code> bytes.
- * <p>The allocated space is incremented by one because of the ending '\\0'.
- * </p>
+ * If not it will be allocated and the old value will be copied.
  *
- * @param size At the end the size will be at least this value.
+ * A new allocation will be use at least <code>m_delta</code> bytes.
+ * The allocated space is incremented by one because of the ending '\\0'.
+ *
+ * @param size the size will be at least this value
  */
 void ReByteBuffer::ensureSize(size_t size){
        if (m_capacity < size){
-               if (size - m_capacity < m_delta)
-                       size = m_capacity + m_delta;
-                       // Think for the ending '\0':
+               int delta = m_delta > 0 ? m_delta
+                       : 2 * m_capacity < - m_delta ? 2 * m_capacity : - m_delta;
+               if (size - m_capacity < delta)
+                       size = m_capacity + delta;
+               // Think for the ending '\0':
                Byte* buffer = new Byte[size + 1];
                assert(buffer != NULL);
                if (m_length > 0)
  * assert(5 == buf.indexOf("12", -1, 3));
  * </code></pre>
  *
- * @param toFind               The sequence to find.
- * @param toFindLength Length of <code>toFind</code>.
- *                                             If -1 the <code>strlen(toFind)</code> will be taken.
- * @param start                The search respects the indices in the range [start, end[
+ * @param toFind               the sequence to find
+ * @param toFindLength Length of <code>toFind</code>,
+ *                                             If -1 the <code>strlen(toFind)</code> will be taken
+ * @param start                the search respects the indices in the range [start, end[
  * @param end                  -1: no upper limit to search<br>
  *                                             otherwise: the first index above the search range
  * @param ignoreCase   <code>true</code>: case insensitive search<br>
  *                                             <code>true</code>: case sensitive search
- * @return     -1: The sequence could not be found.
- *                     Otherwise: The index of <code>toFind</code> in the internal buffer.
+ * @return     -1: the sequence could not be found.
+ *                     Otherwise: the index of <code>toFind</code> in the internal buffer
  */
 int ReByteBuffer::indexOf(const Byte* toFind, size_t toFindLength, int start,
                int end, bool ignoreCase) const{
  * assert(5 == buf.rindexOf("12", -1, 3));
  * </code></pre>
  *
- * @param toFind               The sequence to find.
- * @param toFindLength Length of <code>toFind</code>.
- *                                             If -1 the <code>strlen(toFind)</code> will be taken.
- * @param start                The search respects the indices in the range [start, end[
+ * @param toFind               the sequence to find
+ * @param toFindLength length of <code>toFind</code>.
+ *                                             If -1 the <code>strlen(toFind)</code> will be taken
+ * @param start                the search respects the indices in the range [start, end[
  * @param end                  -1: no upper limit to search<br>
  *                                             otherwise: the first index above the search range
  * @param ignoreCase   <code>true</code>: case insensitive search<br>
  *                                             <code>true</code>: case sensitive search
- * @return     -1: The sequence could not be found.
- *                     Otherwise: The index of <code>toFind</code> in the internal buffer.
+ * @return     -1: the sequence could not be found.
+ *                     Otherwise: the index of <code>toFind</code> in the internal buffer
  */
 int ReByteBuffer::rindexOf(const Byte* toFind, size_t toFindLength, int start,
                int end, bool ignoreCase) const{
  * assert(strcmp("XYZabcXYZ3", buf.str()) == 0);
  * </code></pre>
  *
- * @param toFind                       The substring which will be replaced.
- * @param toFindLength         The length of <code>toFind</code>. -1: <code>strlen()</code> will be used.
- * @param replacement          The replacement.
- * @param replacementLength    The length of <code>replacement</code>. -1: <code>strlen()</code> will be used.
- * @param start                                The first index to inspect.
+ * @param toFind                       the substring which will be replaced
+ * @param toFindLength         the length of <code>toFind</code>. -1: <code>strlen()</code> will be used
+ * @param replacement          the replacement
+ * @param replacementLength    the length of <code>replacement</code>. -1: <code>strlen()</code> will be used
+ * @param start                                the first index to inspect
  */
 ReByteBuffer& ReByteBuffer::replaceAll(const Byte* toFind, size_t toFindLength,
                const Byte* replacement, size_t replacementLength, int start){
        return *this;
 }
 
+/** @brief Sets the increment used to increase the capacity.
+ *
+ * @param delta                > 0: reservation allocates at least this amount of bytes<br>
+ *                                     0: delta is set to a default value<br>
+ *                                     < 0: the current capacity will be doubled until <code>- delta</code>
+ */
+void ReByteBuffer::setDelta(int delta){
+       m_delta = delta == 0 ? PRIMARY_BUFFER_SIZE : delta;
+}
+
 /** @brief Sets the length to a given value.
  *
  * The new length is greater than the current size the buffer will reallocated.
  * assert(5 == buf.getLength());
  * </code></pre>
  *
- * @param length       The new length.
+ * @param length       the new length
  *
- * @return *this (for chaining).
+ * @return *this (for chaining)
  */
 ReByteBuffer&  ReByteBuffer::setLength(size_t length){
        ensureSize(length);
  * assert(strcmp("123XX", buf.str()) == 0);
  * </code></pre>
  *
- * @param length       The new length.
- * @param filler       If the new length is greater than the current length the space
- *                                     will be filled with this value.
- * @return *this (for chaining).
+ * @param length       the new length
+ * @param filler       if the new length is greater than the current length the space
+ *                                     will be filled with this value
+ * @return *this (for chaining)
  */
 ReByteBuffer&  ReByteBuffer::setLengthAndFill(size_t length, Byte filler){
        ensureSize(length);
  * assert(strcmp("12XYZ5", buf.str()) == 0);
  * </code></pre>
  *
- * @param ix                           The index where the cut/insertion takes place.
- * @param replacedLength       The number of deleted bytes. If 0 a pure insertion will be done.
- * @param source                       The sequence to insert. May be NULL (for pure deletion).
- * @param length                       The length of the inserted sequence.
- *                                                     If 0: a pure deletion will be done.
- *                                                     If -1: <code>strlen(source)</code> will be taken.
+ * @param ix                           the index where the cut/insertion takes place
+ * @param replacedLength       the number of deleted bytes. If 0 a pure insertion will be done
+ * @param source                       the sequence to insert. May be NULL (for pure deletion)
+ * @param length                       the length of the inserted sequence<br>
+ *                                                     0: a pure deletion will be done<br>
+ *                                                     -1: <code>strlen(source)</code> will be taken
  *
- * @return true: Success. false: <code>ix</code> out of range.
+ * @return true: Success. false: <code>ix</code> out of range
  */
 bool ReByteBuffer::splice(size_t ix, size_t replacedLength,
                const ReByteBuffer::Byte* source, size_t length){