diff options
author | Alexander Zubkov <green@qrator.net> | 2023-06-23 16:47:37 +0200 |
---|---|---|
committer | Ondrej Zajicek <santiago@crfreenet.org> | 2023-06-23 16:47:37 +0200 |
commit | 65d6a525944faa3f77041419991d77106d8f0a0d (patch) | |
tree | e55c7bae74a6b980c961b7c65479e97d1fb65a96 /conf | |
parent | 5f2ecb2298a6fe4b2fcd9efc0b39c36202496c2c (diff) |
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.
Diffstat (limited to 'conf')
-rw-r--r-- | conf/cf-lex.l | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/conf/cf-lex.l b/conf/cf-lex.l index 9555949d..9025a84d 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -255,12 +255,17 @@ WHITE [ \t] return IP4; } -{XIGIT}{2}((:{XIGIT}{2}){15,}|({XIGIT}{2}){15,}) { - char *s = yytext; +({XIGIT}{2}){16,}|{XIGIT}{2}(:{XIGIT}{2}){15,}|hex:({XIGIT}{2}(:?{XIGIT}{2})*)? { + char *s, *sb = yytext; size_t len = 0, i; struct bytestring *bytes; byte *b; + /* skip 'hex:' prefix */ + if (sb[0] == 'h' && sb[1] == 'e' && sb[2] == 'x' && sb[3] == ':') + sb += 4; + + s = sb; while (*s) { len++; s += 2; @@ -271,7 +276,7 @@ WHITE [ \t] bytes->length = len; b = &bytes->data[0]; - s = yytext; + s = sb; errno = 0; for (i = 0; i < len; i++) { *b = bstrtobyte16(s); |