mirror of
https://github.com/fergalmoran/ladybird.git
synced 2025-12-22 09:19:03 +00:00
LibPDF: Factorize duplicated code in Filter::decode_ascii85()
This commit is contained in:
committed by
Andreas Kling
parent
2fe0647c68
commit
59a6d4b7bc
@@ -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]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user