aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/encode.c
diff options
context:
space:
mode:
authorZyX <kp-pav@yandex.ru>2016-02-03 21:46:01 +0300
committerZyX <kp-pav@yandex.ru>2016-04-18 02:45:49 +0300
commit5814e29cdbe370a417d654dbd18620849aa00a09 (patch)
treecb9c245c0fef3990abf0dbfc4ce986fa1303b05a /src/nvim/eval/encode.c
parentea82270d30eef2dd716cd158d989f96fbd503ba6 (diff)
downloadrneovim-5814e29cdbe370a417d654dbd18620849aa00a09.tar.gz
rneovim-5814e29cdbe370a417d654dbd18620849aa00a09.tar.bz2
rneovim-5814e29cdbe370a417d654dbd18620849aa00a09.zip
eval/decode: Fix surrogate pairs processing
Diffstat (limited to 'src/nvim/eval/encode.c')
-rw-r--r--src/nvim/eval/encode.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c
index 359c9b3de7..e44512d803 100644
--- a/src/nvim/eval/encode.c
+++ b/src/nvim/eval/encode.c
@@ -970,7 +970,7 @@ static inline int convert_to_json_string(garray_T *const gap,
default: {
if (vim_isprintc(ch)) {
ga_concat_len(gap, buf + i, shift);
- } else if (ch <= 0xFFFF) {
+ } else if (ch < SURROGATE_FIRST_CHAR) {
ga_concat_len(gap, ((const char []) {
'\\', 'u',
xdigits[(ch >> (4 * 3)) & 0xF],
@@ -979,9 +979,9 @@ static inline int convert_to_json_string(garray_T *const gap,
xdigits[(ch >> (4 * 0)) & 0xF],
}), sizeof("\\u1234") - 1);
} else {
- uint32_t tmp = (uint32_t) ch - 0x010000;
- uint16_t hi = 0xD800 + ((tmp >> 10) & 0x03FF);
- uint16_t lo = 0xDC00 + ((tmp >> 0) & 0x03FF);
+ uint32_t tmp = (uint32_t) ch - SURROGATE_FIRST_CHAR;
+ uint16_t hi = SURROGATE_HI_START + ((tmp >> 10) & ((1 << 10) - 1));
+ uint16_t lo = SURROGATE_LO_END + ((tmp >> 0) & ((1 << 10) - 1));
ga_concat_len(gap, ((const char []) {
'\\', 'u',
xdigits[(hi >> (4 * 3)) & 0xF],