mirror of
https://github.com/neovim/neovim.git
synced 2025-09-06 19:38:20 +00:00
ops: refactor swapchar() to return bool
This commit is contained in:
@@ -1966,23 +1966,20 @@ static int swapchars(int op_type, pos_T *pos, int length)
|
||||
return did_change;
|
||||
}
|
||||
|
||||
/*
|
||||
* If op_type == OP_UPPER: make uppercase,
|
||||
* if op_type == OP_LOWER: make lowercase,
|
||||
* if op_type == OP_ROT13: do rot13 encoding,
|
||||
* else swap case of character at 'pos'
|
||||
* returns TRUE when something actually changed.
|
||||
*/
|
||||
int swapchar(int op_type, pos_T *pos)
|
||||
// If op_type == OP_UPPER: make uppercase,
|
||||
// if op_type == OP_LOWER: make lowercase,
|
||||
// if op_type == OP_ROT13: do rot13 encoding,
|
||||
// else swap case of character at 'pos'
|
||||
// returns true when something actually changed.
|
||||
bool swapchar(int op_type, pos_T *pos)
|
||||
FUNC_ATTR_NONNULL_ARG(2)
|
||||
{
|
||||
int c;
|
||||
int nc;
|
||||
const int c = gchar_pos(pos);
|
||||
|
||||
c = gchar_pos(pos);
|
||||
|
||||
/* Only do rot13 encoding for ASCII characters. */
|
||||
if (c >= 0x80 && op_type == OP_ROT13)
|
||||
return FALSE;
|
||||
// Only do rot13 encoding for ASCII characters.
|
||||
if (c >= 0x80 && op_type == OP_ROT13) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (op_type == OP_UPPER && c == 0xdf) {
|
||||
pos_T sp = curwin->w_cursor;
|
||||
@@ -1996,7 +1993,7 @@ int swapchar(int op_type, pos_T *pos)
|
||||
inc(pos);
|
||||
}
|
||||
|
||||
nc = c;
|
||||
int nc = c;
|
||||
if (mb_islower(c)) {
|
||||
if (op_type == OP_ROT13) {
|
||||
nc = ROT13(c, 'a');
|
||||
@@ -2011,7 +2008,7 @@ int swapchar(int op_type, pos_T *pos)
|
||||
}
|
||||
}
|
||||
if (nc != c) {
|
||||
if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) {
|
||||
if (c >= 0x80 || nc >= 0x80) {
|
||||
pos_T sp = curwin->w_cursor;
|
||||
|
||||
curwin->w_cursor = *pos;
|
||||
@@ -2019,11 +2016,12 @@ int swapchar(int op_type, pos_T *pos)
|
||||
del_bytes(utf_ptr2len(get_cursor_pos_ptr()), FALSE, FALSE);
|
||||
ins_char(nc);
|
||||
curwin->w_cursor = sp;
|
||||
} else
|
||||
} else {
|
||||
pbyte(*pos, nc);
|
||||
return TRUE;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return FALSE;
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
|
Reference in New Issue
Block a user