[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Tinycc-devel] Unicode letter escape
From: |
Vincent Lefevre |
Subject: |
Re: [Tinycc-devel] Unicode letter escape |
Date: |
Fri, 5 Aug 2022 14:20:41 +0200 |
User-agent: |
Mutt/2.2.6+34 (76e93dd3) vl-149028 (2022-07-31) |
On 2022-08-05 13:32:04 +0200, Samir Ribić via Tinycc-devel wrote:
> Tcc supports \u escape sequence inside L"" but I have no idea how to
> overcome this problem:
> The code inside parse_escape_string function, in this part
>
> case 'x':
> case 'u':
> case 'U':
> p++;
> n = 0;
> for(;;) {
> c = *p;
> if (c >= 'a' && c <= 'f')
> c = c - 'a' + 10;
> else if (c >= 'A' && c <= 'F')
> c = c - 'A' + 10;
> else if (isnum(c))
> c = c - '0';
> else
> break;
> n = n * 16 + c;
> p++;
> }
[...]
Note that tccpp.c already has code that selects the right number of
digits:
case 'x': i = 0; goto parse_hex_or_ucn;
case 'u': i = 4; goto parse_hex_or_ucn;
case 'U': i = 8; goto parse_hex_or_ucn;
parse_hex_or_ucn:
p++;
n = 0;
do {
c = *p;
if (c >= 'a' && c <= 'f')
c = c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
c = c - 'A' + 10;
else if (isnum(c))
c = c - '0';
else if (i > 0)
expect("more hex digits in universal-character-name");
else {
c = n;
goto add_char_nonext;
}
n = n * 16 + c;
p++;
} while (--i);
cstr_u8cat(outstr, n);
continue;
Perhaps some code could be shared, possibly via an inline function...
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)