aboutsummaryrefslogtreecommitdiffstats
path: root/src/coding.h
diff options
context:
space:
mode:
authorPhilipp Stephani2017-12-25 22:00:00 +0100
committerAlan Third2018-06-17 11:50:58 +0100
commit0deab3fbd8a51fc83ab7c8031f4e296a4003b055 (patch)
treec6df46e597238d00b5cee8157e4f76be36d9999d /src/coding.h
parentebe065fddf76fde64a9c07b419b67fe47fb6c1cb (diff)
downloademacs-0deab3fbd8a51fc83ab7c8031f4e296a4003b055.tar.gz
emacs-0deab3fbd8a51fc83ab7c8031f4e296a4003b055.zip
Allow inserting non-BMP characters
* src/coding.h (UTF_16_HIGH_SURROGATE_P, UTF_16_LOW_SURROGATE_P): Move from coding.c and document. (surrogates_to_codepoint): New function. * src/nsterm.m (insertText:): Properly handle surrogate pairs. (cherry picked from commit 703ac3ea1c1ce381f385469a0e88bc29d3fe83c2)
Diffstat (limited to 'src/coding.h')
-rw-r--r--src/coding.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/coding.h b/src/coding.h
index 2a87fc32e9d..502c4723149 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -662,6 +662,30 @@ struct coding_system
662/* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op. */ 662/* Note that this encodes utf-8, not utf-8-emacs, so it's not a no-op. */
663#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, true) 663#define ENCODE_UTF_8(str) code_convert_string_norecord (str, Qutf_8, true)
664 664
665/* Return true if VAL is a high surrogate. VAL must be a 16-bit code
666 unit. */
667
668#define UTF_16_HIGH_SURROGATE_P(val) \
669 (((val) & 0xFC00) == 0xD800)
670
671/* Return true if VAL is a low surrogate. VAL must be a 16-bit code
672 unit. */
673
674#define UTF_16_LOW_SURROGATE_P(val) \
675 (((val) & 0xFC00) == 0xDC00)
676
677/* Return the Unicode code point for the given UTF-16 surrogates. */
678
679INLINE int
680surrogates_to_codepoint (int low, int high)
681{
682 eassert (0 <= low && low <= 0xFFFF);
683 eassert (0 <= high && high <= 0xFFFF);
684 eassert (UTF_16_LOW_SURROGATE_P (low));
685 eassert (UTF_16_HIGH_SURROGATE_P (high));
686 return 0x10000 + (low - 0xDC00) + ((high - 0xD800) * 0x400);
687}
688
665/* Extern declarations. */ 689/* Extern declarations. */
666extern Lisp_Object code_conversion_save (bool, bool); 690extern Lisp_Object code_conversion_save (bool, bool);
667extern bool encode_coding_utf_8 (struct coding_system *); 691extern bool encode_coding_utf_8 (struct coding_system *);