1
1
mirror of https://github.com/wader/fq.git synced 2024-11-26 21:55:57 +03:00

Merge pull request #767 from wader/binary-split-correct-len

interp: split: Correctly split binary
This commit is contained in:
Mattias Wadman 2023-09-24 20:05:28 +02:00 committed by GitHub
commit 5058d23db1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 14 deletions

View File

@ -36,13 +36,13 @@ def _splits_binary($regex; $flags):
( . as $b
# last null output is to do a last iteration that output from end of last match to end of binary
| foreach (_match_binary($regex; $flags), null) as $m (
{prev: null, curr: null};
( .prev = .curr
| .curr = $m
{prev: null, current: null};
( .prev = .current
| .current = $m
);
if .prev == null then $b[0:.curr.offset]
elif .curr == null then $b[.prev.offset+.prev.length:]
else $b[.prev.offset+.prev.length:.curr.offset+.curr.length]
if .prev == null then $b[0:.current.offset]
elif .current == null then $b[.prev.offset+.prev.length:]
else $b[.prev.offset+.prev.length:.current.offset]
end
)
);

View File

@ -414,13 +414,13 @@ null> "ååå" as $p | "cbbcåååccåååcbc", "åååcbbc", "cbbcååå" | .,
"binary_rune"
[
"cbbc",
"ccååå",
"cc",
"cbc"
]
"binary_byte"
[
"cbbc",
"ccååå",
"cc",
"cbc"
]
"åååcbbc"
@ -465,16 +465,14 @@ null> "å(?<n>å)(å)" as $p | "cbbcåååccåååcbc", "åååcbbc", "cbbcåå
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|63 62 62 63 |cbbc |.: raw bits 0x0-0x3.7 (4)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x00| 63 63 c3 a5 c3 a5| cc....|.: raw bits 0xa-0x11.7 (8)
0x10|c3 a5 |.. |
0x0| 63 63 | cc |.: raw bits 0xa-0xb.7 (2)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x10| 63 62 63| | cbc| |.: raw bits 0x12-0x14.7 (3)
"binary_byte"
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x0|63 62 62 63 |cbbc |.: raw bits 0x0-0x3.7 (4)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x00| 63 63 c3 a5 c3 a5| cc....|.: raw bits 0xa-0x11.7 (8)
0x10|c3 a5 |.. |
0x0| 63 63 | cc |.: raw bits 0xa-0xb.7 (2)
|00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f|0123456789abcdef|
0x10| 63 62 63| | cbc| |.: raw bits 0x12-0x14.7 (3)
"åååcbbc"