mirror of
https://github.com/neovim/neovim.git
synced 2025-02-25 18:55:25 -06:00
style: fixing minor issues noted in code review.
This commit is contained in:
parent
071aab5148
commit
5cecd7a93a
@ -2899,11 +2899,7 @@ const char * set_one_cmd_context(
|
||||
xp->xp_pattern = skipwhite((const char_u *)arg);
|
||||
p = (const char *)xp->xp_pattern;
|
||||
while (*p != NUL) {
|
||||
if (has_mbyte) {
|
||||
c = utf_ptr2char((const char_u *)p);
|
||||
} else {
|
||||
c = (uint8_t)(*p);
|
||||
}
|
||||
c = utf_ptr2char((const char_u *)p);
|
||||
if (c == '\\' && p[1] != NUL) {
|
||||
p++;
|
||||
} else if (c == '`') {
|
||||
@ -2921,19 +2917,11 @@ const char * set_one_cmd_context(
|
||||
|| ascii_iswhite(c)) {
|
||||
len = 0; /* avoid getting stuck when space is in 'isfname' */
|
||||
while (*p != NUL) {
|
||||
if (has_mbyte) {
|
||||
c = utf_ptr2char((const char_u *)p);
|
||||
} else {
|
||||
c = *p;
|
||||
}
|
||||
c = utf_ptr2char((const char_u *)p);
|
||||
if (c == '`' || vim_isfilec_or_wc(c)) {
|
||||
break;
|
||||
}
|
||||
if (has_mbyte) {
|
||||
len = (size_t)(*mb_ptr2len)((const char_u *)p);
|
||||
} else {
|
||||
len = 1;
|
||||
}
|
||||
len = (size_t)utfc_ptr2len((const char_u *)p);
|
||||
MB_PTR_ADV(p);
|
||||
}
|
||||
if (in_quote) {
|
||||
|
@ -3327,17 +3327,11 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
|
||||
|
||||
/* Locate start of last word in the cmd buffer. */
|
||||
for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff; ) {
|
||||
if (has_mbyte) {
|
||||
len = (*mb_head_off)(ccline.cmdbuff, w - 1) + 1;
|
||||
if (!vim_iswordc(utf_ptr2char(w - len))) {
|
||||
break;
|
||||
}
|
||||
w -= len;
|
||||
} else {
|
||||
if (!vim_iswordc(w[-1]))
|
||||
break;
|
||||
--w;
|
||||
len = utf_head_off(ccline.cmdbuff, w - 1) + 1;
|
||||
if (!vim_iswordc(utf_ptr2char(w - len))) {
|
||||
break;
|
||||
}
|
||||
w -= len;
|
||||
}
|
||||
len = (int)((ccline.cmdbuff + ccline.cmdpos) - w);
|
||||
if (p_ic ? STRNICMP(w, arg, len) == 0 : STRNCMP(w, arg, len) == 0)
|
||||
@ -3838,24 +3832,13 @@ ExpandOne (
|
||||
|
||||
// Find longest common part
|
||||
if (mode == WILD_LONGEST && xp->xp_numfiles > 0) {
|
||||
size_t len;
|
||||
size_t mb_len = 1;
|
||||
int c0;
|
||||
int ci;
|
||||
size_t len = 0;
|
||||
|
||||
for (len = 0; xp->xp_files[0][len]; len += mb_len) {
|
||||
if (has_mbyte) {
|
||||
mb_len = (* mb_ptr2len)(&xp->xp_files[0][len]);
|
||||
c0 = utf_ptr2char(&xp->xp_files[0][len]);
|
||||
} else {
|
||||
c0 = xp->xp_files[0][len];
|
||||
}
|
||||
for (i = 1; i < xp->xp_numfiles; ++i) {
|
||||
if (has_mbyte) {
|
||||
ci = utf_ptr2char(&xp->xp_files[i][len]);
|
||||
} else {
|
||||
ci = xp->xp_files[i][len];
|
||||
}
|
||||
for (size_t mb_len; xp->xp_files[0][len]; len += mb_len) {
|
||||
mb_len = utfc_ptr2len(&xp->xp_files[0][len]);
|
||||
int c0 = utf_ptr2char(&xp->xp_files[0][len]);
|
||||
for (i = 1; i < xp->xp_numfiles; i++) {
|
||||
int ci = utf_ptr2char(&xp->xp_files[i][len]);
|
||||
|
||||
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|
||||
|| xp->xp_context == EXPAND_FILES
|
||||
|
@ -1763,10 +1763,10 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume,
|
||||
if (text != NULL) {
|
||||
/* Replace unprintable characters, if there are any. But
|
||||
* replace a TAB with a space. */
|
||||
for (p = text; *p != NUL; ++p) {
|
||||
int len;
|
||||
for (p = text; *p != NUL; p++) {
|
||||
int len = utfc_ptr2len(p);
|
||||
|
||||
if (has_mbyte && (len = (*mb_ptr2len)(p)) > 1) {
|
||||
if (len > 1) {
|
||||
if (!vim_isprintc(utf_ptr2char(p))) {
|
||||
break;
|
||||
}
|
||||
|
@ -2866,15 +2866,12 @@ do_dialog (
|
||||
// Make the character lowercase, as chars in "hotkeys" are.
|
||||
c = mb_tolower(c);
|
||||
retval = 1;
|
||||
for (i = 0; hotkeys[i]; ++i) {
|
||||
if (has_mbyte) {
|
||||
if (utf_ptr2char(hotkeys + i) == c) {
|
||||
break;
|
||||
}
|
||||
i += (*mb_ptr2len)(hotkeys + i) - 1;
|
||||
} else if (hotkeys[i] == c)
|
||||
for (i = 0; hotkeys[i]; i++) {
|
||||
if (utf_ptr2char(hotkeys + i) == c) {
|
||||
break;
|
||||
++retval;
|
||||
}
|
||||
i += utfc_ptr2len(hotkeys + i) - 1;
|
||||
retval++;
|
||||
}
|
||||
if (hotkeys[i])
|
||||
break;
|
||||
@ -2906,25 +2903,13 @@ copy_char (
|
||||
int lowercase /* make character lower case */
|
||||
)
|
||||
{
|
||||
int len;
|
||||
int c;
|
||||
|
||||
if (has_mbyte) {
|
||||
if (lowercase) {
|
||||
c = mb_tolower(utf_ptr2char(from));
|
||||
return (*mb_char2bytes)(c, to);
|
||||
} else {
|
||||
len = (*mb_ptr2len)(from);
|
||||
memmove(to, from, (size_t)len);
|
||||
return len;
|
||||
}
|
||||
} else {
|
||||
if (lowercase)
|
||||
*to = (char_u)TOLOWER_LOC(*from);
|
||||
else
|
||||
*to = *from;
|
||||
return 1;
|
||||
if (lowercase) {
|
||||
int c = mb_tolower(utf_ptr2char(from));
|
||||
return utf_char2bytes(c, to);
|
||||
}
|
||||
int len = utfc_ptr2len(from);
|
||||
memmove(to, from, (size_t)len);
|
||||
return len;
|
||||
}
|
||||
|
||||
#define HAS_HOTKEY_LEN 30
|
||||
|
@ -3639,18 +3639,12 @@ int do_join(size_t count,
|
||||
sumsize += currsize + spaces[t];
|
||||
endcurr1 = endcurr2 = NUL;
|
||||
if (insert_space && currsize > 0) {
|
||||
if (has_mbyte) {
|
||||
cend = curr + currsize;
|
||||
cend = curr + currsize;
|
||||
MB_PTR_BACK(curr, cend);
|
||||
endcurr1 = utf_ptr2char(cend);
|
||||
if (cend > curr) {
|
||||
MB_PTR_BACK(curr, cend);
|
||||
endcurr1 = utf_ptr2char(cend);
|
||||
if (cend > curr) {
|
||||
MB_PTR_BACK(curr, cend);
|
||||
endcurr2 = utf_ptr2char(cend);
|
||||
}
|
||||
} else {
|
||||
endcurr1 = *(curr + currsize - 1);
|
||||
if (currsize > 1)
|
||||
endcurr2 = *(curr + currsize - 2);
|
||||
endcurr2 = utf_ptr2char(cend);
|
||||
}
|
||||
}
|
||||
line_breakcheck();
|
||||
|
@ -6849,66 +6849,37 @@ int get_sts_value(void)
|
||||
*/
|
||||
void find_mps_values(int *initc, int *findc, int *backwards, int switchit)
|
||||
{
|
||||
char_u *ptr;
|
||||
char_u *ptr = curbuf->b_p_mps;
|
||||
|
||||
ptr = curbuf->b_p_mps;
|
||||
while (*ptr != NUL) {
|
||||
if (has_mbyte) {
|
||||
char_u *prev;
|
||||
|
||||
if (utf_ptr2char(ptr) == *initc) {
|
||||
if (switchit) {
|
||||
*findc = *initc;
|
||||
*initc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1);
|
||||
*backwards = true;
|
||||
} else {
|
||||
*findc = utf_ptr2char(ptr + mb_ptr2len(ptr) + 1);
|
||||
*backwards = false;
|
||||
}
|
||||
return;
|
||||
if (utf_ptr2char(ptr) == *initc) {
|
||||
if (switchit) {
|
||||
*findc = *initc;
|
||||
*initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1);
|
||||
*backwards = true;
|
||||
} else {
|
||||
*findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1);
|
||||
*backwards = false;
|
||||
}
|
||||
prev = ptr;
|
||||
ptr += mb_ptr2len(ptr) + 1;
|
||||
if (utf_ptr2char(ptr) == *initc) {
|
||||
if (switchit) {
|
||||
*findc = *initc;
|
||||
*initc = utf_ptr2char(prev);
|
||||
*backwards = false;
|
||||
} else {
|
||||
*findc = utf_ptr2char(prev);
|
||||
*backwards = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
ptr += mb_ptr2len(ptr);
|
||||
} else {
|
||||
if (*ptr == *initc) {
|
||||
if (switchit) {
|
||||
*backwards = TRUE;
|
||||
*findc = *initc;
|
||||
*initc = ptr[2];
|
||||
} else {
|
||||
*backwards = FALSE;
|
||||
*findc = ptr[2];
|
||||
}
|
||||
return;
|
||||
}
|
||||
ptr += 2;
|
||||
if (*ptr == *initc) {
|
||||
if (switchit) {
|
||||
*backwards = FALSE;
|
||||
*findc = *initc;
|
||||
*initc = ptr[-2];
|
||||
} else {
|
||||
*backwards = TRUE;
|
||||
*findc = ptr[-2];
|
||||
}
|
||||
return;
|
||||
}
|
||||
++ptr;
|
||||
return;
|
||||
}
|
||||
char_u *prev = ptr;
|
||||
ptr += utfc_ptr2len(ptr) + 1;
|
||||
if (utf_ptr2char(ptr) == *initc) {
|
||||
if (switchit) {
|
||||
*findc = *initc;
|
||||
*initc = utf_ptr2char(prev);
|
||||
*backwards = false;
|
||||
} else {
|
||||
*findc = utf_ptr2char(prev);
|
||||
*backwards = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
ptr += utfc_ptr2len(ptr);
|
||||
if (*ptr == ',') {
|
||||
ptr++;
|
||||
}
|
||||
if (*ptr == ',')
|
||||
++ptr;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1103,7 +1103,7 @@ static int get_coll_element(char_u **pp)
|
||||
char_u *p = *pp;
|
||||
|
||||
if (p[0] != NUL && p[1] == '.') {
|
||||
l = (*mb_ptr2len)(p + 2);
|
||||
l = utfc_ptr2len(p + 2);
|
||||
if (p[l + 2] == '.' && p[l + 3] == ']') {
|
||||
c = utf_ptr2char(p + 2);
|
||||
*pp += l + 4;
|
||||
@ -3444,9 +3444,7 @@ static long bt_regexec_both(char_u *line,
|
||||
|
||||
/* If there is a "must appear" string, look for it. */
|
||||
if (prog->regmust != NULL) {
|
||||
int c;
|
||||
|
||||
c = utf_ptr2char(prog->regmust);
|
||||
int c = utf_ptr2char(prog->regmust);
|
||||
s = line + col;
|
||||
|
||||
// This is used very often, esp. for ":global". Use two versions of
|
||||
@ -5441,7 +5439,7 @@ do_class:
|
||||
}
|
||||
} else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) {
|
||||
scan++;
|
||||
} else if (has_mbyte && (len = (*mb_ptr2len)(scan)) > 1) {
|
||||
} else if ((len = utfc_ptr2len(scan)) > 1) {
|
||||
if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) {
|
||||
break;
|
||||
}
|
||||
@ -6756,14 +6754,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
|
||||
// Write to buffer, if copy is set.
|
||||
if (func_one != NULL) {
|
||||
func_one = (fptr_T)(func_one(&cc, c));
|
||||
} else if (func_all != NULL) {
|
||||
func_all = (fptr_T)(func_all(&cc, c));
|
||||
} else {
|
||||
if (func_all != NULL) {
|
||||
func_all = (fptr_T)(func_all(&cc, c));
|
||||
} else {
|
||||
// just copy
|
||||
cc = c;
|
||||
}
|
||||
// just copy
|
||||
cc = c;
|
||||
}
|
||||
|
||||
if (has_mbyte) {
|
||||
int totlen = mb_ptr2len(src - 1);
|
||||
|
||||
|
@ -5030,11 +5030,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
|
||||
* Run for each character.
|
||||
*/
|
||||
for (;; ) {
|
||||
int curc;
|
||||
int clen;
|
||||
|
||||
curc = utf_ptr2char(reginput);
|
||||
clen = utfc_ptr2len(reginput);
|
||||
int curc = utf_ptr2char(reginput);
|
||||
int clen = utfc_ptr2len(reginput);
|
||||
if (curc == NUL) {
|
||||
clen = 0;
|
||||
go_to_nextline = false;
|
||||
|
@ -4297,12 +4297,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
|
||||
&& utf_iscomposing(utf_ptr2char(fword
|
||||
+ sp->ts_fcharstart))) {
|
||||
sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP;
|
||||
} else if (!soundfold && slang->sl_has_map
|
||||
&& similar_chars(slang,
|
||||
utf_ptr2char(tword + sp->ts_twordlen
|
||||
- sp->ts_tcharlen),
|
||||
utf_ptr2char(fword +
|
||||
sp->ts_fcharstart))) {
|
||||
} else if (
|
||||
!soundfold
|
||||
&& slang->sl_has_map
|
||||
&& similar_chars(
|
||||
slang,
|
||||
utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen),
|
||||
utf_ptr2char(fword + sp->ts_fcharstart))) {
|
||||
// For a similar character adjust score from
|
||||
// SCORE_SUBST to SCORE_SIMILAR.
|
||||
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
|
||||
@ -4520,21 +4521,22 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
|
||||
PROF_STORE(sp->ts_state)
|
||||
sp->ts_state = STATE_REP_INI;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// When characters are identical, swap won't do anything.
|
||||
// Also get here if the second char is not a word character.
|
||||
if (c == c2) {
|
||||
PROF_STORE(sp->ts_state)
|
||||
sp->ts_state = STATE_SWAP3;
|
||||
break;
|
||||
}
|
||||
if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) {
|
||||
go_deeper(stack, depth, SCORE_SWAP);
|
||||
// When characters are identical, swap won't do anything.
|
||||
// Also get here if the second char is not a word character.
|
||||
if (c == c2) {
|
||||
PROF_STORE(sp->ts_state)
|
||||
sp->ts_state = STATE_SWAP3;
|
||||
break;
|
||||
}
|
||||
if (c2 != NUL && TRY_DEEPER(su, stack, depth, SCORE_SWAP)) {
|
||||
go_deeper(stack, depth, SCORE_SWAP);
|
||||
#ifdef DEBUG_TRIEWALK
|
||||
sprintf(changename[depth], "%.*s-%s: swap %c and %c",
|
||||
sp->ts_twordlen, tword, fword + sp->ts_fidx,
|
||||
c, c2);
|
||||
snprintf(changename[depth], sizeof(changename[0]),
|
||||
"%.*s-%s: swap %c and %c",
|
||||
sp->ts_twordlen, tword, fword + sp->ts_fidx,
|
||||
c, c2);
|
||||
#endif
|
||||
PROF_STORE(sp->ts_state)
|
||||
sp->ts_state = STATE_UNSWAP;
|
||||
@ -4652,21 +4654,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
|
||||
sp->ts_state = STATE_UNROT3L;
|
||||
++depth;
|
||||
p = fword + sp->ts_fidx;
|
||||
if (has_mbyte) {
|
||||
n = MB_CPTR2LEN(p);
|
||||
c = utf_ptr2char(p);
|
||||
fl = MB_CPTR2LEN(p + n);
|
||||
fl += MB_CPTR2LEN(p + n + fl);
|
||||
memmove(p, p + n, fl);
|
||||
mb_char2bytes(c, p + fl);
|
||||
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
|
||||
} else {
|
||||
c = *p;
|
||||
*p = p[1];
|
||||
p[1] = p[2];
|
||||
p[2] = c;
|
||||
stack[depth].ts_fidxtry = sp->ts_fidx + 3;
|
||||
}
|
||||
n = MB_CPTR2LEN(p);
|
||||
c = utf_ptr2char(p);
|
||||
fl = MB_CPTR2LEN(p + n);
|
||||
fl += MB_CPTR2LEN(p + n + fl);
|
||||
memmove(p, p + n, fl);
|
||||
utf_char2bytes(c, p + fl);
|
||||
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
|
||||
} else {
|
||||
PROF_STORE(sp->ts_state)
|
||||
sp->ts_state = STATE_REP_INI;
|
||||
|
Loading…
Reference in New Issue
Block a user