static int _rl_vi_change_mbchar_case(int count) { wchar_t wc; char mb[MB_LEN_MAX + 1]; int mb_len; mbstate_t ps; memset(&ps, 0, sizeof(mbstate_t)); if (_rl_adjust_point(rl_line_buffer, rl_point, &ps) > 0) count--; while (count-- && (rl_point < rl_end)) { mbrtowc(&wc, (rl_line_buffer + rl_point), (size_t)(rl_end - rl_point), &ps); if (iswupper(wc)) wc = towlower(wc); else if (iswlower(wc)) wc = towupper(wc); else { /* Just skip over chars neither upper nor lower case */ rl_forward_char(1, 0); continue; } /* Vi is kind of strange here. */ if (wc) { mb_len = wctomb(mb, wc); if (mb_len >= 0) mb[mb_len] = '\0'; rl_begin_undo_group(); rl_delete(1, 0); rl_insert_text(mb); rl_end_undo_group(); rl_vi_check(); } else rl_forward_char(1, 0); } return 0; }
int rl_vi_change_case(int count, int ignore) { char c = 0; /* Do NOT try this on an empty line: */ if (rl_point >= rl_end) return (0); #if defined(HANDLE_MULTIBYTE) if ((MB_CUR_MAX > 1) && (rl_byte_oriented == 0)) return (_rl_vi_change_mbchar_case(count)); #endif while (count-- && (rl_point < rl_end)) { if (_rl_uppercase_p(rl_line_buffer[rl_point])) c = (char)_rl_to_lower(rl_line_buffer[rl_point]); else if (_rl_lowercase_p(rl_line_buffer[rl_point])) c = (char)_rl_to_upper(rl_line_buffer[rl_point]); else { /* Just skip over characters neither upper nor lower case. */ rl_forward_char (1, c); continue; } /* Vi is kind of strange here. */ if (c) { rl_begin_undo_group (); rl_delete (1, c); _rl_insert_char (1, c); rl_end_undo_group (); rl_vi_check (); } else rl_forward_char (1, c); } return (0); }
int rl_vi_change_case (int count, int ignore) { char c = 0; /* Don't try this on an empty line. */ if (rl_point >= rl_end) return (0); while (count-- && rl_point < rl_end) { if (uppercase_p (rl_line_buffer[rl_point])) c = to_lower (rl_line_buffer[rl_point]); else if (lowercase_p (rl_line_buffer[rl_point])) c = to_upper (rl_line_buffer[rl_point]); else { /* Just skip over characters neither upper nor lower case. */ rl_forward (1, c); continue; } /* Vi is kind of strange here. */ if (c) { rl_begin_undo_group (); rl_delete (1, c); rl_insert (1, c); rl_end_undo_group (); rl_vi_check (); } else rl_forward (1, c); } return (0); }