aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/coding.c b/src/coding.c
index 71f687a14e3..9cba6494a8d 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6353,22 +6353,26 @@ 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/* Like make_string, but always returns a multibyte Lisp string, and
6357 avoids decoding if TEXT encoded in UTF-8. */
6358
6356Lisp_Object 6359Lisp_Object
6357make_utf8_string (const char *data, ptrdiff_t size) 6360make_string_from_utf8 (const char *text, ptrdiff_t nbytes)
6358{ 6361{
6359 ptrdiff_t chars, bytes; 6362 ptrdiff_t chars, bytes;
6360 parse_str_as_multibyte ((const unsigned char *) data, size, &chars, &bytes); 6363 parse_str_as_multibyte ((const unsigned char *) text, nbytes,
6361 /* If DATA is a valid UTF-8 string, we can convert it to a Lisp 6364 &chars, &bytes);
6365 /* If TEXT is a valid UTF-8 string, we can convert it to a Lisp
6362 string directly. Otherwise, we need to decode it. */ 6366 string directly. Otherwise, we need to decode it. */
6363 if (chars == size || bytes == size) 6367 if (chars == nbytes || bytes == nbytes)
6364 return make_specified_string (data, chars, size, true); 6368 return make_specified_string (text, chars, nbytes, true);
6365 else 6369 else
6366 { 6370 {
6367 struct coding_system coding; 6371 struct coding_system coding;
6368 setup_coding_system (Qutf_8_unix, &coding); 6372 setup_coding_system (Qutf_8_unix, &coding);
6369 coding.mode |= CODING_MODE_LAST_BLOCK; 6373 coding.mode |= CODING_MODE_LAST_BLOCK;
6370 coding.source = (const unsigned char *) data; 6374 coding.source = (const unsigned char *) text;
6371 decode_coding_object (&coding, Qnil, 0, 0, size, size, Qt); 6375 decode_coding_object (&coding, Qnil, 0, 0, nbytes, nbytes, Qt);
6372 return coding.dst_object; 6376 return coding.dst_object;
6373 } 6377 }
6374} 6378}