diff --git a/builtin_set.cpp b/builtin_set.cpp index e395252a7..19297eaff 100644 --- a/builtin_set.cpp +++ b/builtin_set.cpp @@ -341,7 +341,7 @@ static void print_variables(int include_values, int esc, int scope) value.resize(60); } - wcstring e_value = esc ? expand_escape_variable2(value) : value; + wcstring e_value = esc ? expand_escape_variable(value) : value; sb_append(sb_out, L" ", e_value.c_str(), NULL); diff --git a/complete.cpp b/complete.cpp index 0f18db6b9..c0c3095d0 100644 --- a/complete.cpp +++ b/complete.cpp @@ -203,8 +203,6 @@ void completion_autoload_t::command_removed(const wcstring &cmd) { } -static void complete_free_entry( complete_entry_t *c ); - /** Create a new completion entry @@ -1594,7 +1592,7 @@ static int complete_variable( const wchar_t *whole_var, flags = COMPLETE_NO_CASE | COMPLETE_DONT_ESCAPE; } - wcstring value = expand_escape_variable2( value_unescaped ); + wcstring value = expand_escape_variable( value_unescaped ); wcstring desc = format_string(COMPLETE_VAR_DESC_VAL, value.c_str()); completion_allocate( comp_list, diff --git a/expand.cpp b/expand.cpp index da1a13c15..2f3af4f13 100644 --- a/expand.cpp +++ b/expand.cpp @@ -187,7 +187,7 @@ static const wchar_t* expand_var(const wchar_t *in) Test if the specified string does not contain character which can not be used inside a quoted string. */ -static int is_quotable( wchar_t *str ) +static int is_quotable( const wchar_t *str ) { switch( *str ) { @@ -208,83 +208,62 @@ static int is_quotable( wchar_t *str ) } -wchar_t *expand_escape_variable( const wchar_t *in ) +static int is_quotable(const wcstring &str) { + return is_quotable(str.c_str()); +} + +wcstring expand_escape_variable( const wcstring &in ) { - array_list_t l; - string_buffer_t buff; + wcstring_list_t lst; + wcstring buff; - CHECK( in, 0 ); + tokenize_variable_array2( in, lst ); - al_init( &l ); - tokenize_variable_array( in, &l ); - sb_init( &buff ); - - switch( al_get_count( &l) ) + switch( lst.size() ) { case 0: - sb_append( &buff, L"''"); + buff.append(L"''"); break; case 1: { - wchar_t *el = (wchar_t *)al_get( &l, 0 ); + const wcstring &el = lst.at(0); - if( wcschr( el, L' ' ) && is_quotable( el ) ) + if( el.find(L' ') != wcstring::npos && is_quotable( el ) ) { - sb_append( &buff, - L"'", - el, - L"'", - NULL ); + buff.append(L"'"); + buff.append(el); + buff.append(L"'"); } else { - wchar_t *val = escape( el, 1 ); - sb_append( &buff, val ); - free( val ); + buff.append(escape_string(el, 1)); } - free( el ); break; } default: { - int j; - for( j=0; j