Logo Search packages:      
Sourcecode: sam2p version File versions

char * SimBuffer::B::substr_grow ( slen_t  first,
slen_t  oldmuch,
slen_t  newmuch 
)

Removes oldmuch chars from index first, and makes place for newmuch chars there. Returns the beginning of the new place. Calls memmove(). Tue Jun 11 15:33:33 CEST 2002

Definition at line 1144 of file gensi.cpp.

References vi_grow2().

                                                                          {
  slen_t idx=first;
  if (first<len) {
    if (first+oldmuch>len) oldmuch=len-first;
    if (newmuch<oldmuch) { first+=newmuch; oldmuch-=newmuch; newmuch=0; }
    else if (newmuch>oldmuch) { first+=oldmuch; newmuch-=oldmuch; oldmuch=0; }
    else return const_cast<char*>(beg)+first;
  } else {
    len=first=idx=oldmuch=0;
    if (newmuch==0) { vi_grow2(0,0,0,0); return const_cast<char*>(beg); }
  }
  // fprintf(stderr, "newmuch=%u oldmuch=%u len=%u\n", newmuch, oldmuch, len);
  if (newmuch>0) {
    vi_grow2(0,newmuch,0,0);
    char *p=const_cast<char*>(beg)+first; /* after vi_grow2() */
    memmove(p+newmuch, p, len-first-newmuch);
  } else if (oldmuch>0) {
    char *p=const_cast<char*>(beg)+first; /* before vi_grow2() */
    memmove(p, p+oldmuch, len-first-oldmuch);
    vi_grow2(0,-(slendiff_t)oldmuch,0,0);
  } else assert(0);
  // fprintf(stderr, "len=%u oldmuch=%u\n", len, oldmuch);
  return const_cast<char*>(beg)+idx;
}


Generated by  Doxygen 1.6.0   Back to index