diff options
Diffstat (limited to 'src/coding.c')
| -rw-r--r-- | src/coding.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c index 2c6b2c4d051..71f687a14e3 100644 --- a/src/coding.c +++ b/src/coding.c | |||
| @@ -6353,6 +6353,25 @@ utf8_string_p (Lisp_Object string) | |||
| 6353 | return check_utf_8 (&coding) != -1; | 6353 | return check_utf_8 (&coding) != -1; |
| 6354 | } | 6354 | } |
| 6355 | 6355 | ||
| 6356 | Lisp_Object | ||
| 6357 | make_utf8_string (const char *data, ptrdiff_t size) | ||
| 6358 | { | ||
| 6359 | ptrdiff_t chars, bytes; | ||
| 6360 | parse_str_as_multibyte ((const unsigned char *) data, size, &chars, &bytes); | ||
| 6361 | /* If DATA is a valid UTF-8 string, we can convert it to a Lisp | ||
| 6362 | string directly. Otherwise, we need to decode it. */ | ||
| 6363 | if (chars == size || bytes == size) | ||
| 6364 | return make_specified_string (data, chars, size, true); | ||
| 6365 | else | ||
| 6366 | { | ||
| 6367 | struct coding_system coding; | ||
| 6368 | setup_coding_system (Qutf_8_unix, &coding); | ||
| 6369 | coding.mode |= CODING_MODE_LAST_BLOCK; | ||
| 6370 | coding.source = (const unsigned char *) data; | ||
| 6371 | decode_coding_object (&coding, Qnil, 0, 0, size, size, Qt); | ||
| 6372 | return coding.dst_object; | ||
| 6373 | } | ||
| 6374 | } | ||
| 6356 | 6375 | ||
| 6357 | /* Detect how end-of-line of a text of length SRC_BYTES pointed by | 6376 | /* Detect how end-of-line of a text of length SRC_BYTES pointed by |
| 6358 | SOURCE is encoded. If CATEGORY is one of | 6377 | SOURCE is encoded. If CATEGORY is one of |