[前][次][番号順一覧][スレッド一覧]

ruby-changes:70147

From: YO4 <ko1@a...>
Date: Fri, 10 Dec 2021 22:16:55 +0900 (JST)
Subject: [ruby-changes:70147] aed21d6574 (master): [ruby/reline] support input surrogate paird codepoint

https://git.ruby-lang.org/ruby.git/commit/?id=aed21d6574

From aed21d6574e1c18d64d446cf3709545aa7a608c2 Mon Sep 17 00:00:00 2001
From: YO4 <ysno@a...>
Date: Mon, 6 Dec 2021 23:01:50 +0900
Subject: [ruby/reline] support input surrogate paird codepoint

support surrogate pair input

https://github.com/ruby/reline/commit/0b4acedc6a
---
 lib/reline/windows.rb | 21 +++++++++++++++++++++
 1 file changed, 21 insertions(+)

diff --git a/lib/reline/windows.rb b/lib/reline/windows.rb
index 08ab3f26101..297713b44e4 100644
--- a/lib/reline/windows.rb
+++ b/lib/reline/windows.rb
@@ -213,8 +213,29 @@ class Reline::Windows https://github.com/ruby/ruby/blob/trunk/lib/reline/windows.rb#L213
     [ { control_keys: :SHIFT, virtual_key_code: VK_TAB }, [27, 91, 90] ],
   ]
 
+  @@hsg = nil
+
   def self.process_key_event(repeat_count, virtual_key_code, virtual_scan_code, char_code, control_key_state)
 
+    # high-surrogate
+    if char_code & 0xDC00 == 0xD800
+      @@hsg = char_code
+      return
+    end
+    # low-surrogate
+    if char_code & 0xDC00 == 0xDC00
+      if @@hsg
+        char_code = 0x10000 + (@@hsg - 0xD800) * 0x400 + char_code - 0xDC00
+        @@hsg = nil
+      else
+        # no high-surrogate. ignored.
+        return
+      end
+    else
+      # ignore high-surrogate without low-surrogate if there
+      @@hsg = nil
+    end
+
     key = KeyEventRecord.new(virtual_key_code, char_code, control_key_state)
 
     match = KEY_MAP.find { |args,| key.matches?(**args) }
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]