From edbc878b73dc582887213ffb24d2dedaa3ab95c4 Mon Sep 17 00:00:00 2001 From: Redkale <8730487+redkale@users.noreply.github.com> Date: Thu, 19 Sep 2019 21:22:47 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8DUtility.encodeUTF8Length?= =?UTF-8?q?=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/org/redkale/util/Utility.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/org/redkale/util/Utility.java b/src/org/redkale/util/Utility.java index 549a9477e..405cbe9de 100644 --- a/src/org/redkale/util/Utility.java +++ b/src/org/redkale/util/Utility.java @@ -1924,7 +1924,15 @@ public final class Utility { final int limit = start + len; for (int i = start; i < limit; i++) { c = chars[i]; - size += (c < 0x80 ? 1 : (c < 0x800 ? 2 : 3)); + if (c < 0x80) { + size++; + } else if (c < 0x800) { + size += 2; + } else if (Character.isSurrogate(c)) { + size += 2; + } else { + size += 3; + } } return size; }