0
0
mirror of https://gitlab.nic.cz/labs/bird.git synced 2024-11-09 12:48:43 +00:00

Add hex:XYZ syntax for short hex strings

Hexadecimal bytestring literals have minimal length to not collide
with IP addresses or regular (hexadecimal) number literals.

Allow to use shorter literals with explicit hex: prefix.
This commit is contained in:
Alexander Zubkov 2023-06-23 16:47:37 +02:00 committed by Ondrej Zajicek
parent 5f2ecb2298
commit 65d6a52594

View File

@ -255,12 +255,17 @@ WHITE [ \t]
return IP4; return IP4;
} }
{XIGIT}{2}((:{XIGIT}{2}){15,}|({XIGIT}{2}){15,}) { ({XIGIT}{2}){16,}|{XIGIT}{2}(:{XIGIT}{2}){15,}|hex:({XIGIT}{2}(:?{XIGIT}{2})*)? {
char *s = yytext; char *s, *sb = yytext;
size_t len = 0, i; size_t len = 0, i;
struct bytestring *bytes; struct bytestring *bytes;
byte *b; byte *b;
/* skip 'hex:' prefix */
if (sb[0] == 'h' && sb[1] == 'e' && sb[2] == 'x' && sb[3] == ':')
sb += 4;
s = sb;
while (*s) { while (*s) {
len++; len++;
s += 2; s += 2;
@ -271,7 +276,7 @@ WHITE [ \t]
bytes->length = len; bytes->length = len;
b = &bytes->data[0]; b = &bytes->data[0];
s = yytext; s = sb;
errno = 0; errno = 0;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
*b = bstrtobyte16(s); *b = bstrtobyte16(s);