- pos_type parSize = pars_[pit].size();
-
- pos_type pos = (pit == begPit ? begPos : 0);
- right = (pit == endPit ? endPos : parSize);
-
- // process sequences of modified characters; in change
- // tracking mode, this approach results in much better
- // usability than changing case on a char-by-char basis
- docstring changes;
-
- bool capitalize = true;
-
- for (; pos < right; ++pos) {
- char_type oldChar = pars_[pit].getChar(pos);
- char_type newChar = oldChar;
-
- // ignore insets and don't play with deleted text!
- if (oldChar != Paragraph::META_INSET && !pars_[pit].isDeleted(pos)) {
- switch (action) {
- case text_lowercase:
- newChar = lowercase(oldChar);
- break;
- case text_capitalization:
- if (capitalize) {
- newChar = uppercase(oldChar);
- capitalize = false;
- }
- break;
- case text_uppercase:
- newChar = uppercase(oldChar);
- break;
- }
- }
-
- if (!pars_[pit].isLetter(pos) || pars_[pit].isDeleted(pos)) {
- capitalize = true; // permit capitalization again
- }
-
- if (oldChar != newChar) {
- changes += newChar;
- }
-
- if (oldChar == newChar || pos == right - 1) {
- if (oldChar != newChar) {
- pos++; // step behind the changing area
- }
- int erasePos = pos - changes.size();
- for (size_t i = 0; i < changes.size(); i++) {
- pars_[pit].insertChar(pos, changes[i],
- pars_[pit].getFontSettings(cur.buffer().params(),
- erasePos),
- trackChanges);
- if (!pars_[pit].eraseChar(erasePos, trackChanges)) {
- ++erasePos;
- ++pos; // advance
- ++right; // expand selection
- }
- }
- changes.clear();
- }
- }
+ Paragraph & par = pars_[pit];
+ pos_type const pos = (pit == begPit ? begPos : 0);
+ right = (pit == endPit ? endPos : par.size());
+ par.changeCase(cur.buffer().params(), pos, right, action);