Removed a lot of string_buffer_t

This commit is contained in:
ridiculousfish 2012-02-22 12:00:02 -08:00
parent a837a27b34
commit 376e199ebb
13 changed files with 153 additions and 282 deletions

View file

@ -90,7 +90,7 @@ static int get_cursor_pos()
*/
static void replace_part( const wchar_t *begin,
const wchar_t *end,
wchar_t *insert,
const wchar_t *insert,
int append_mode )
{
const wchar_t *buff = get_buffer();
@ -144,7 +144,7 @@ static void write_part( const wchar_t *begin,
int tokenize )
{
tokenizer tok;
string_buffer_t out;
wcstring out;
wchar_t *buff;
size_t pos;
@ -154,7 +154,7 @@ static void write_part( const wchar_t *begin,
{
buff = wcsndup( begin, end-begin );
// fwprintf( stderr, L"Subshell: %ls, end char %lc\n", buff, *end );
sb_init( &out );
out.clear();
for( tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
tok_has_next( &tok );
@ -168,20 +168,18 @@ static void write_part( const wchar_t *begin,
{
case TOK_STRING:
{
wchar_t *tmp = unescape( tok_last( &tok ), UNESCAPE_INCOMPLETE );
sb_append( &out, tmp, L"\n", NULL );
free( tmp );
out.append(escape_string(tok_last( &tok ), UNESCAPE_INCOMPLETE));
out.push_back(L'\n');
break;
}
}
}
stdout_buffer.append((const wchar_t *)out.buff);
stdout_buffer.append(out);
free( buff );
tok_destroy( &tok );
sb_destroy( &out );
}
else
{
@ -637,21 +635,16 @@ static int builtin_commandline( parser_t &parser, wchar_t **argv )
default:
{
string_buffer_t sb;
wcstring sb = argv[woptind];
int i;
sb_init( &sb );
sb_append( &sb, argv[woptind] );
for( i=woptind+1; i<argc; i++ )
{
sb_append( &sb, L"\n" );
sb_append( &sb, argv[i] );
sb.push_back(L'\n');
sb.append(argv[i]);
}
replace_part( begin, end, (wchar_t *)sb.buff, append_mode );
sb_destroy( &sb );
replace_part( begin, end, sb.c_str(), append_mode );
break;
}

View file

@ -60,10 +60,9 @@ static int is_path_variable( const wchar_t *env )
*/
static int my_env_set( const wchar_t *key, wcstring_list_t &val, int scope )
{
string_buffer_t sb;
size_t i;
int retcode = 0;
wchar_t *val_str=0;
const wchar_t *val_str=NULL;
if( is_path_variable( key ) )
{
@ -127,21 +126,18 @@ static int my_env_set( const wchar_t *key, wcstring_list_t &val, int scope )
}
sb_init( &sb );
wcstring sb;
if( val.size() )
{
for( i=0; i< val.size() ; i++ )
{
const wchar_t *next = val[ i ].c_str();
sb_append( &sb, next?next:L"" );
sb.append(val[i]);
if( i<val.size() - 1 )
{
sb_append( &sb, ARRAY_SEP_STR );
sb.append( ARRAY_SEP_STR );
}
}
val_str = (wchar_t *)sb.buff;
val_str = sb.c_str();
}
switch( env_set( key, val_str, scope | ENV_USER ) )
@ -161,8 +157,6 @@ static int my_env_set( const wchar_t *key, wcstring_list_t &val, int scope )
}
}
sb_destroy( &sb );
return retcode;
}

View file

@ -1337,20 +1337,12 @@ static int complete_param( const wchar_t *cmd_orig,
is more commonly supported by
homebrew getopt-like functions.
*/
string_buffer_t completion;
sb_init( &completion );
sb_printf( &completion,
L"%ls=",
whole_opt.c_str()+offset );
wcstring completion = format_string(L"%ls=", whole_opt.c_str()+offset);
completion_allocate( comp_out,
(wchar_t *)completion.buff,
completion,
C_(o->desc.c_str()),
flags );
sb_destroy( &completion );
}
completion_allocate( comp_out,
@ -1532,45 +1524,24 @@ static int try_complete_user( const wchar_t *cmd,
{
if( wcsncmp( user_name, pw_name, name_len )==0 )
{
string_buffer_t desc;
sb_init( &desc );
sb_printf( &desc,
COMPLETE_USER_DESC,
pw_name );
wcstring desc = format_string(COMPLETE_USER_DESC, pw_name);
completion_allocate( comp,
&pw_name[name_len],
(wchar_t *)desc.buff,
desc,
COMPLETE_NO_SPACE );
res=1;
sb_destroy( &desc );
}
else if( wcsncasecmp( user_name, pw_name, name_len )==0 )
{
string_buffer_t name;
string_buffer_t desc;
sb_init( &name );
sb_init( &desc );
sb_printf( &name,
L"~%ls",
pw_name );
sb_printf( &desc,
COMPLETE_USER_DESC,
pw_name );
wcstring name = format_string(L"~%ls", pw_name);
wcstring desc = format_string(COMPLETE_USER_DESC, pw_name);
completion_allocate( comp,
(wchar_t *)name.buff,
(wchar_t *)desc.buff,
name,
desc,
COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE | COMPLETE_NO_SPACE );
res=1;
sb_destroy( &desc );
sb_destroy( &name );
res=1;
}
free( pw_name );
}

View file

@ -736,30 +736,29 @@ void try_send_all( connection_t *c )
/**
Escape specified string
*/
static wchar_t *full_escape( const wchar_t *in )
static wcstring full_escape( const wchar_t *in )
{
string_buffer_t out;
sb_init( &out );
wcstring out;
for( ; *in; in++ )
{
if( *in < 32 )
{
sb_printf( &out, L"\\x%.2x", *in );
append_format( out, L"\\x%.2x", *in );
}
else if( *in < 128 )
{
sb_append_char( &out, *in );
out.push_back(*in);
}
else if( *in < 65536 )
{
sb_printf( &out, L"\\u%.4x", *in );
append_format( out, L"\\u%.4x", *in );
}
else
{
sb_printf( &out, L"\\U%.8x", *in );
append_format( out, L"\\U%.8x", *in );
}
}
return (wchar_t *)out.buff;
return out;
}
@ -803,12 +802,8 @@ message_t *create_message( int type,
val_in=L"";
}
wchar_t *esc = full_escape( val_in );
if( !esc )
break;
char *val = wcs2utf(esc );
free(esc);
wcstring esc = full_escape( val_in );
char *val = wcs2utf(esc.c_str());
sz = strlen(type==SET?SET_MBS:SET_EXPORT_MBS) + strlen(key) + strlen(val) + 4;
msg = (message_t *)malloc( sizeof( message_t ) + sz );

View file

@ -437,17 +437,13 @@ static int setup_child_process( job_t *j, process_t *p )
}
/**
Returns the interpreter for the specified script. Returns 0 if file
is not a script with a shebang. This function leaks memory on every
call. Only use it in the execve error handler which calls exit
right afterwards, anyway.
Returns the interpreter for the specified script. Returns false if file
is not a script with a shebang.
*/
static wchar_t *get_interpreter( const wcstring &file )
static bool get_interpreter( const wcstring &file, wcstring &interpreter )
{
string_buffer_t sb;
wcstring res;
FILE *fp = wfopen( file, "r" );
sb_init( &sb );
wchar_t *res = 0;
if( fp )
{
while( 1 )
@ -457,17 +453,20 @@ static wchar_t *get_interpreter( const wcstring &file )
break;
if( ch == L'\n' )
break;
sb_append_char( &sb, (wchar_t)ch );
res.push_back(ch);
}
fclose(fp);
}
res = (wchar_t *)sb.buff;
if( !wcsncmp( L"#! /", res, 4 ) )
return res+3;
if( !wcsncmp( L"#!/", res, 3 ) )
return res+2;
return 0;
if (string_prefixes_string(L"#! /", res)) {
interpreter = 3 + res.c_str();
return true;
} else if (string_prefixes_string(L"#!/", res)) {
interpreter = 2 + res.c_str();
return true;
} else {
return false;
}
}
@ -543,14 +542,10 @@ static void launch_process( process_t *p )
size_t sz = 0;
char **p;
string_buffer_t sz1;
string_buffer_t sz2;
wcstring sz1, sz2;
long arg_max = -1;
sb_init( &sz1 );
sb_init( &sz2 );
for(p=argv; *p; p++)
{
sz += strlen(*p)+1;
@ -561,32 +556,28 @@ static void launch_process( process_t *p )
sz += strlen(*p)+1;
}
sb_format_size( &sz1, sz );
sz1 = format_size(sz);
arg_max = sysconf( _SC_ARG_MAX );
if( arg_max > 0 )
{
sb_format_size( &sz2, arg_max );
sz2 = format_size(arg_max);
debug( 0,
L"The total size of the argument and environment lists (%ls) exceeds the operating system limit of %ls.",
(wchar_t *)sz1.buff,
(wchar_t *)sz2.buff);
sz1.c_str(),
sz2.c_str());
}
else
{
debug( 0,
L"The total size of the argument and environment lists (%ls) exceeds the operating system limit.",
(wchar_t *)sz1.buff);
sz1.c_str());
}
debug( 0,
L"Try running the command again with fewer arguments.");
sb_destroy( &sz1 );
sb_destroy( &sz2 );
L"Try running the command again with fewer arguments.");
exit(STATUS_EXEC_FAIL);
break;
@ -602,11 +593,10 @@ static void launch_process( process_t *p )
case ENOENT:
{
wchar_t *interpreter = get_interpreter( p->actual_cmd );
if( interpreter && waccess( interpreter, X_OK ) )
wcstring interpreter;
if( get_interpreter(p->actual_cmd, interpreter) && waccess( interpreter, X_OK ) )
{
debug(0, L"The file '%ls' specified the interpreter '%ls', which is not an executable command.", p->actual_cmd, interpreter );
debug(0, L"The file '%ls' specified the interpreter '%ls', which is not an executable command.", p->actual_cmd, interpreter.c_str() );
}
else
{

View file

@ -355,20 +355,11 @@ static int find_process( const wchar_t *proc,
if( wcsncmp( proc, jid, wcslen(proc ) )==0 )
{
string_buffer_t desc_buff;
sb_init( &desc_buff );
sb_printf( &desc_buff,
COMPLETE_JOB_DESC_VAL,
j->command_cstr() );
wcstring desc_buff = format_string(COMPLETE_JOB_DESC_VAL, j->command_cstr());
completion_allocate( out,
jid+wcslen(proc),
(wchar_t *)desc_buff.buff,
desc_buff,
0 );
sb_destroy( &desc_buff );
}
}
@ -1084,22 +1075,20 @@ static int expand_brackets(parser_t &parser, const wchar_t *in, int flags, std::
}
else
{
string_buffer_t mod;
sb_init( &mod );
wcstring mod;
if( last_sep )
{
sb_append_substring( &mod, in, bracket_begin-in+1 );
sb_append( &mod, last_sep+1 );
sb_append_char( &mod, BRACKET_END );
mod.append( in, bracket_begin-in+1 );
mod.append( last_sep+1 );
mod.push_back( BRACKET_END );
}
else
{
sb_append( &mod, in );
sb_append_char( &mod, BRACKET_END );
mod.append(in);
mod.push_back(BRACKET_END);
}
return expand_brackets( parser, (wchar_t*)mod.buff, 1, out );
return expand_brackets( parser, mod.c_str(), 1, out );
}
}

View file

@ -16,7 +16,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
/** \file fish_indent.c
/** \file fish_indent.cpp
The fish_indent proegram.
*/
@ -47,9 +47,9 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define GETOPT_STRING "hvi"
/**
Read the entire contents of a file into the specified string_Buffer_t
Read the entire contents of a file into the specified string
*/
static void read_file( FILE *f, string_buffer_t *b )
static void read_file( FILE *f, wcstring &b )
{
while( 1 )
{
@ -66,28 +66,23 @@ static void read_file( FILE *f, string_buffer_t *b )
break;
}
sb_append_char( b, c );
b.push_back(c);
}
}
/**
Insert the specified number of tabe into the output buffer
Insert the specified number of tabs into the output buffer
*/
static void insert_tabs( string_buffer_t *out, int indent )
static void insert_tabs( wcstring &out, int indent )
{
int i;
for( i=0; i<indent; i++ )
{
sb_append( out, L"\t" );
}
out.append(L'\t', indent);
}
/**
Indent the specified input
*/
static int indent( string_buffer_t *out, wchar_t *in, int flags )
static int indent( wcstring &out, const wcstring &in, int flags )
{
tokenizer tok;
int res=0;
@ -97,7 +92,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
int prev_type = 0;
int prev_prev_type = 0;
tok_init( &tok, in, TOK_SHOW_COMMENTS );
tok_init( &tok, in.c_str(), TOK_SHOW_COMMENTS );
for( ; tok_has_next( &tok ); tok_next( &tok ) )
{
@ -140,7 +135,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
insert_tabs( out, indent );
}
sb_printf( out, L"%ls", last );
append_format(out, L"%ls", last );
indent = next_indent;
@ -148,8 +143,8 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
else
{
if ( prev_type != TOK_REDIRECT_FD )
sb_append( out, L" " );
sb_append( out, last );
out.append( L" " );
out.append( last );
}
break;
@ -158,7 +153,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
case TOK_END:
{
if( prev_type != TOK_END || prev_prev_type != TOK_END )
sb_append( out, L"\n" );
out.append( L"\n" );
do_indent = 1;
is_command = 1;
break;
@ -166,64 +161,65 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
case TOK_PIPE:
{
sb_append( out, L" " );
out.append( L" " );
if ( last[0] == '2' && !last[1] ) {
sb_append( out, L"^" );
out.append( L"^" );
} else if ( last[0] != '1' || last[1] ) {
sb_append( out, last, L">" );
out.append( last);
out.append( L">" );
}
sb_append( out, L" | " );
out.append( L" | " );
is_command = 1;
break;
}
case TOK_REDIRECT_OUT:
{
sb_append( out, L" " );
out.append( L" " );
if ( wcscmp( last, L"2" ) == 0 ) {
sb_append( out, L"^" );
out.append( L"^" );
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L"> " );
out.append( last );
out.append( L"> " );
}
break;
}
case TOK_REDIRECT_APPEND:
{
sb_append( out, L" " );
out.append( L" " );
if ( wcscmp( last, L"2" ) == 0 ) {
sb_append( out, L"^^" );
out.append( L"^^" );
} else {
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">> " );
out.append( last );
out.append( L">> " );
}
break;
}
case TOK_REDIRECT_IN:
{
sb_append( out, L" " );
out.append( L" " );
if ( wcscmp( last, L"0" ) != 0 )
sb_append( out, last );
sb_append( out, L"< " );
out.append( last );
out.append( L"< " );
break;
}
case TOK_REDIRECT_FD:
{
sb_append( out, L" " );
out.append( L" " );
if ( wcscmp( last, L"1" ) != 0 )
sb_append( out, last );
sb_append( out, L">& " );
out.append( last );
out.append( L">& " );
break;
}
case TOK_BACKGROUND:
{
sb_append( out, L"&\n" );
out.append( L"&\n" );
do_indent = 1;
is_command = 1;
break;
@ -236,7 +232,7 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
insert_tabs( out, indent );
}
sb_printf( out, L"%ls", last );
append_format( out, L"%ls", last );
do_indent = 1;
break;
}
@ -260,34 +256,20 @@ static int indent( string_buffer_t *out, wchar_t *in, int flags )
/**
Remove any prefix and suffix newlines from the specified
string. Does not allocete a new string, edits the string in place
and returns a pointer somewhere into the string.
string.
*/
static wchar_t *trim( wchar_t *in )
static void trim( wcstring &str )
{
wchar_t *end;
while( *in == L'\n' )
{
in++;
}
end = in + wcslen(in);
while( 1 )
{
if( end < in+2 )
break;
if (str.empty())
return;
end--;
if( (*end == L'\n' ) && ( *(end-1) == L'\n' ) )
*end=0;
else
break;
}
return in;
size_t pos = str.find_first_not_of(L" \n");
if (pos > 0)
str.erase(0, pos);
pos = str.find_last_not_of(L" \n");
if (pos != wcstring::npos && pos + 1 < str.length())
str.erase(pos + 1);
}
@ -295,10 +277,7 @@ static wchar_t *trim( wchar_t *in )
The main mathod. Run the program.
*/
int main( int argc, char **argv )
{
string_buffer_t sb_in;
string_buffer_t sb_out;
{
int do_indent=1;
set_main_thread();
wsetlocale( LC_ALL, L"" );
@ -376,23 +355,22 @@ int main( int argc, char **argv )
}
}
sb_init( &sb_in );
sb_init( &sb_out );
read_file( stdin, &sb_in );
wcstring sb_in, sb_out;
read_file( stdin, sb_in );
wutil_init();
if( !indent( &sb_out, (wchar_t *)sb_in.buff, do_indent ) )
if( !indent( sb_out, sb_in, do_indent ) )
{
fwprintf( stdout, L"%ls", trim( (wchar_t *)sb_out.buff) );
trim(sb_out);
fwprintf( stdout, L"%ls", sb_out.c_str() );
}
else
{
/*
Indenting failed - print original input
*/
fwprintf( stdout, L"%ls", (wchar_t *)sb_in.buff );
fwprintf( stdout, L"%ls", sb_in.c_str() );
}

