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; return did_change;
} }
/* // If op_type == OP_UPPER: make uppercase,
* If op_type == OP_UPPER: make uppercase, // if op_type == OP_LOWER: make lowercase,
* if op_type == OP_LOWER: make lowercase, // if op_type == OP_ROT13: do rot13 encoding,
* if op_type == OP_ROT13: do rot13 encoding, // else swap case of character at 'pos'
* else swap case of character at 'pos' // returns true when something actually changed.
* returns TRUE when something actually changed. bool swapchar(int op_type, pos_T *pos)
*/ FUNC_ATTR_NONNULL_ARG(2)
int swapchar(int op_type, pos_T *pos)
{ {
int c; const int c = gchar_pos(pos);
int nc;
c = gchar_pos(pos); // Only do rot13 encoding for ASCII characters.
if (c >= 0x80 && op_type == OP_ROT13) {
/* Only do rot13 encoding for ASCII characters. */ return false;
if (c >= 0x80 && op_type == OP_ROT13) }
return FALSE;
if (op_type == OP_UPPER && c == 0xdf) { if (op_type == OP_UPPER && c == 0xdf) {
pos_T sp = curwin->w_cursor; pos_T sp = curwin->w_cursor;
@@ -1996,7 +1993,7 @@ int swapchar(int op_type, pos_T *pos)
inc(pos); inc(pos);
} }
nc = c; int nc = c;
if (mb_islower(c)) { if (mb_islower(c)) {
if (op_type == OP_ROT13) { if (op_type == OP_ROT13) {
nc = ROT13(c, 'a'); nc = ROT13(c, 'a');
@@ -2011,7 +2008,7 @@ int swapchar(int op_type, pos_T *pos)
} }
} }
if (nc != c) { if (nc != c) {
if (enc_utf8 && (c >= 0x80 || nc >= 0x80)) { if (c >= 0x80 || nc >= 0x80) {
pos_T sp = curwin->w_cursor; pos_T sp = curwin->w_cursor;
curwin->w_cursor = *pos; 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); del_bytes(utf_ptr2len(get_cursor_pos_ptr()), FALSE, FALSE);
ins_char(nc); ins_char(nc);
curwin->w_cursor = sp; curwin->w_cursor = sp;
} else } else {
pbyte(*pos, nc); pbyte(*pos, nc);
return TRUE; }
return true;
} }
return FALSE; return false;
} }
/* /*