aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/character.c81
1 files changed, 46 insertions, 35 deletions
diff --git a/src/character.c b/src/character.c
index 9fa4dffc11..a296fa94b2 100644
--- a/src/character.c
+++ b/src/character.c
@@ -96,6 +96,51 @@ char unibyte_has_multibyte_table[256];
+/* If character code C has modifier masks, reflect them to the
+ character code if possible. Return the resulting code. */
+
+int
+char_resolve_modifier_mask (c)
+ int c;
+{
+ /* An non-ASCII character can't reflect modifier bits to the code. */
+ if (! ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
+ return c;
+
+ /* For Meta, Shift, and Control modifiers, we need special care. */
+ if (c & CHAR_META)
+ {
+ /* Move the meta bit to the right place for a string. */
+ c = (c & ~CHAR_META) | 0x80;
+ }
+ if (c & CHAR_SHIFT)
+ {
+ /* Shift modifier is valid only with [A-Za-z]. */
+ if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
+ c &= ~CHAR_SHIFT;
+ else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
+ c = (c & ~CHAR_SHIFT) - ('a' - 'A');
+ }
+ if (c & CHAR_CTL)
+ {
+ /* Simulate the code in lread.c. */
+ /* Allow `\C- ' and `\C-?'. */
+ if ((c & ~CHAR_CTL) == ' ')
+ c = 0;
+ else if ((c & ~CHAR_CTL) == '?')
+ c = 127;
+ /* ASCII control chars are made from letters (both cases),
+ as well as the non-letters within 0100...0137. */
+ else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
+ c &= (037 | (~0177 & ~CHAR_CTL));
+ else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
+ c &= (037 | (~0177 & ~CHAR_CTL));
+ }
+
+ return c;
+}
+
+
/* Store multibyte form of character C at P. If C has modifier bits,
handle them appropriately. */
@@ -108,41 +153,7 @@ char_string (c, p)
if (c & CHAR_MODIFIER_MASK)
{
- /* As an non-ASCII character can't have modifier bits, we just
- ignore the bits. */
- if (ASCII_CHAR_P ((c & ~CHAR_MODIFIER_MASK)))
- {
- /* For Meta, Shift, and Control modifiers, we need special care. */
- if (c & CHAR_META)
- {
- /* Move the meta bit to the right place for a string. */
- c = (c & ~CHAR_META) | 0x80;
- }
- if (c & CHAR_SHIFT)
- {
- /* Shift modifier is valid only with [A-Za-z]. */
- if ((c & 0377) >= 'A' && (c & 0377) <= 'Z')
- c &= ~CHAR_SHIFT;
- else if ((c & 0377) >= 'a' && (c & 0377) <= 'z')
- c = (c & ~CHAR_SHIFT) - ('a' - 'A');
- }
- if (c & CHAR_CTL)
- {
- /* Simulate the code in lread.c. */
- /* Allow `\C- ' and `\C-?'. */
- if (c == (CHAR_CTL | ' '))
- c = 0;
- else if (c == (CHAR_CTL | '?'))
- c = 127;
- /* ASCII control chars are made from letters (both cases),
- as well as the non-letters within 0100...0137. */
- else if ((c & 0137) >= 0101 && (c & 0137) <= 0132)
- c &= (037 | (~0177 & ~CHAR_CTL));
- else if ((c & 0177) >= 0100 && (c & 0177) <= 0137)
- c &= (037 | (~0177 & ~CHAR_CTL));
- }
- }
-
+ c = (unsigned) char_resolve_modifier_mask ((int) c);
/* If C still has any modifier bits, just ignore it. */
c &= ~CHAR_MODIFIER_MASK;
}