mirror of
https://github.com/glfw/glfw.git
synced 2026-09-22 08:50:15 +00:00
Clean up internal Unicode code point handling
Call code points by their name and store them as uint32_t.
(cherry picked from commit fe7be39793)
This commit is contained in:
+11
-11
@@ -433,10 +433,10 @@ static char** parseUriList(char* text, int* count)
|
||||
// Based on cutef8 by Jeff Bezanson (Public Domain)
|
||||
//
|
||||
#if defined(X_HAVE_UTF8_STRING)
|
||||
static unsigned int decodeUTF8(const char** s)
|
||||
static uint32_t decodeUTF8(const char** s)
|
||||
{
|
||||
unsigned int ch = 0, count = 0;
|
||||
static const unsigned int offsets[] =
|
||||
uint32_t codepoint = 0, count = 0;
|
||||
static const uint32_t offsets[] =
|
||||
{
|
||||
0x00000000u, 0x00003080u, 0x000e2080u,
|
||||
0x03c82080u, 0xfa082080u, 0x82082080u
|
||||
@@ -444,13 +444,13 @@ static unsigned int decodeUTF8(const char** s)
|
||||
|
||||
do
|
||||
{
|
||||
ch = (ch << 6) + (unsigned char) **s;
|
||||
codepoint = (codepoint << 6) + (unsigned char) **s;
|
||||
(*s)++;
|
||||
count++;
|
||||
} while ((**s & 0xc0) == 0x80);
|
||||
|
||||
assert(count <= 6);
|
||||
return ch - offsets[count - 1];
|
||||
return codepoint - offsets[count - 1];
|
||||
}
|
||||
#endif /*X_HAVE_UTF8_STRING*/
|
||||
|
||||
@@ -1328,9 +1328,9 @@ static void processEvent(XEvent *event)
|
||||
|
||||
_glfwInputKey(window, key, keycode, GLFW_PRESS, mods);
|
||||
|
||||
const long character = _glfwKeySym2Unicode(keysym);
|
||||
if (character != -1)
|
||||
_glfwInputChar(window, character, mods, plain);
|
||||
const uint32_t codepoint = _glfwKeySym2Unicode(keysym);
|
||||
if (codepoint != GLFW_INVALID_CODEPOINT)
|
||||
_glfwInputChar(window, codepoint, mods, plain);
|
||||
}
|
||||
|
||||
return;
|
||||
@@ -2871,11 +2871,11 @@ const char* _glfwPlatformGetScancodeName(int scancode)
|
||||
if (keysym == NoSymbol)
|
||||
return NULL;
|
||||
|
||||
const long ch = _glfwKeySym2Unicode(keysym);
|
||||
if (ch == -1)
|
||||
const uint32_t codepoint = _glfwKeySym2Unicode(keysym);
|
||||
if (codepoint == GLFW_INVALID_CODEPOINT)
|
||||
return NULL;
|
||||
|
||||
const size_t count = _glfwEncodeUTF8(_glfw.x11.keynames[key], (unsigned int) ch);
|
||||
const size_t count = _glfwEncodeUTF8(_glfw.x11.keynames[key], codepoint);
|
||||
if (count == 0)
|
||||
return NULL;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user