Skip to content

Commit

Permalink
wgetch( ) can now return SMP (Unicode past 64K) characters on Windows…
Browse files Browse the repository at this point in the history
…, using surrogate pairs
  • Loading branch information
Bill-Gray committed May 9, 2023
1 parent 6b432b4 commit 2050706
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions pdcurses/getch.c
Original file line number Diff line number Diff line change
Expand Up @@ -467,11 +467,11 @@ bool PDC_is_function_key( const int key)

#define WAIT_FOREVER -1

static int _raw_wgetch(WINDOW *win)
static int _raw_wgetch_no_surrogate_pairs( WINDOW *win)
{
int key = ERR, remaining_millisecs;

PDC_LOG(("_raw_wgetch() - called\n"));
PDC_LOG(("_raw_wgetch_no_surrogate_pairs() - called\n"));

assert( SP);
assert( win);
Expand Down Expand Up @@ -629,6 +629,23 @@ static int _raw_wgetch(WINDOW *win)
}
}

#define IS_HIGH_SURROGATE( x) ((x) >= 0xd800 && (x) < 0xdc00)
#define IS_LOW_SURROGATE( x) ((x) >= 0xdc00 && (x) < 0xe000)

static int _raw_wgetch( WINDOW *win)
{
int rval = _raw_wgetch_no_surrogate_pairs( win);

if( IS_HIGH_SURROGATE( rval))
{
const int c = _raw_wgetch_no_surrogate_pairs( win);

if( IS_LOW_SURROGATE( c))
rval = ((rval - 0xd800) << 10) + 0x10000 + c - 0xdc00;
}
return( rval);
}

int mvgetch(int y, int x)
{
PDC_LOG(("mvgetch() - called\n"));
Expand Down

0 comments on commit 2050706

Please sign in to comment.