Rework some of the new case-modifying commands to share more code, and

also to update the autosuggestion and syntax highlighting
This commit is contained in:
ridiculousfish 2013-09-10 20:46:46 -07:00
parent cd1c2f74d3
commit b993dce12f

View file

@ -3792,37 +3792,37 @@ const wchar_t *reader_readline(void)
}
case R_UPCASE_WORD:
{
size_t pos = data->buff_pos;
move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false);
for (; pos < data->buff_pos; pos++)
data->command_line.at(pos) = towupper(data->command_line.at(pos));
reader_repaint();
break;
}
case R_DOWNCASE_WORD:
{
size_t pos = data->buff_pos;
move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false);
for (; pos < data->buff_pos; pos++)
data->command_line.at(pos) = towlower(data->command_line.at(pos));
reader_repaint();
break;
}
case R_CAPITALIZE_WORD:
{
size_t pos = data->buff_pos;
// For capitalize_word, whether we've capitalized a character so far
bool capitalized_first = false;
// We apply the operation from the current location to the end of the word
size_t pos = data->buff_pos;
move_word(MOVE_DIR_RIGHT, false, move_word_style_punctuation, false);
for (; pos < data->buff_pos; pos++) {
if (iswalnum(data->command_line.at(pos)) && !capitalized_first) {
data->command_line.at(pos) = towupper(data->command_line.at(pos));
capitalized_first = true;
} else
data->command_line.at(pos) = towlower(data->command_line.at(pos));
for (; pos < data->buff_pos; pos++)
{
wchar_t chr = data->command_line.at(pos);
// We always change the case; this decides whether we go uppercase (true) or lowercase (false)
bool make_uppercase;
if (c == R_CAPITALIZE_WORD)
make_uppercase = ! capitalized_first && iswalnum(chr);
else
make_uppercase = (c == R_UPCASE_WORD);
// Apply the operation and then record what we did
if (make_uppercase)
chr = towupper(chr);
else
chr = towlower(chr);
data->command_line.at(pos) = chr;
capitalized_first = capitalized_first || make_uppercase;
}
data->command_line_changed();
reader_super_highlight_me_plenty(data->buff_pos);
reader_repaint();
break;
}