diff options
author | Kenichi Handa <handa@gnu.org> | 2013-08-20 17:56:03 +0300 |
---|---|---|
committer | Eli Zaretskii <eliz@gnu.org> | 2013-08-20 17:56:03 +0300 |
commit | 3f246b657225c786c460b22d774ab0b2e7488b55 (patch) | |
tree | e2cc742e357b2d21e23a05cbb97d37a1fce1e0e9 /src/character.c | |
parent | 9f0809d4ab26a4376ecce03909d35db80da40023 (diff) | |
download | emacs-3f246b657225c786c460b22d774ab0b2e7488b55.tar.gz |
src/character.c (string_char): Improve commentary.
Diffstat (limited to 'src/character.c')
-rw-r--r-- | src/character.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/src/character.c b/src/character.c index b2caaa290af..1bde2364e37 100644 --- a/src/character.c +++ b/src/character.c @@ -174,11 +174,14 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len) if (*p < 0x80 || ! (*p & 0x20) || ! (*p & 0x10)) { + /* 1-, 2-, and 3-byte sequences can be handled by the macro. */ c = STRING_CHAR_ADVANCE (p); } else if (! (*p & 0x08)) { - c = ((((p)[0] & 0xF) << 18) + /* A 4-byte sequence of this form: + 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */ + c = ((((p)[0] & 0x7) << 18) | (((p)[1] & 0x3F) << 12) | (((p)[2] & 0x3F) << 6) | ((p)[3] & 0x3F)); @@ -186,7 +189,14 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len) } else { - c = ((((p)[1] & 0x3F) << 18) + /* A 5-byte sequence of this form: + + 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx + + Note that the top 4 `x's are always 0, so shifting p[1] can + never exceed the maximum valid character codepoint. */ + c = (/* (((p)[0] & 0x3) << 24) ... always 0, so no need to shift. */ + (((p)[1] & 0x3F) << 18) | (((p)[2] & 0x3F) << 12) | (((p)[3] & 0x3F) << 6) | ((p)[4] & 0x3F)); |