mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-12 04:22:28 +00:00
LibPDF: Factorize duplicated code in Filter::decode_ascii85()
This commit is contained in:
parent
2fe0647c68
commit
59a6d4b7bc
Notes:
sideshowbarker
2024-07-17 04:03:27 +09:00
Author: https://github.com/LucasChollet
Commit: 59a6d4b7bc
Pull-request: https://github.com/SerenityOS/serenity/pull/21900
Reviewed-by: https://github.com/nico ✅
1 changed files with 8 additions and 23 deletions
|
@ -114,33 +114,18 @@ PDFErrorOr<ByteBuffer> Filter::decode_ascii85(ReadonlyBytes bytes)
|
||||||
|
|
||||||
u32 number = 0;
|
u32 number = 0;
|
||||||
|
|
||||||
if (byte_index + 5 >= bytes.size()) {
|
auto const to_write = byte_index + 5 >= bytes.size() ? bytes.size() - byte_index : 5;
|
||||||
auto to_write = bytes.size() - byte_index;
|
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
auto byte = byte_index >= bytes.size() ? 'u' : bytes[byte_index++];
|
|
||||||
if (Reader::is_whitespace(byte)) {
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
number = number * 85 + byte - 33;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (size_t i = 0; i < to_write - 1; i++)
|
for (int i = 0; i < 5; i++) {
|
||||||
buffer.append(reinterpret_cast<u8*>(&number)[3 - i]);
|
auto byte = byte_index >= bytes.size() ? 'u' : bytes[byte_index++];
|
||||||
|
if (Reader::is_whitespace(byte)) {
|
||||||
break;
|
i--;
|
||||||
} else {
|
continue;
|
||||||
for (int i = 0; i < 5; i++) {
|
|
||||||
auto byte = bytes[byte_index++];
|
|
||||||
if (Reader::is_whitespace(byte)) {
|
|
||||||
i--;
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
number = number * 85 + byte - 33;
|
|
||||||
}
|
}
|
||||||
|
number = number * 85 + byte - 33;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < 4; i++)
|
for (size_t i = 0; i < to_write - 1; i++)
|
||||||
buffer.append(reinterpret_cast<u8*>(&number)[3 - i]);
|
buffer.append(reinterpret_cast<u8*>(&number)[3 - i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue