allow for negative length (meaning left of start) in expand

This commit is contained in:
zimoch
2010-10-20 13:21:05 +00:00
parent 318d0e389b
commit 7cc19d2614
2 changed files with 15 additions and 3 deletions

View File

@ -273,9 +273,18 @@ StreamBuffer StreamBuffer::expand(long start, long length) const
if (start < 0)
{
start += len;
if (start < 0) start = 0;
}
end = length >= 0 ? start+length : len;
if (length < 0)
{
start += length;
length = -length;
}
if (start < 0)
{
length += start;
start = 0;
}
end = start+length;
if (end > len) end = len;
StreamBuffer result((end-start)*2);
start += offs;

View File

@ -218,7 +218,10 @@ public:
// expand: create copy of StreamBuffer where all nonprintable characters
// are replaced by <xx> with xx being the hex code of the characters
StreamBuffer expand(long start=0, long length=-1) const;
StreamBuffer expand(long start, long length) const;
StreamBuffer expand(long start=0) const
{return expand(start, len);}
// dump: debug function, like expand but also show the 'hidden' memory
// before and after the real data. Uses colours.