mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-26 12:53:13 +00:00
Replace some string_buffer_t with wcstring
This commit is contained in:
parent
62bd43f17f
commit
a837a27b34
5 changed files with 24 additions and 34 deletions
10
builtin.cpp
10
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 )
|
||||
{
|
||||
|
@ -2179,16 +2178,15 @@ 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 )
|
||||
|
|
|
@ -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 );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
13
fish.cpp
13
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 );
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
2
reader.h
2
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
|
||||
|
|
Loading…
Reference in a new issue