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
12
builtin.cpp
12
builtin.cpp
|
@ -2128,10 +2128,9 @@ static int builtin_read( parser_t &parser, wchar_t **argv )
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string_buffer_t sb;
|
|
||||||
int eof=0;
|
int eof=0;
|
||||||
|
|
||||||
sb_init( &sb );
|
wcstring sb;
|
||||||
|
|
||||||
while( 1 )
|
while( 1 )
|
||||||
{
|
{
|
||||||
|
@ -2178,17 +2177,16 @@ static int builtin_read( parser_t &parser, wchar_t **argv )
|
||||||
|
|
||||||
if( res == L'\n' )
|
if( res == L'\n' )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
sb_append_char( &sb, res );
|
sb.push_back(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( sb.used < 2 && eof )
|
if( sb.size() < 2 && eof )
|
||||||
{
|
{
|
||||||
exit_res = 1;
|
exit_res = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
buff = wcsdup( (wchar_t *)sb.buff );
|
buff = wcsdup( sb.c_str() );
|
||||||
sb_destroy( &sb );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i != argc && !exit_res )
|
if( i != argc && !exit_res )
|
||||||
|
|
|
@ -94,42 +94,40 @@ static void replace_part( const wchar_t *begin,
|
||||||
int append_mode )
|
int append_mode )
|
||||||
{
|
{
|
||||||
const wchar_t *buff = get_buffer();
|
const wchar_t *buff = get_buffer();
|
||||||
string_buffer_t out;
|
|
||||||
int out_pos=get_cursor_pos();
|
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)
|
switch( append_mode)
|
||||||
{
|
{
|
||||||
case REPLACE_MODE:
|
case REPLACE_MODE:
|
||||||
{
|
{
|
||||||
|
|
||||||
sb_append( &out, insert );
|
out.append(insert);
|
||||||
out_pos = wcslen( insert ) + (begin-buff);
|
out_pos = wcslen( insert ) + (begin-buff);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
case APPEND_MODE:
|
case APPEND_MODE:
|
||||||
{
|
{
|
||||||
sb_append_substring( &out, begin, end-begin );
|
out.append( begin, end-begin );
|
||||||
sb_append( &out, insert );
|
out.append( insert );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case INSERT_MODE:
|
case INSERT_MODE:
|
||||||
{
|
{
|
||||||
int cursor = get_cursor_pos() -(begin-buff);
|
int cursor = get_cursor_pos() -(begin-buff);
|
||||||
sb_append_substring( &out, begin, cursor );
|
out.append( begin, cursor );
|
||||||
sb_append( &out, insert );
|
out.append( insert );
|
||||||
sb_append_substring( &out, begin+cursor, end-begin-cursor );
|
out.append( begin+cursor, end-begin-cursor );
|
||||||
out_pos += wcslen( insert );
|
out_pos += wcslen( insert );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sb_append( &out, end );
|
out.append( end );
|
||||||
reader_set_buffer( (wchar_t *)out.buff, out_pos );
|
reader_set_buffer( out, out_pos );
|
||||||
sb_destroy( &out );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
13
fish.cpp
13
fish.cpp
|
@ -324,7 +324,6 @@ int main( int argc, char **argv )
|
||||||
char **ptr;
|
char **ptr;
|
||||||
char *file = *(argv+(my_optind++));
|
char *file = *(argv+(my_optind++));
|
||||||
int i;
|
int i;
|
||||||
string_buffer_t sb;
|
|
||||||
int fd;
|
int fd;
|
||||||
wchar_t *rel_filename, *abs_filename;
|
wchar_t *rel_filename, *abs_filename;
|
||||||
|
|
||||||
|
@ -336,19 +335,15 @@ int main( int argc, char **argv )
|
||||||
|
|
||||||
if( *(argv+my_optind))
|
if( *(argv+my_optind))
|
||||||
{
|
{
|
||||||
sb_init( &sb );
|
wcstring sb;
|
||||||
|
|
||||||
for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
|
for( i=1,ptr = argv+my_optind; *ptr; i++, ptr++ )
|
||||||
{
|
{
|
||||||
if( i != 1 )
|
if( i != 1 )
|
||||||
sb_append( &sb, ARRAY_SEP_STR );
|
sb.append( ARRAY_SEP_STR );
|
||||||
wchar_t *val = str2wcs( *ptr );
|
sb.append( str2wcstring( *ptr ));
|
||||||
sb_append( &sb, val );
|
|
||||||
free( val );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
env_set( L"argv", (wchar_t *)sb.buff, 0 );
|
env_set( L"argv", sb.c_str(), 0 );
|
||||||
sb_destroy( &sb );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
rel_filename = str2wcs( file );
|
rel_filename = str2wcs( file );
|
||||||
|
|
|
@ -2108,15 +2108,14 @@ history_t *reader_get_history(void) {
|
||||||
return data ? data->history : NULL;
|
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 )
|
if( !data )
|
||||||
return;
|
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. */
|
/* 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 );
|
size_t l = b.size();
|
||||||
const wcstring tmp = b;
|
data->command_line = b;
|
||||||
data->command_line = tmp;
|
|
||||||
|
|
||||||
data->check_size();
|
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 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.
|
\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
|
Get the current cursor position in the command line. If interactive
|
||||||
|
|
Loading…
Reference in a new issue