Add send_unicode_hex_string function (#3828)
* Add send_string_unicode function Co-authored-by: kdb424 <kdb424@gmail.com> Co-authored-by: Konstantin <vomindoraan@gmail.com> * Clean up code based on feedback * Fix includes
This commit is contained in:
		
				
					committed by
					
						
						Jack Humbert
					
				
			
			
				
	
			
			
			
						parent
						
							26f4e7031a
						
					
				
				
					commit
					f5ae3760c6
				
			@@ -16,6 +16,8 @@
 | 
			
		||||
 | 
			
		||||
#include "process_unicode_common.h"
 | 
			
		||||
#include "eeprom.h"
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include <ctype.h>
 | 
			
		||||
 | 
			
		||||
static uint8_t input_mode;
 | 
			
		||||
uint8_t mods;
 | 
			
		||||
@@ -120,3 +122,29 @@ void register_hex(uint16_t hex) {
 | 
			
		||||
    unregister_code(hex_to_keycode(digit));
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void send_unicode_hex_string(const char *str)
 | 
			
		||||
{
 | 
			
		||||
  if (!str) { return; } // Safety net
 | 
			
		||||
 | 
			
		||||
  while (*str) {
 | 
			
		||||
    // Find the next code point (token) in the string
 | 
			
		||||
    for (; *str == ' '; str++);
 | 
			
		||||
    size_t n = strcspn(str, " "); // Length of the current token
 | 
			
		||||
    char code_point[n+1];
 | 
			
		||||
    strncpy(code_point, str, n);
 | 
			
		||||
    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
 | 
			
		||||
  }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -31,6 +31,7 @@ uint8_t get_unicode_input_mode(void);
 | 
			
		||||
void unicode_input_start(void);
 | 
			
		||||
void unicode_input_finish(void);
 | 
			
		||||
void register_hex(uint16_t hex);
 | 
			
		||||
void send_unicode_hex_string(const char *str);
 | 
			
		||||
 | 
			
		||||
#define UC_OSX 0  // Mac OS X
 | 
			
		||||
#define UC_LNX 1  // Linux
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user