+ inword = SYNTAX (c) == Sword && (inword || !SYNTAX_PREFIX (c));
+ }
+ if (i < end_byte)
+ {
+ /* The work is not yet finished because of a multibyte character
+ just encountered. */
+ int opoint = PT;
+ int opoint_byte = PT_BYTE;
+ int c2;
+
+ while (start < end)
+ {
+ if ((c = FETCH_BYTE (i)) >= 0x80)
+ c = FETCH_MULTIBYTE_CHAR (i);
+ c2 = c;
+ if (inword && flag != CASE_CAPITALIZE_UP)
+ c2 = DOWNCASE (c);
+ else if (!UPPERCASEP (c)
+ && (!inword || flag != CASE_CAPITALIZE_UP))
+ c2 = UPCASE1 (c);
+ if (c != c2)
+ {
+ int fromlen, tolen, j;
+ unsigned char str[MAX_MULTIBYTE_LENGTH];
+
+ changed = 1;
+ /* Handle the most likely case */
+ if (c < 0400 && c2 < 0400)
+ FETCH_BYTE (i) = c2;
+ else if (fromlen = CHAR_STRING (c, str),
+ tolen = CHAR_STRING (c2, str),
+ fromlen == tolen)
+ {
+ /* Length is unchanged. */
+ for (j = 0; j < tolen; ++j)
+ FETCH_BYTE (i + j) = str[j];
+ }
+ else
+ {
+ /* Replace one character with the other,
+ keeping text properties the same. */
+ replace_range_2 (start, i,
+ start + 1, i + fromlen,
+ str, 1, tolen,
+ 1);
+ if (opoint > start)
+ opoint_byte += tolen - fromlen;
+ }
+ }
+ if ((int) flag >= (int) CASE_CAPITALIZE)
+ inword = SYNTAX (c2) == Sword;
+ INC_BOTH (start, i);
+ }
+ TEMP_SET_PT_BOTH (opoint, opoint_byte);