diff options
author | Rickard Green <[email protected]> | 2017-08-23 14:25:42 +0200 |
---|---|---|
committer | Rickard Green <[email protected]> | 2017-08-23 14:25:42 +0200 |
commit | d50bc5031eb0889c894bf20f5206cfc06162f30a (patch) | |
tree | b8a335a5e72f26a3a93b92d8d7b473a6d16cf931 /erts/emulator/beam/utils.c | |
parent | 26416b5430795f3a27913931afbb7ef1dc51d4bd (diff) | |
parent | 319eefea3b2097b543751c63cebbb4a92011dbbf (diff) | |
download | otp-d50bc5031eb0889c894bf20f5206cfc06162f30a.tar.gz otp-d50bc5031eb0889c894bf20f5206cfc06162f30a.tar.bz2 otp-d50bc5031eb0889c894bf20f5206cfc06162f30a.zip |
Merge branch 'rickard/unicode-display_string/OTP-14545' into maint
* rickard/unicode-display_string/OTP-14545:
Unicode support for erlang:display_string/1
Diffstat (limited to 'erts/emulator/beam/utils.c')
-rw-r--r-- | erts/emulator/beam/utils.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/erts/emulator/beam/utils.c b/erts/emulator/beam/utils.c index cb8d93549c..bab7352479 100644 --- a/erts/emulator/beam/utils.c +++ b/erts/emulator/beam/utils.c @@ -3705,6 +3705,52 @@ erts_unicode_list_to_buf(Eterm list, byte *buf, Sint len, Sint* written) return res; } +Sint +erts_unicode_list_to_buf_len(Eterm list) +{ + Eterm* listptr; + Sint sz = 0; + + if (is_nil(list)) { + return 0; + } + if (is_not_list(list)) { + return -1; + } + listptr = list_val(list); + + while (1) { + Sint val; + + if (is_not_small(CAR(listptr))) { + return -1; + } + val = signed_val(CAR(listptr)); + if (0 <= val && val < 0x80) { + sz++; + } else if (val < 0x800) { + sz += 2; + } else if (val < 0x10000UL) { + if (0xD800 <= val && val <= 0xDFFF) { + return -1; + } + sz += 3; + } else if (val < 0x110000) { + sz += 4; + } else { + return -1; + } + list = CDR(listptr); + if (is_nil(list)) { + return sz; + } + if (is_not_list(list)) { + return -1; + } + listptr = list_val(list); + } +} + /* ** Convert an integer to a byte list ** return pointer to converted stuff (need not to be at start of buf!) |