ops: refactor swapchar() to return bool

This commit is contained in:
Jan Edmund Lazo
2019-06-21 22:11:15 -04:00
parent 3abffe7015
commit f99e314da0

View File

@@ -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;
}
/*