1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 06:17:35 +00:00

LibPDF: Factorize duplicated code in Filter::decode_ascii85()

This commit is contained in:
Lucas CHOLLET 2023-11-11 17:56:40 -05:00 committed by Andreas Kling
parent 2fe0647c68
commit 59a6d4b7bc

View file

@ -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]);
} }