summary refs log tree commit diff
path: root/quantum/process_keycode/process_unicode_common.c
diff options
context:
space:
mode:
authorNick Brassel <nick@tzarc.org>2022-05-29 07:57:11 +1000
committerNick Brassel <nick@tzarc.org>2022-05-29 07:57:11 +1000
commitb835171008eaeaa992a1b8e390af8bce6f5f0b8f (patch)
treede22c239cc47556f8be7538f95f48ad75b86d110 /quantum/process_keycode/process_unicode_common.c
parentf5d091a9d58c8349437e9d52de87294258cbd256 (diff)
parent0c8f78020d01ee5c45481d7d93b9b0d9f7b95103 (diff)
Merge branch 'develop' -- breaking changes 2022-05-28.
Diffstat (limited to 'quantum/process_keycode/process_unicode_common.c')
-rw-r--r--quantum/process_keycode/process_unicode_common.c63
1 files changed, 1 insertions, 62 deletions
diff --git a/quantum/process_keycode/process_unicode_common.c b/quantum/process_keycode/process_unicode_common.c
index 46b77e14ba..652becbc9a 100644
--- a/quantum/process_keycode/process_unicode_common.c
+++ b/quantum/process_keycode/process_unicode_common.c
@@ -16,8 +16,7 @@
 
 #include "process_unicode_common.h"
 #include "eeprom.h"
-#include <ctype.h>
-#include <string.h>
+#include "utf8.h"
 
 unicode_config_t unicode_config;
 uint8_t          unicode_saved_mods;
@@ -231,66 +230,6 @@ void register_unicode(uint32_t code_point) {
     unicode_input_finish();
 }
 
-// clang-format off
-
-void send_unicode_hex_string(const char *str) {
-    if (!str) {
-        return;
-    }
-
-    while (*str) {
-        // Find the next code point (token) in the string
-        for (; *str == ' '; str++);    // Skip leading spaces
-        size_t n = strcspn(str, " ");  // Length of the current token
-        char code_point[n+1];
-        strncpy(code_point, str, n);   // Copy token into buffer
-        code_point[n] = '\0';          // Make sure it's null-terminated
-
-        // Normalize the code point: make all hex digits lowercase
-        for (char *p = code_point; *p; p++) {
-            *p = tolower((unsigned char)*p);
-        }
-
-        // Send the code point as a Unicode input string
-        unicode_input_start();
-        send_string(code_point);
-        unicode_input_finish();
-
-        str += n;  // Move to the first ' ' (or '\0') after the current token
-    }
-}
-
-// clang-format on
-
-// Borrowed from https://nullprogram.com/blog/2017/10/06/
-static const char *decode_utf8(const char *str, int32_t *code_point) {
-    const char *next;
-
-    if (str[0] < 0x80) { // U+0000-007F
-        *code_point = str[0];
-        next        = str + 1;
-    } else if ((str[0] & 0xE0) == 0xC0) { // U+0080-07FF
-        *code_point = ((int32_t)(str[0] & 0x1F) << 6) | ((int32_t)(str[1] & 0x3F) << 0);
-        next        = str + 2;
-    } else if ((str[0] & 0xF0) == 0xE0) { // U+0800-FFFF
-        *code_point = ((int32_t)(str[0] & 0x0F) << 12) | ((int32_t)(str[1] & 0x3F) << 6) | ((int32_t)(str[2] & 0x3F) << 0);
-        next        = str + 3;
-    } else if ((str[0] & 0xF8) == 0xF0 && (str[0] <= 0xF4)) { // U+10000-10FFFF
-        *code_point = ((int32_t)(str[0] & 0x07) << 18) | ((int32_t)(str[1] & 0x3F) << 12) | ((int32_t)(str[2] & 0x3F) << 6) | ((int32_t)(str[3] & 0x3F) << 0);
-        next        = str + 4;
-    } else {
-        *code_point = -1;
-        next        = str + 1;
-    }
-
-    // part of a UTF-16 surrogate pair - invalid
-    if (*code_point >= 0xD800 && *code_point <= 0xDFFF) {
-        *code_point = -1;
-    }
-
-    return next;
-}
-
 void send_unicode_string(const char *str) {
     if (!str) {
         return;