aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.c
diff options
context:
space:
mode:
authorYAMAMOTO Mitsuharu2019-05-23 10:53:23 +0900
committerYAMAMOTO Mitsuharu2019-05-23 10:53:23 +0900
commitb40dde705af4d53853de6185a2468153b442dc9a (patch)
treee8dabba695163c2d07439fad6accff761f8f714c /src/coding.c
parent5d7dafacf4afc888511649f6fc24c28210cd0dfc (diff)
parent03feb9376b54c489e24478954a11061e9b0d6db7 (diff)
downloademacs-b40dde705af4d53853de6185a2468153b442dc9a.tar.gz
emacs-b40dde705af4d53853de6185a2468153b442dc9a.zip
Merge branch 'master' into harfbuzz
Diffstat (limited to 'src/coding.c')
-rw-r--r--src/coding.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/coding.c b/src/coding.c
index 2c6b2c4d051..9cba6494a8d 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6353,6 +6353,29 @@ 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
6359Lisp_Object
6360make_string_from_utf8 (const char *text, ptrdiff_t nbytes)
6361{
6362 ptrdiff_t chars, bytes;
6363 parse_str_as_multibyte ((const unsigned char *) text, nbytes,
6364 &chars, &bytes);
6365 /* If TEXT is a valid UTF-8 string, we can convert it to a Lisp
6366 string directly. Otherwise, we need to decode it. */
6367 if (chars == nbytes || bytes == nbytes)
6368 return make_specified_string (text, chars, nbytes, true);
6369 else
6370 {
6371 struct coding_system coding;
6372 setup_coding_system (Qutf_8_unix, &coding);
6373 coding.mode |= CODING_MODE_LAST_BLOCK;
6374 coding.source = (const unsigned char *) text;
6375 decode_coding_object (&coding, Qnil, 0, 0, nbytes, nbytes, Qt);
6376 return coding.dst_object;
6377 }
6378}
6356 6379
6357/* Detect how end-of-line of a text of length SRC_BYTES pointed by 6380/* Detect how end-of-line of a text of length SRC_BYTES pointed by
6358 SOURCE is encoded. If CATEGORY is one of 6381 SOURCE is encoded. If CATEGORY is one of