xiaoxiang781216 commented on code in PR #6666: URL: https://github.com/apache/incubator-nuttx/pull/6666#discussion_r927250057
########## libs/libc/wchar/lib_mbrtowc.c: ########## @@ -32,12 +32,53 @@ * Included Files ****************************************************************************/ -#include <stdlib.h> -#include <stdio.h> #include <errno.h> -#include <string.h> #include <wchar.h> +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* Implemented according to https://en.wikipedia.org/wiki/UTF-8 */ + +#define SA 0xc2u +#define SB 0xf4u + +/* Upper 6 state bits are a negative integer offset to bound-check next byte + * equivalent to: (((b) - 0x80) | ((b) + offset)) & ~0x3f + */ + +#define OOB(c, b) (((((b) >> 3) - 0x10) | \ + (((b) >> 3) + ((int32_t)(c) >> 26))) & ~7) + +/* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */ + +#define R(a, b) ((uint32_t)(((a) == 0x80 ? 0x40u - (b) : 0u - (a)) << 23)) + +#define C(x) ((x) < 2 ? -1 : (R(0x80, 0xc0) | (x))) +#define D(x) C((x) + 16) +#define E(x) (((x) == 0 ? R(0xa0, 0xc0) : \ + (x) == 0xd ? R(0x80, 0xa0) : R(0x80, 0xc0)) \ + | (R(0x80, 0xc0) >> 6) \ + | (x)) +#define F(x) (((x) >= 5 ? 0 : \ + (x) == 0 ? R(0x90, 0xc0) : \ + (x) == 4 ? R(0x80, 0x90) : R(0x80, 0xc0)) \ + | (R(0x80, 0xc0) >> 6) \ + | (R(0x80, 0xc0) >> 12) \ + | (x)) + +static const uint32_t g_bittab[] = +{ + C(0x2), C(0x3), C(0x4), C(0x5), C(0x6), C(0x7), Review Comment: @acassis @pkarashchenko the first two items don't include in the table, that's why the code put the first item in the 3rd slot. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org