diff --git a/builtin.cpp b/builtin.cpp index 4af4f208e..d7ba8a11a 100644 --- a/builtin.cpp +++ b/builtin.cpp @@ -2128,10 +2128,9 @@ static int builtin_read( parser_t &parser, wchar_t **argv ) } else { - string_buffer_t sb; int eof=0; - sb_init( &sb ); + wcstring sb; while( 1 ) { @@ -2178,17 +2177,16 @@ static int builtin_read( parser_t &parser, wchar_t **argv ) if( res == L'\n' ) break; - - sb_append_char( &sb, res ); + + sb.push_back(res); } - if( sb.used < 2 && eof ) + if( sb.size() < 2 && eof ) { exit_res = 1; } - buff = wcsdup( (wchar_t *)sb.buff ); - sb_destroy( &sb ); + buff = wcsdup( sb.c_str() ); } if( i != argc && !exit_res ) diff --git a/builtin_commandline.cpp b/builtin_commandline.cpp index d470a3913..26b40e624 100644 --- a/builtin_commandline.cpp +++ b/builtin_commandline.cpp @@ -94,42 +94,40 @@ static void replace_part( const wchar_t *begin, int append_mode ) { const wchar_t *buff = get_buffer(); - string_buffer_t out; int out_pos=get_cursor_pos(); - - sb_init( &out ); + + wcstring out; - sb_append_substring( &out, buff, begin-buff ); + out.append(buff, begin - buff); switch( append_mode) { case REPLACE_MODE: { - sb_append( &out, insert ); + out.append(insert); out_pos = wcslen( insert ) + (begin-buff); break; } case APPEND_MODE: { - sb_append_substring( &out, begin, end-begin ); - sb_append( &out, insert ); + out.append( begin, end-begin ); + out.append( insert ); break; } case INSERT_MODE: { int cursor = get_cursor_pos() -(begin-buff); - sb_append_substring( &out, begin, cursor ); - sb_append( &out, insert ); - sb_append_substring( &out, begin+cursor, end-begin-cursor ); + out.append( begin, cursor ); + out.append( insert ); + out.append( begin+cursor, end-begin-cursor ); out_pos += wcslen( insert ); break; } } - sb_append( &out, end ); - reader_set_buffer( (wchar_t *)out.buff, out_pos ); - sb_destroy( &out ); + out.append( end ); + reader_set_buffer( out, out_pos ); } /** diff --git a/fish.cpp b/fish.cpp index 3b8f92f8f..29c1ccf42 100644 --- a/fish.cpp +++ b/fish.cpp @@ -324,7 +324,6 @@ int main( int argc, char **argv ) char **ptr; char *file = *(argv+(my_optind++)); int i; - string_buffer_t sb; int fd; wchar_t *rel_filename, *abs_filename; @@ -336,19 +335,15 @@ int main( int argc, char **argv ) if( *(argv+my_optind)) { - sb_init( &sb ); - + wcstring sb; for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ ) { if( i != 1 ) - sb_append( &sb, ARRAY_SEP_STR ); - wchar_t *val = str2wcs( *ptr ); - sb_append( &sb, val ); - free( val ); + sb.append( ARRAY_SEP_STR ); + sb.append( str2wcstring( *ptr )); } - env_set( L"argv", (wchar_t *)sb.buff, 0 ); - sb_destroy( &sb ); + env_set( L"argv", sb.c_str(), 0 ); } rel_filename = str2wcs( file ); diff --git a/reader.cpp b/reader.cpp index bbf6b608f..139efbc2b 100644 --- a/reader.cpp +++ b/reader.cpp @@ -2108,15 +2108,14 @@ history_t *reader_get_history(void) { return data ? data->history : NULL; } -void reader_set_buffer( const wchar_t *b, int p ) +void reader_set_buffer( const wcstring &b, int p ) { if( !data ) return; /* Callers like to pass us pointers into ourselves, so be careful! I don't know if we can use operator= with a pointer to our interior, so use an intermediate. */ - int l = wcslen( b ); - const wcstring tmp = b; - data->command_line = tmp; + size_t l = b.size(); + data->command_line = b; data->check_size(); diff --git a/reader.h b/reader.h index 37da4d1ee..9cb412e89 100644 --- a/reader.h +++ b/reader.h @@ -95,7 +95,7 @@ history_t *reader_get_history(void); \param b the new buffer value \param p the cursor position. If \c p is less than zero, the cursor is placed on the last character. */ -void reader_set_buffer( const wchar_t *b, int p ); +void reader_set_buffer( const wcstring &b, int p ); /** Get the current cursor position in the command line. If interactive