aboutsummaryrefslogtreecommitdiffhomepage
path: root/complete.cpp
diff options
context:
space:
mode:
authorGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-24 09:32:15 -0800
committerGravatar ridiculousfish <corydoras@ridiculousfish.com>2012-02-24 09:33:30 -0800
commit90e979d0d9a94601fc9a0c1e5ad785ede1e92381 (patch)
treea2e80a09c0e85f6d6d55362b5cc7dace1b9f427a /complete.cpp
parent8232857d0785b5b2db8884d11680de5c2fe9b857 (diff)
Added some const correctness
Diffstat (limited to 'complete.cpp')
-rw-r--r--complete.cpp23
1 files changed, 10 insertions, 13 deletions
diff --git a/complete.cpp b/complete.cpp
index 78282cc7..c7d12f81 100644
--- a/complete.cpp
+++ b/complete.cpp
@@ -1556,8 +1556,9 @@ static int try_complete_user( const wchar_t *cmd,
void complete( const wchar_t *cmd,
std::vector<completion_t> &comp )
{
+
const wchar_t *tok_begin, *tok_end, *cmdsubst_begin, *cmdsubst_end, *prev_begin, *prev_end;
- wchar_t *buff;
+ wcstring buff;
tokenizer tok;
const wchar_t *current_token=0, *current_command=0, *prev_token=0;
int on_command=0;
@@ -1601,10 +1602,7 @@ void complete( const wchar_t *cmd,
{
pos = cursor_pos-(cmdsubst_begin-cmd);
- buff = wcsndup( cmdsubst_begin, cmdsubst_end-cmdsubst_begin );
-
- if( !buff )
- done=1;
+ buff = wcstring( cmdsubst_begin, cmdsubst_end-cmdsubst_begin );
}
if( !done )
@@ -1612,7 +1610,7 @@ void complete( const wchar_t *cmd,
int had_cmd=0;
int end_loop=0;
- tok_init( &tok, buff, TOK_ACCEPT_UNFINISHED );
+ tok_init( &tok, buff.c_str(), TOK_ACCEPT_UNFINISHED );
while( tok_has_next( &tok) && !end_loop )
{
@@ -1623,21 +1621,21 @@ void complete( const wchar_t *cmd,
case TOK_STRING:
{
- wchar_t *ncmd = tok_last( &tok );
- int is_ddash = (wcscmp( ncmd, L"--" ) == 0) && ( (tok_get_pos( &tok )+2) < pos );
+ const wcstring ncmd = tok_last( &tok );
+ int is_ddash = (ncmd == L"--") && ( (tok_get_pos( &tok )+2) < pos );
if( !had_cmd )
{
if( parser_keywords_is_subcommand( ncmd ) )
{
- if( wcscmp( ncmd, L"builtin" )==0)
+ if (ncmd == L"builtin" )
{
use_function = 0;
use_command = 0;
use_builtin = 1;
}
- else if( wcscmp( ncmd, L"command" )==0)
+ else if (ncmd == L"command")
{
use_command = 1;
use_function = 0;
@@ -1653,9 +1651,9 @@ void complete( const wchar_t *cmd,
int token_end;
free( (void *)current_command );
- current_command = wcsdup( ncmd );
+ current_command = wcsdup( ncmd.c_str() );
- token_end = tok_get_pos( &tok ) + wcslen( ncmd );
+ token_end = tok_get_pos( &tok ) + ncmd.size();
on_command = (pos <= token_end );
had_cmd=1;
@@ -1703,7 +1701,6 @@ void complete( const wchar_t *cmd,
}
tok_destroy( &tok );
- free( buff );
/*
Get the string to complete