diff options
| author | Kenichi Handa | 1997-11-08 03:05:44 +0000 |
|---|---|---|
| committer | Kenichi Handa | 1997-11-08 03:05:44 +0000 |
| commit | f1c54f1aed01aa8a6247be58f8a21e0d92aa714e (patch) | |
| tree | e6b6677a98e294970b26389df2e4bdfd45903682 /src | |
| parent | 733eafd8ed4bb3f97193f26e855ed4bf40bc9c23 (diff) | |
| download | emacs-f1c54f1aed01aa8a6247be58f8a21e0d92aa714e.tar.gz emacs-f1c54f1aed01aa8a6247be58f8a21e0d92aa714e.zip | |
(Fsref): If IDX points an 8-bit code which is not part
of multibyte characters, return it. Pay attention to
enable-multibyte-characters.
Diffstat (limited to 'src')
| -rw-r--r-- | src/editfns.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/src/editfns.c b/src/editfns.c index 13df66854a4..8287e9ccca3 100644 --- a/src/editfns.c +++ b/src/editfns.c | |||
| @@ -158,8 +158,8 @@ INDEX not pointing at character boundary is an error.") | |||
| 158 | (str, idx) | 158 | (str, idx) |
| 159 | Lisp_Object str, idx; | 159 | Lisp_Object str, idx; |
| 160 | { | 160 | { |
| 161 | register int idxval, len; | 161 | register int idxval, len, i; |
| 162 | register unsigned char *p; | 162 | register unsigned char *p, *q; |
| 163 | register Lisp_Object val; | 163 | register Lisp_Object val; |
| 164 | 164 | ||
| 165 | CHECK_STRING (str, 0); | 165 | CHECK_STRING (str, 0); |
| @@ -167,9 +167,25 @@ INDEX not pointing at character boundary is an error.") | |||
| 167 | idxval = XINT (idx); | 167 | idxval = XINT (idx); |
| 168 | if (idxval < 0 || idxval >= (len = XVECTOR (str)->size)) | 168 | if (idxval < 0 || idxval >= (len = XVECTOR (str)->size)) |
| 169 | args_out_of_range (str, idx); | 169 | args_out_of_range (str, idx); |
| 170 | |||
| 170 | p = XSTRING (str)->data + idxval; | 171 | p = XSTRING (str)->data + idxval; |
| 171 | if (!CHAR_HEAD_P (p)) | 172 | if (!NILP (current_buffer->enable_multibyte_characters) |
| 172 | error ("Not character boundary"); | 173 | && !CHAR_HEAD_P (p) |
| 174 | && idxval > 0) | ||
| 175 | { | ||
| 176 | /* We must check if P points to a tailing byte of a multibyte | ||
| 177 | form. If so, we signal error. */ | ||
| 178 | i = idxval - 1; | ||
| 179 | q = p - 1; | ||
| 180 | while (i > 0 && *q >= 0xA0) i--, q--; | ||
| 181 | |||
| 182 | if (*q == LEADING_CODE_COMPOSITION) | ||
| 183 | i = multibyte_form_length (XSTRING (str)->data + i, len - i); | ||
| 184 | else | ||
| 185 | i = BYTES_BY_CHAR_HEAD (*q); | ||
| 186 | if (q + i > p) | ||
| 187 | error ("Not character boundary"); | ||
| 188 | } | ||
| 173 | 189 | ||
| 174 | len = XSTRING (str)->size - idxval; | 190 | len = XSTRING (str)->size - idxval; |
| 175 | XSETFASTINT (val, STRING_CHAR (p, len)); | 191 | XSETFASTINT (val, STRING_CHAR (p, len)); |