aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKenichi Handa2013-08-20 17:56:03 +0300
committerEli Zaretskii2013-08-20 17:56:03 +0300
commit3f246b657225c786c460b22d774ab0b2e7488b55 (patch)
treee2cc742e357b2d21e23a05cbb97d37a1fce1e0e9 /src
parent9f0809d4ab26a4376ecce03909d35db80da40023 (diff)
downloademacs-3f246b657225c786c460b22d774ab0b2e7488b55.tar.gz
emacs-3f246b657225c786c460b22d774ab0b2e7488b55.zip
src/character.c (string_char): Improve commentary.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog4
-rw-r--r--src/character.c14
2 files changed, 16 insertions, 2 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index e21d82bdc09..997459f01c2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,7 @@
12013-08-20 Kenichi Handa <handa@gnu.org>
2
3 * character.c (string_char): Improve commentary.
4
12013-08-20 Paul Eggert <eggert@cs.ucla.edu> 52013-08-20 Paul Eggert <eggert@cs.ucla.edu>
2 6
3 * image.c (SIGNATURE_DIGESTSIZE): Remove. 7 * image.c (SIGNATURE_DIGESTSIZE): Remove.
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)
174 174
175 if (*p < 0x80 || ! (*p & 0x20) || ! (*p & 0x10)) 175 if (*p < 0x80 || ! (*p & 0x20) || ! (*p & 0x10))
176 { 176 {
177 /* 1-, 2-, and 3-byte sequences can be handled by the macro. */
177 c = STRING_CHAR_ADVANCE (p); 178 c = STRING_CHAR_ADVANCE (p);
178 } 179 }
179 else if (! (*p & 0x08)) 180 else if (! (*p & 0x08))
180 { 181 {
181 c = ((((p)[0] & 0xF) << 18) 182 /* A 4-byte sequence of this form:
183 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
184 c = ((((p)[0] & 0x7) << 18)
182 | (((p)[1] & 0x3F) << 12) 185 | (((p)[1] & 0x3F) << 12)
183 | (((p)[2] & 0x3F) << 6) 186 | (((p)[2] & 0x3F) << 6)
184 | ((p)[3] & 0x3F)); 187 | ((p)[3] & 0x3F));
@@ -186,7 +189,14 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len)
186 } 189 }
187 else 190 else
188 { 191 {
189 c = ((((p)[1] & 0x3F) << 18) 192 /* A 5-byte sequence of this form:
193
194 111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
195
196 Note that the top 4 `x's are always 0, so shifting p[1] can
197 never exceed the maximum valid character codepoint. */
198 c = (/* (((p)[0] & 0x3) << 24) ... always 0, so no need to shift. */
199 (((p)[1] & 0x3F) << 18)
190 | (((p)[2] & 0x3F) << 12) 200 | (((p)[2] & 0x3F) << 12)
191 | (((p)[3] & 0x3F) << 6) 201 | (((p)[3] & 0x3F) << 6)
192 | ((p)[4] & 0x3F)); 202 | ((p)[4] & 0x3F));