diff options
author | 2012-11-18 16:30:30 -0800 | |
---|---|---|
committer | 2012-11-18 16:30:30 -0800 | |
commit | 9992b8eb0e3366ff8a3948aa0b66a19c3c12c737 (patch) | |
tree | 6dda0fef85812016fbba9ea067c9d586092b506d /parse_util.cpp | |
parent | bab69f26724028d16054a3daf5c78aad7c67bb2d (diff) |
Apply new indentation, brace, and whitespace style
Diffstat (limited to 'parse_util.cpp')
-rw-r--r-- | parse_util.cpp | 1076 |
1 files changed, 538 insertions, 538 deletions
diff --git a/parse_util.cpp b/parse_util.cpp index dc111657..3b96ac67 100644 --- a/parse_util.cpp +++ b/parse_util.cpp @@ -51,614 +51,614 @@ */ #define AUTOLOAD_MIN_AGE 60 -int parse_util_lineno( const wchar_t *str, size_t offset ) +int parse_util_lineno(const wchar_t *str, size_t offset) { - if (! str) - return 0; + if (! str) + return 0; - int res = 1; - for( size_t i=0; str[i] && i<offset; i++ ) - { - if( str[i] == L'\n' ) + int res = 1; + for (size_t i=0; str[i] && i<offset; i++) { - res++; + if (str[i] == L'\n') + { + res++; + } } - } - return res; + return res; } -int parse_util_get_line_from_offset( const wcstring &str, size_t pos ) +int parse_util_get_line_from_offset(const wcstring &str, size_t pos) { const wchar_t *buff = str.c_str(); - int count = 0; - for( size_t i=0; i<pos; i++ ) - { - if( !buff[i] ) + int count = 0; + for (size_t i=0; i<pos; i++) { - return -1; - } + if (!buff[i]) + { + return -1; + } - if( buff[i] == L'\n' ) - { - count++; + if (buff[i] == L'\n') + { + count++; + } } - } - return count; + return count; } -size_t parse_util_get_offset_from_line( const wcstring &str, int line ) +size_t parse_util_get_offset_from_line(const wcstring &str, int line) { const wchar_t *buff = str.c_str(); - size_t i; - int count = 0; - - if( line < 0 ) - { - return (size_t)(-1); - } - - if( line == 0 ) - return 0; + size_t i; + int count = 0; - for( i=0;; i++ ) - { - if( !buff[i] ) + if (line < 0) { - return -1; + return (size_t)(-1); } - if( buff[i] == L'\n' ) + if (line == 0) + return 0; + + for (i=0;; i++) { - count++; - if( count == line ) - { - return (i+1)<str.size()?i+1:i; - } + if (!buff[i]) + { + return -1; + } + if (buff[i] == L'\n') + { + count++; + if (count == line) + { + return (i+1)<str.size()?i+1:i; + } + + } } - } } -size_t parse_util_get_offset( const wcstring &str, int line, long line_offset ) +size_t parse_util_get_offset(const wcstring &str, int line, long line_offset) { const wchar_t *buff = str.c_str(); - size_t off = parse_util_get_offset_from_line( buff, line ); - size_t off2 = parse_util_get_offset_from_line( buff, line+1 ); - long line_offset2 = line_offset; + size_t off = parse_util_get_offset_from_line(buff, line); + size_t off2 = parse_util_get_offset_from_line(buff, line+1); + long line_offset2 = line_offset; - if( off == (size_t)(-1) ) - { - return -1; - } + if (off == (size_t)(-1)) + { + return -1; + } - if( off2 == (size_t)(-1) ) - { - off2 = wcslen( buff )+1; - } + if (off2 == (size_t)(-1)) + { + off2 = wcslen(buff)+1; + } - if( line_offset2 < 0 ) - { - line_offset2 = 0; - } + if (line_offset2 < 0) + { + line_offset2 = 0; + } - if( line_offset2 >= off2-off-1 ) - { - line_offset2 = off2-off-1; - } + if (line_offset2 >= off2-off-1) + { + line_offset2 = off2-off-1; + } - return off + line_offset2; + return off + line_offset2; } -int parse_util_locate_cmdsubst( const wchar_t *in, - wchar_t **begin, - wchar_t **end, - int allow_incomplete ) +int parse_util_locate_cmdsubst(const wchar_t *in, + wchar_t **begin, + wchar_t **end, + int allow_incomplete) { - wchar_t *pos; - wchar_t prev=0; - int syntax_error=0; - int paran_count=0; + wchar_t *pos; + wchar_t prev=0; + int syntax_error=0; + int paran_count=0; - wchar_t *paran_begin=0, *paran_end=0; + wchar_t *paran_begin=0, *paran_end=0; - CHECK( in, 0 ); + CHECK(in, 0); - for( pos = (wchar_t *)in; *pos; pos++ ) - { - if( prev != '\\' ) + for (pos = (wchar_t *)in; *pos; pos++) { - if( wcschr( L"\'\"", *pos ) ) - { - wchar_t *q_end = quote_end( pos ); - if( q_end && *q_end) - { - pos=q_end; - } - else - { - break; - } - } - else - { - if( *pos == '(' ) + if (prev != '\\') { - if(( paran_count == 0)&&(paran_begin==0)) - { - paran_begin = pos; - } + if (wcschr(L"\'\"", *pos)) + { + wchar_t *q_end = quote_end(pos); + if (q_end && *q_end) + { + pos=q_end; + } + else + { + break; + } + } + else + { + if (*pos == '(') + { + if ((paran_count == 0)&&(paran_begin==0)) + { + paran_begin = pos; + } - paran_count++; - } - else if( *pos == ')' ) - { + paran_count++; + } + else if (*pos == ')') + { - paran_count--; + paran_count--; - if( (paran_count == 0) && (paran_end == 0) ) - { - paran_end = pos; - break; - } + if ((paran_count == 0) && (paran_end == 0)) + { + paran_end = pos; + break; + } - if( paran_count < 0 ) - { - syntax_error = 1; - break; - } - } - } + if (paran_count < 0) + { + syntax_error = 1; + break; + } + } + } + } + prev = *pos; } - prev = *pos; - } - syntax_error |= (paran_count < 0 ); - syntax_error |= ((paran_count>0)&&(!allow_incomplete)); + syntax_error |= (paran_count < 0); + syntax_error |= ((paran_count>0)&&(!allow_incomplete)); - if( syntax_error ) - { - return -1; - } + if (syntax_error) + { + return -1; + } - if( paran_begin == 0 ) - { - return 0; - } + if (paran_begin == 0) + { + return 0; + } - if( begin ) - { - *begin = paran_begin; - } + if (begin) + { + *begin = paran_begin; + } - if( end ) - { - *end = paran_count?(wchar_t *)in+wcslen(in):paran_end; - } + if (end) + { + *end = paran_count?(wchar_t *)in+wcslen(in):paran_end; + } - return 1; + return 1; } -void parse_util_cmdsubst_extent( const wchar_t *buff, - size_t cursor_pos, - const wchar_t **a, - const wchar_t **b ) +void parse_util_cmdsubst_extent(const wchar_t *buff, + size_t cursor_pos, + const wchar_t **a, + const wchar_t **b) { - wchar_t *begin, *end; - wchar_t *pos; - const wchar_t *cursor = buff + cursor_pos; - - CHECK( buff, ); - - if( a ) - { - *a = (wchar_t *)buff; - } - - if( b ) - { - *b = (wchar_t *)buff+wcslen(buff); - } + wchar_t *begin, *end; + wchar_t *pos; + const wchar_t *cursor = buff + cursor_pos; - pos = (wchar_t *)buff; + CHECK(buff,); - while( 1 ) - { - if( parse_util_locate_cmdsubst( pos, - &begin, - &end, - 1 ) <= 0) + if (a) { - /* - No subshell found - */ - break; + *a = (wchar_t *)buff; } - if( !end ) + if (b) { - end = (wchar_t *)buff + wcslen(buff); + *b = (wchar_t *)buff+wcslen(buff); } - if(( begin < cursor ) && (end >= cursor) ) + pos = (wchar_t *)buff; + + while (1) { - begin++; + if (parse_util_locate_cmdsubst(pos, + &begin, + &end, + 1) <= 0) + { + /* + No subshell found + */ + break; + } - if( a ) - { - *a = begin; - } + if (!end) + { + end = (wchar_t *)buff + wcslen(buff); + } - if( b ) - { - *b = end; - } + if ((begin < cursor) && (end >= cursor)) + { + begin++; - break; - } + if (a) + { + *a = begin; + } - if( !*end ) - { - break; - } + if (b) + { + *b = end; + } - pos = end+1; - } + break; + } + + if (!*end) + { + break; + } + + pos = end+1; + } } /** Get the beginning and end of the job or process definition under the cursor */ -static void job_or_process_extent( const wchar_t *buff, - size_t cursor_pos, - const wchar_t **a, - const wchar_t **b, - int process ) +static void job_or_process_extent(const wchar_t *buff, + size_t cursor_pos, + const wchar_t **a, + const wchar_t **b, + int process) { - const wchar_t *begin, *end; - long pos; - wchar_t *buffcpy; - int finished=0; - - tokenizer tok; + const wchar_t *begin, *end; + long pos; + wchar_t *buffcpy; + int finished=0; - CHECK( buff, ); + tokenizer tok; - if( a ) - { - *a=0; - } + CHECK(buff,); - if( b ) - { - *b = 0; - } + if (a) + { + *a=0; + } - parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end ); - if( !end || !begin ) - { - return; - } + if (b) + { + *b = 0; + } - pos = cursor_pos - (begin - buff); + parse_util_cmdsubst_extent(buff, cursor_pos, &begin, &end); + if (!end || !begin) + { + return; + } - if( a ) - { - *a = begin; - } + pos = cursor_pos - (begin - buff); - if( b ) - { - *b = end; - } + if (a) + { + *a = begin; + } - buffcpy = wcsndup( begin, end-begin ); + if (b) + { + *b = end; + } - if( !buffcpy ) - { - DIE_MEM(); - } + buffcpy = wcsndup(begin, end-begin); - for( tok_init( &tok, buffcpy, TOK_ACCEPT_UNFINISHED ); - tok_has_next( &tok ) && !finished; - tok_next( &tok ) ) - { - int tok_begin = tok_get_pos( &tok ); + if (!buffcpy) + { + DIE_MEM(); + } - switch( tok_last_type( &tok ) ) + for (tok_init(&tok, buffcpy, TOK_ACCEPT_UNFINISHED); + tok_has_next(&tok) && !finished; + tok_next(&tok)) { - case TOK_PIPE: - { - if( !process ) + int tok_begin = tok_get_pos(&tok); + + switch (tok_last_type(&tok)) { - break; + case TOK_PIPE: + { + if (!process) + { + break; + } } - } - - case TOK_END: - case TOK_BACKGROUND: - { - if( tok_begin >= pos ) + case TOK_END: + case TOK_BACKGROUND: { - finished=1; - if( b ) - { - *b = (wchar_t *)buff + tok_begin; - } + + if (tok_begin >= pos) + { + finished=1; + if (b) + { + *b = (wchar_t *)buff + tok_begin; + } + } + else + { + if (a) + { + *a = (wchar_t *)buff + tok_begin+1; + } + } + + break; } - else - { - if( a ) - { - *a = (wchar_t *)buff + tok_begin+1; - } } - - break; - } } - } - free( buffcpy); + free(buffcpy); - tok_destroy( &tok ); + tok_destroy(&tok); } -void parse_util_process_extent( const wchar_t *buff, - size_t pos, - const wchar_t **a, - const wchar_t **b ) +void parse_util_process_extent(const wchar_t *buff, + size_t pos, + const wchar_t **a, + const wchar_t **b) { - job_or_process_extent( buff, pos, a, b, 1 ); + job_or_process_extent(buff, pos, a, b, 1); } -void parse_util_job_extent( const wchar_t *buff, - size_t pos, - const wchar_t **a, - const wchar_t **b ) +void parse_util_job_extent(const wchar_t *buff, + size_t pos, + const wchar_t **a, + const wchar_t **b) { - job_or_process_extent( buff,pos,a, b, 0 ); + job_or_process_extent(buff,pos,a, b, 0); } -void parse_util_token_extent( const wchar_t *buff, - size_t cursor_pos, - const wchar_t **tok_begin, - const wchar_t **tok_end, - const wchar_t **prev_begin, - const wchar_t **prev_end ) +void parse_util_token_extent(const wchar_t *buff, + size_t cursor_pos, + const wchar_t **tok_begin, + const wchar_t **tok_end, + const wchar_t **prev_begin, + const wchar_t **prev_end) { - const wchar_t *begin, *end; - long pos; - wchar_t *buffcpy; - - tokenizer tok; + const wchar_t *begin, *end; + long pos; + wchar_t *buffcpy; - const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL; + tokenizer tok; - CHECK( buff, ); + const wchar_t *a = NULL, *b = NULL, *pa = NULL, *pb = NULL; - assert( cursor_pos >= 0 ); + CHECK(buff,); - parse_util_cmdsubst_extent( buff, cursor_pos, &begin, &end ); + assert(cursor_pos >= 0); - if( !end || !begin ) - { - return; - } + parse_util_cmdsubst_extent(buff, cursor_pos, &begin, &end); - pos = cursor_pos - (begin - buff); - - a = buff + pos; - b = a; - pa = buff + pos; - pb = pa; + if (!end || !begin) + { + return; + } - assert( begin >= buff ); - assert( begin <= (buff+wcslen(buff) ) ); - assert( end >= begin ); - assert( end <= (buff+wcslen(buff) ) ); + pos = cursor_pos - (begin - buff); - buffcpy = wcsndup( begin, end-begin ); + a = buff + pos; + b = a; + pa = buff + pos; + pb = pa; - if( !buffcpy ) - { - DIE_MEM(); - } + assert(begin >= buff); + assert(begin <= (buff+wcslen(buff))); + assert(end >= begin); + assert(end <= (buff+wcslen(buff))); - for( tok_init( &tok, buffcpy, TOK_ACCEPT_UNFINISHED | TOK_SQUASH_ERRORS ); - tok_has_next( &tok ); - tok_next( &tok ) ) - { - size_t tok_begin = tok_get_pos( &tok ); - size_t tok_end = tok_begin; + buffcpy = wcsndup(begin, end-begin); - /* - Calculate end of token - */ - if( tok_last_type( &tok ) == TOK_STRING ) + if (!buffcpy) { - tok_end += wcslen(tok_last(&tok)); + DIE_MEM(); } - /* - Cursor was before beginning of this token, means that the - cursor is between two tokens, so we set it to a zero element - string and break - */ - if( tok_begin > pos ) + for (tok_init(&tok, buffcpy, TOK_ACCEPT_UNFINISHED | TOK_SQUASH_ERRORS); + tok_has_next(&tok); + tok_next(&tok)) { - a = b = (wchar_t *)buff + pos; - break; - } + size_t tok_begin = tok_get_pos(&tok); + size_t tok_end = tok_begin; - /* - If cursor is inside the token, this is the token we are - looking for. If so, set a and b and break - */ - if( (tok_last_type( &tok ) == TOK_STRING) && (tok_end >= pos ) ) - { - a = begin + tok_get_pos( &tok ); - b = a + wcslen(tok_last(&tok)); - break; - } + /* + Calculate end of token + */ + if (tok_last_type(&tok) == TOK_STRING) + { + tok_end += wcslen(tok_last(&tok)); + } - /* - Remember previous string token - */ - if( tok_last_type( &tok ) == TOK_STRING ) - { - pa = begin + tok_get_pos( &tok ); - pb = pa + wcslen(tok_last(&tok)); + /* + Cursor was before beginning of this token, means that the + cursor is between two tokens, so we set it to a zero element + string and break + */ + if (tok_begin > pos) + { + a = b = (wchar_t *)buff + pos; + break; + } + + /* + If cursor is inside the token, this is the token we are + looking for. If so, set a and b and break + */ + if ((tok_last_type(&tok) == TOK_STRING) && (tok_end >= pos)) + { + a = begin + tok_get_pos(&tok); + b = a + wcslen(tok_last(&tok)); + break; + } + + /* + Remember previous string token + */ + if (tok_last_type(&tok) == TOK_STRING) + { + pa = begin + tok_get_pos(&tok); + pb = pa + wcslen(tok_last(&tok)); + } } - } - free( buffcpy); + free(buffcpy); - tok_destroy( &tok ); + tok_destroy(&tok); - if( tok_begin ) - { - *tok_begin = a; - } + if (tok_begin) + { + *tok_begin = a; + } - if( tok_end ) - { - *tok_end = b; - } + if (tok_end) + { + *tok_end = b; + } - if( prev_begin ) - { - *prev_begin = pa; - } + if (prev_begin) + { + *prev_begin = pa; + } - if( prev_end ) - { - *prev_end = pb; - } + if (prev_end) + { + *prev_end = pb; + } - assert( pa >= buff ); - assert( pa <= (buff+wcslen(buff) ) ); - assert( pb >= pa ); - assert( pb <= (buff+wcslen(buff) ) ); + assert(pa >= buff); + assert(pa <= (buff+wcslen(buff))); + assert(pb >= pa); + assert(pb <= (buff+wcslen(buff))); } -void parse_util_set_argv( const wchar_t * const *argv, const wcstring_list_t &named_arguments ) +void parse_util_set_argv(const wchar_t * const *argv, const wcstring_list_t &named_arguments) { - if( *argv ) - { - const wchar_t * const *arg; - wcstring sb; - - for( arg=argv; *arg; arg++ ) + if (*argv) { - if( arg != argv ) - { - sb.append(ARRAY_SEP_STR); - } - sb.append(*arg); - } + const wchar_t * const *arg; + wcstring sb; - env_set( L"argv", sb.c_str(), ENV_LOCAL ); - } - else - { - env_set( L"argv", 0, ENV_LOCAL ); - } + for (arg=argv; *arg; arg++) + { + if (arg != argv) + { + sb.append(ARRAY_SEP_STR); + } + sb.append(*arg); + } - if( named_arguments.size() ) - { - const wchar_t * const *arg; - size_t i; + env_set(L"argv", sb.c_str(), ENV_LOCAL); + } + else + { + env_set(L"argv", 0, ENV_LOCAL); + } - for( i=0, arg=argv; i < named_arguments.size(); i++ ) + if (named_arguments.size()) { - env_set( named_arguments.at(i).c_str(), *arg, ENV_LOCAL ); + const wchar_t * const *arg; + size_t i; - if( *arg ) - arg++; - } + for (i=0, arg=argv; i < named_arguments.size(); i++) + { + env_set(named_arguments.at(i).c_str(), *arg, ENV_LOCAL); + + if (*arg) + arg++; + } - } + } } -wchar_t *parse_util_unescape_wildcards( const wchar_t *str ) +wchar_t *parse_util_unescape_wildcards(const wchar_t *str) { - wchar_t *in, *out; - wchar_t *unescaped; + wchar_t *in, *out; + wchar_t *unescaped; - CHECK( str, 0 ); + CHECK(str, 0); - unescaped = wcsdup(str); + unescaped = wcsdup(str); - if( !unescaped ) - { - DIE_MEM(); - } + if (!unescaped) + { + DIE_MEM(); + } - for( in=out=unescaped; *in; in++ ) - { - switch( *in ) + for (in=out=unescaped; *in; in++) { - case L'\\': - { - switch ( *(in + 1) ) - { - case L'*': - case L'?': - { - in++; - *(out++)=*in; - break; - } - case L'\\': - { - in++; - *(out++)=L'\\'; - *(out++)=L'\\'; - break; - } - default: - { - *(out++)=*in; - break; - } - } - break; - } - - case L'*': - { - *(out++)=ANY_STRING; - break; - } - - case L'?': - { - *(out++)=ANY_CHAR; - break; - } - - default: - { - *(out++)=*in; - break; - } - } - } + switch (*in) + { + case L'\\': + { + switch (*(in + 1)) + { + case L'*': + case L'?': + { + in++; + *(out++)=*in; + break; + } + case L'\\': + { + in++; + *(out++)=L'\\'; + *(out++)=L'\\'; + break; + } + default: + { + *(out++)=*in; + break; + } + } + break; + } + + case L'*': + { + *(out++)=ANY_STRING; + break; + } + + case L'?': + { + *(out++)=ANY_CHAR; + break; + } + + default: + { + *(out++)=*in; + break; + } + } + } *out = *in; - return unescaped; + return unescaped; } @@ -667,116 +667,116 @@ wchar_t *parse_util_unescape_wildcards( const wchar_t *str ) token is not quoted. */ -static wchar_t get_quote( const wchar_t *cmd, size_t len ) +static wchar_t get_quote(const wchar_t *cmd, size_t len) { - size_t i=0; - wchar_t res=0; + size_t i=0; + wchar_t res=0; - while( 1 ) - { - if( !cmd[i] ) - break; - - if( cmd[i] == L'\\' ) + while (1) { - i++; - if( !cmd[i] ) - break; - i++; - } - else - { - if( cmd[i] == L'\'' || cmd[i] == L'\"' ) - { - const wchar_t *end = quote_end( &cmd[i] ); - //fwprintf( stderr, L"Jump %d\n", end-cmd ); - if(( end == 0 ) || (!*end) || (end-cmd > len)) + if (!cmd[i]) + break; + + if (cmd[i] == L'\\') { - res = cmd[i]; - break; + i++; + if (!cmd[i]) + break; + i++; + } + else + { + if (cmd[i] == L'\'' || cmd[i] == L'\"') + { + const wchar_t *end = quote_end(&cmd[i]); + //fwprintf( stderr, L"Jump %d\n", end-cmd ); + if ((end == 0) || (!*end) || (end-cmd > len)) + { + res = cmd[i]; + break; + } + i = end-cmd+1; + } + else + i++; } - i = end-cmd+1; - } - else - i++; } - } - return res; + return res; } -void parse_util_get_parameter_info( const wcstring &cmd, const size_t pos, wchar_t *quote, size_t *offset, int *type ) +void parse_util_get_parameter_info(const wcstring &cmd, const size_t pos, wchar_t *quote, size_t *offset, int *type) { - size_t prev_pos=0; - wchar_t last_quote = '\0'; - int unfinished; + size_t prev_pos=0; + wchar_t last_quote = '\0'; + int unfinished; - tokenizer tok; - tok_init( &tok, cmd.c_str(), TOK_ACCEPT_UNFINISHED | TOK_SQUASH_ERRORS ); + tokenizer tok; + tok_init(&tok, cmd.c_str(), TOK_ACCEPT_UNFINISHED | TOK_SQUASH_ERRORS); - for( ; tok_has_next( &tok ); tok_next( &tok ) ) - { - if( tok_get_pos( &tok ) > pos ) - break; + for (; tok_has_next(&tok); tok_next(&tok)) + { + if (tok_get_pos(&tok) > pos) + break; - if( tok_last_type( &tok ) == TOK_STRING ) - last_quote = get_quote( tok_last( &tok ), - pos - tok_get_pos( &tok ) ); + if (tok_last_type(&tok) == TOK_STRING) + last_quote = get_quote(tok_last(&tok), + pos - tok_get_pos(&tok)); - if( type != NULL ) - *type = tok_last_type( &tok ); + if (type != NULL) + *type = tok_last_type(&tok); - prev_pos = tok_get_pos( &tok ); - } + prev_pos = tok_get_pos(&tok); + } - tok_destroy( &tok ); + tok_destroy(&tok); wchar_t *cmd_tmp = wcsdup(cmd.c_str()); - cmd_tmp[pos]=0; - size_t cmdlen = wcslen( cmd_tmp ); - unfinished = (cmdlen==0); - if( !unfinished ) - { - unfinished = (quote != 0); - - if( !unfinished ) - { - if( wcschr( L" \t\n\r", cmd_tmp[cmdlen-1] ) != 0 ) - { - if( ( cmdlen == 1) || (cmd_tmp[cmdlen-2] != L'\\') ) + cmd_tmp[pos]=0; + size_t cmdlen = wcslen(cmd_tmp); + unfinished = (cmdlen==0); + if (!unfinished) + { + unfinished = (quote != 0); + + if (!unfinished) { - unfinished=1; + if (wcschr(L" \t\n\r", cmd_tmp[cmdlen-1]) != 0) + { + if ((cmdlen == 1) || (cmd_tmp[cmdlen-2] != L'\\')) + { + unfinished=1; + } + } } - } } - } - if( quote ) - *quote = last_quote; + if (quote) + *quote = last_quote; - if( offset != 0 ) - { - if( !unfinished ) + if (offset != 0) { - while( (cmd_tmp[prev_pos] != 0) && (wcschr( L";|",cmd_tmp[prev_pos])!= 0) ) - prev_pos++; + if (!unfinished) + { + while ((cmd_tmp[prev_pos] != 0) && (wcschr(L";|",cmd_tmp[prev_pos])!= 0)) + prev_pos++; - *offset = prev_pos; - } - else - { - *offset = pos; + *offset = prev_pos; + } + else + { + *offset = pos; + } } - } free(cmd_tmp); } -wcstring parse_util_escape_string_with_quote( const wcstring &cmd, wchar_t quote) +wcstring parse_util_escape_string_with_quote(const wcstring &cmd, wchar_t quote) { wcstring result; - if( quote == L'\0' ) + if (quote == L'\0') { - result = escape_string( cmd, ESCAPE_ALL | ESCAPE_NO_QUOTED | ESCAPE_NO_TILDE ); + result = escape_string(cmd, ESCAPE_ALL | ESCAPE_NO_QUOTED | ESCAPE_NO_TILDE); } else { @@ -786,17 +786,17 @@ wcstring parse_util_escape_string_with_quote( const wcstring &cmd, wchar_t quote wchar_t c = cmd.at(i); switch (c) { - case L'\n': - case L'\t': - case L'\b': - case L'\r': - unescapable = true; - break; - default: - if (c == quote) - result.push_back(L'\\'); - result.push_back(c); - break; + case L'\n': + case L'\t': + case L'\b': + case L'\r': + unescapable = true; + break; + default: + if (c == quote) + result.push_back(L'\\'); + result.push_back(c); + break; } } |