#include <cstring>
using namespace std;
int TextBuffer::Unpack( char* str, char* begin, char* end ) {
int len = -1, len1 = strlen( begin ), len2 = len1+1;
int i, j, start = nextByte;
for ( i = start; i < bufferSize-len1-len2; i++ )
if ( strncmp( buffer+i, begin, len1 ) == 0 ) {
i += len1;
break;
}
for ( j = i; j < bufferSize-len2; j++ )
if ( strncmp( buffer+j, end, len2 ) == 0 ) {
len = j - i;
break;
}
if ( len == -1 ) return( false );
nextByte = j + len2;
if ( nextByte > bufferSize ) return( false );
strncpy ( str, buffer+i, len );
str[len] = '\0';
i = 0;
while ( ( str[i]==' ' ) || ( str[i]=='\n' ) ||
( str[i]=='\t' ) ) i++;
strcpy( str, str+i );
i = len - i - 1;
while ( ( str[i]==' ' ) || ( str[i]=='\n' ) ||
( str[i]=='\t' ) ) i--;
str[i+1] = '\0';
return( true );
}
|