File: sub.cc

package info (click to toggle)
nullmailer 1.00RC7-22
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 1,192 kB
  • ctags: 695
  • sloc: cpp: 4,375; sh: 519; makefile: 249; perl: 184; ansic: 10
file content (37 lines) | stat: -rw-r--r-- 851 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "mystring.h"

// return the sub-string ending at 'offset'
mystring mystring::left(size_t offset) const
{
  if(offset > rep->length)
    return *this;
  else
    return mystring(rep->buf, offset);
}

// return the sub-string starting at 'offset'
mystring mystring::right(size_t offset) const
{
  if(offset >= rep->length)
    return mystring();
  else if(offset == 0)
    return *this;
  else
    return mystring(rep->buf+offset, rep->length-offset);
}

// return the 'len' characters of the string starting at 'offset'
mystring mystring::sub(size_t offset, size_t len) const
{
  // return right(offset).left(len);
  if(len == 0)
    return mystring();
  else if(offset == 0 && len >= rep->length)
    return *this;
  else {
    if(len+offset >= rep->length)
      len = rep->length - offset;
    return mystring(rep->buf+offset, len);
  }
}