00001
00002
00003
00004 #include <string.h>
00005 #include "string2.h"
00006
00007
00008 const char whitespace[] = "\r\n \t" ;
00009
00010 void MPKstring::FixStringForBackspaces( char str[] )
00011 {
00012 char* location = strchr( str, 8 ) ;
00013 while( location != 0 )
00014 {
00015 if( location == 0 )
00016 {
00017 strcpy( str, str + 1 ) ;
00018 }
00019 else
00020 {
00021 strcpy( location - 1, location + 1 ) ;
00022 }
00023 location = strchr( str, 8 ) ;
00024 }
00025
00026 }
00027
00028 void MPKstring::TrimLeadingWhitespace( char str[] )
00029 {
00030 size_t i;
00031 for( i = 0; i < strlen( str ); i++ )
00032 {
00033 if( strrchr( whitespace, str[ i ] ) == NULL )
00034 {
00035 break ;
00036 }
00037 }
00038 char* buffer = new char[ strlen( str ) + 1 ] ;
00039 strcpy( buffer, str + i ) ;
00040 strcpy( str, buffer ) ;
00041 delete[] buffer ;
00042 };
00043
00044 void MPKstring::TrimTrailingWhitespace( char str[] )
00045 {
00046 int i;
00047 for( i = strlen( str ) - 1; i >=0; i-- )
00048 {
00049 if( strrchr( whitespace, str[ i ] ) == NULL )
00050 {
00051 break ;
00052 }
00053 }
00054 char* buffer = new char[ strlen( str ) + 1 ] ;
00055 strncpy( buffer, str, i + 1 ) ;
00056 buffer[ i + 1 ] = NULL ;
00057 strcpy( str, buffer ) ;
00058 delete[] buffer ;
00059 };
00060