diff options
author | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 2019-05-23 10:53:23 +0900 |
---|---|---|
committer | YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp> | 2019-05-23 10:53:23 +0900 |
commit | b40dde705af4d53853de6185a2468153b442dc9a (patch) | |
tree | e8dabba695163c2d07439fad6accff761f8f714c /src/coding.c | |
parent | 5d7dafacf4afc888511649f6fc24c28210cd0dfc (diff) | |
parent | 03feb9376b54c489e24478954a11061e9b0d6db7 (diff) | |
download | emacs-b40dde705af4d53853de6185a2468153b442dc9a.tar.gz emacs-b40dde705af4d53853de6185a2468153b442dc9a.tar.bz2 emacs-b40dde705af4d53853de6185a2468153b442dc9a.zip |
Merge branch 'master' into harfbuzz
Diffstat (limited to 'src/coding.c')
-rw-r--r-- | src/coding.c | 23 |
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) return check_utf_8 (&coding) != -1; } +/* Like make_string, but always returns a multibyte Lisp string, and + avoids decoding if TEXT encoded in UTF-8. */ + +Lisp_Object +make_string_from_utf8 (const char *text, ptrdiff_t nbytes) +{ + ptrdiff_t chars, bytes; + parse_str_as_multibyte ((const unsigned char *) text, nbytes, + &chars, &bytes); + /* If TEXT is a valid UTF-8 string, we can convert it to a Lisp + string directly. Otherwise, we need to decode it. */ + if (chars == nbytes || bytes == nbytes) + return make_specified_string (text, chars, nbytes, true); + else + { + struct coding_system coding; + setup_coding_system (Qutf_8_unix, &coding); + coding.mode |= CODING_MODE_LAST_BLOCK; + coding.source = (const unsigned char *) text; + decode_coding_object (&coding, Qnil, 0, 0, nbytes, nbytes, Qt); + return coding.dst_object; + } +} /* Detect how end-of-line of a text of length SRC_BYTES pointed by SOURCE is encoded. If CATEGORY is one of |