|
0
|
1 |
#include "mystring.h"
|
|
|
2 |
|
|
|
3 |
// return the sub-string ending at 'offset'
|
|
|
4 |
mystring mystring::left(size_t offset) const
|
|
|
5 |
{
|
|
|
6 |
if(offset > rep->length)
|
|
|
7 |
return *this;
|
|
|
8 |
else
|
|
|
9 |
return mystring(rep->buf, offset);
|
|
|
10 |
}
|
|
|
11 |
|
|
|
12 |
// return the sub-string starting at 'offset'
|
|
|
13 |
mystring mystring::right(size_t offset) const
|
|
|
14 |
{
|
|
|
15 |
if(offset >= rep->length)
|
|
|
16 |
return mystring();
|
|
|
17 |
else if(offset == 0)
|
|
|
18 |
return *this;
|
|
|
19 |
else
|
|
|
20 |
return mystring(rep->buf+offset, rep->length-offset);
|
|
|
21 |
}
|
|
|
22 |
|
|
|
23 |
// return the 'len' characters of the string starting at 'offset'
|
|
|
24 |
mystring mystring::sub(size_t offset, size_t len) const
|
|
|
25 |
{
|
|
|
26 |
// return right(offset).left(len);
|
|
|
27 |
if(len == 0)
|
|
|
28 |
return mystring();
|
|
|
29 |
else if(offset == 0 && len >= rep->length)
|
|
|
30 |
return *this;
|
|
|
31 |
else {
|
|
|
32 |
if(len+offset >= rep->length)
|
|
|
33 |
len = rep->length - offset;
|
|
|
34 |
return mystring(rep->buf+offset, len);
|
|
|
35 |
}
|
|
|
36 |
}
|
|
|
37 |
|