View file

@ -158,7 +158,7 @@ static const wchar_t *hightlight_var[] =
/**
This string_buffer_t contains the text that should be sent back to the calling program
*/
static string_buffer_t out_buff;
static wcstring out_buff;
/**
This is the file to which the output text should be sent. It is really a pipe.
*/
@ -698,21 +698,11 @@ static int completion_try_print( int cols,
*/
while(do_loop)
{
string_buffer_t msg;
sb_init( &msg );
set_color( rgb_color_t::black(), get_color(HIGHLIGHT_PAGER_PROGRESS) );
sb_printf( &msg,
_(L" %d to %d of %d"),
pos,
pos+termsize.ws_row-1,
rows );
sb_printf( &msg,
L" \r" );
wcstring msg = format_string(_(L" %d to %d of %d"), pos, pos+termsize.ws_row-1, rows );
msg.append(L" \r" );
writestr((wchar_t *)msg.buff);
sb_destroy( &msg );
writestr(msg.c_str());
set_color( rgb_color_t::normal(), rgb_color_t::normal() );
pager_flush();
int c = readch();
@ -817,7 +807,7 @@ static int completion_try_print( int cols,
default:
{
sb_append_char( &out_buff, c );
out_buff.push_back( c );
do_loop = 0;
break;
}
@ -1044,11 +1034,6 @@ static void init( int mangle_descriptors, int out )
}
/**
Init the stringbuffer used to keep any output in
*/
sb_init( &out_buff );
env_universal_init( 0, 0, 0, 0);
input_common_init( &interrupt_handler );
output_set_writer( &pager_buffered_writer );
@ -1115,7 +1100,6 @@ static void destroy()
debug( 0, _(L"Error while closing terminfo") );
}
sb_destroy( &out_buff );
fclose( out_file );
}
@ -1437,7 +1421,7 @@ int main( int argc, char **argv )
free(prefix );
fwprintf( out_file, L"%ls", (wchar_t *)out_buff.buff );
fwprintf( out_file, L"%ls", out_buff.c_str() );
if( is_ca_mode )
{
writembs(exit_ca_mode);

View file

@ -115,22 +115,20 @@ static void err( const wchar_t *blah, ... )
static void test_escape()
{
int i;
string_buffer_t sb;
wcstring sb;
say( L"Testing escaping and unescaping" );
sb_init( &sb );
for( i=0; i<ESCAPE_TEST_COUNT; i++ )
{
wchar_t *o, *e, *u;
const wchar_t *o, *e, *u;
sb_clear( &sb );
sb.clear();
while( rand() % ESCAPE_TEST_LENGTH )
{
sb_append_char( &sb, (rand() %ESCAPE_TEST_CHAR) +1 );
sb.push_back((rand() %ESCAPE_TEST_CHAR) +1 );
}
o = (wchar_t *)sb.buff;
o = (const wchar_t *)sb.c_str();
e = escape(o, 1);
u = unescape( e, 0 );
if( !o || !e || !u )
@ -146,8 +144,8 @@ static void test_escape()
}
free( e );
free( u );
free( (void *)e );
free( (void *)u );
}

View file

@ -606,20 +606,18 @@ void parse_util_set_argv( const wchar_t * const *argv, const wcstring_list_t &na
if( *argv )
{
const wchar_t * const *arg;
string_buffer_t sb;
sb_init( &sb );
wcstring sb;
for( arg=argv; *arg; arg++ )
{
if( arg != argv )
{
sb_append( &sb, ARRAY_SEP_STR );
sb.append(ARRAY_SEP_STR);
}
sb_append( &sb, *arg );
sb.append(*arg);
}
env_set( L"argv", (wchar_t *)sb.buff, ENV_LOCAL );
sb_destroy( &sb );
env_set( L"argv", sb.c_str(), ENV_LOCAL );
}
else
{

View file

@ -919,16 +919,15 @@ void parser_t::stack_trace( block_t *b, wcstring &buff)
const process_t * const process = b->state2<process_t*>();
if( process->argv(1) )
{
string_buffer_t tmp;
sb_init( &tmp );
wcstring tmp;
for( i=1; process->argv(i); i++ )
{
sb_append( &tmp, i>1?L" ":L"", process->argv(i), NULL );
if (i > 1)
tmp.push_back(L' ');
tmp.append(process->argv(i));
}
append_format( buff, _(L"\twith parameter list '%ls'\n"), (wchar_t *)tmp.buff );
sb_destroy( &tmp );
append_format( buff, _(L"\twith parameter list '%ls'\n"), tmp.c_str() );
}
}
@ -2582,12 +2581,11 @@ int parser_t::parser_test_argument( const wchar_t *arg, wcstring *out, const wch
{
wchar_t *subst = wcsndup( paran_begin+1, paran_end-paran_begin-1 );
string_buffer_t tmp;
sb_init( &tmp );
wcstring tmp;
sb_append_substring( &tmp, arg_cpy, paran_begin - arg_cpy);
sb_append_char( &tmp, INTERNAL_SEPARATOR);
sb_append( &tmp, paran_end+1);
tmp.append(arg_cpy, paran_begin - arg_cpy);
tmp.push_back(INTERNAL_SEPARATOR);
tmp.append(paran_end+1);
// debug( 1, L"%ls -> %ls %ls", arg_cpy, subst, tmp.buff );
@ -2595,7 +2593,7 @@ int parser_t::parser_test_argument( const wchar_t *arg, wcstring *out, const wch
free( subst );
free( arg_cpy );
arg_cpy = (wchar_t *)tmp.buff;
arg_cpy = wcsdup(tmp.c_str());
/*
Do _not_ call sb_destroy on this stringbuffer - it's

View file

@ -118,16 +118,6 @@ int no_exec=0;
*/
static event_t event(0);
/**
Stringbuffer used to create arguments when firing events
*/
static string_buffer_t event_pid;
/**
Stringbuffer used to create arguments when firing events
*/
static string_buffer_t event_status;
/**
A stack containing the values of is_interactive. Used by proc_push_interactive and proc_pop_interactive.
*/
@ -137,8 +127,6 @@ void proc_init()
{
proc_push_interactive( 0 );
event.arguments.reset(new wcstring_list_t);
sb_init( &event_pid );
sb_init( &event_status );
}
@ -208,8 +196,6 @@ void process_t::set_argv(const wcstring_list_t &argv) {
void proc_destroy()
{
event.arguments.reset(NULL);
sb_destroy( &event_pid );
sb_destroy( &event_status );
job_list_t &jobs = job_list();
while( ! jobs.empty() )
{

View file

@ -937,7 +937,6 @@ static void completion_insert( const wchar_t *val, int flags )
int tok_start, tok_len, move_cursor;
const wchar_t *begin, *end;
string_buffer_t sb;
wchar_t *escaped;
const wchar_t *buff = data->command_line.c_str();
@ -947,33 +946,31 @@ static void completion_insert( const wchar_t *val, int flags )
tok_start = begin - buff;
tok_len = end-begin;
sb_init( &sb );
sb_append_substring( &sb, buff, begin - buff );
wcstring sb(buff, begin - buff);
if( do_escape )
{
escaped = escape( val, ESCAPE_ALL | ESCAPE_NO_QUOTED );
sb_append( &sb, escaped );
sb.append( escaped );
move_cursor = wcslen(escaped);
free( escaped );
}
else
{
sb_append( &sb, val );
sb.append( val );
move_cursor = wcslen(val);
}
if( add_space )
{
sb_append( &sb, L" " );
sb.append( L" " );
move_cursor += 1;
}
sb_append( &sb, end );
sb.append( end );
reader_set_buffer( (wchar_t *)sb.buff, (begin-buff)+move_cursor );
sb_destroy( &sb );
reader_set_buffer( sb, (begin-buff)+move_cursor );
reader_super_highlight_me_plenty( data->buff_pos );
reader_repaint();