From 12f1eb15ca3fed6310402847559a7c99d3c77847 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Sat, 2 Apr 2022 17:14:10 -0400 Subject: Programmatically apply new formatting to code Run this: for i in **/*.cc **/*.c **/*.h **/*.hh; do clang-format < $i >| $i.new && mv $i.new $i done --- libqpdf/Pl_RunLength.cc | 99 +++++++++++++++++++------------------------------ 1 file changed, 38 insertions(+), 61 deletions(-) (limited to 'libqpdf/Pl_RunLength.cc') diff --git a/libqpdf/Pl_RunLength.cc b/libqpdf/Pl_RunLength.cc index ed3b7576..b92e2756 100644 --- a/libqpdf/Pl_RunLength.cc +++ b/libqpdf/Pl_RunLength.cc @@ -1,7 +1,7 @@ #include -#include #include +#include Pl_RunLength::Members::Members(action_e action) : action(action), @@ -14,8 +14,8 @@ Pl_RunLength::Members::~Members() { } -Pl_RunLength::Pl_RunLength(char const* identifier, Pipeline* next, - action_e action) : +Pl_RunLength::Pl_RunLength( + char const* identifier, Pipeline* next, action_e action) : Pipeline(identifier, next), m(new Members(action)) { @@ -28,12 +28,9 @@ Pl_RunLength::~Pl_RunLength() void Pl_RunLength::write(unsigned char* data, size_t len) { - if (this->m->action == a_encode) - { + if (this->m->action == a_encode) { encode(data, len); - } - else - { + } else { decode(data, len); } } @@ -41,22 +38,20 @@ Pl_RunLength::write(unsigned char* data, size_t len) void Pl_RunLength::encode(unsigned char* data, size_t len) { - for (size_t i = 0; i < len; ++i) - { - if ((this->m->state == st_top) != (this->m->length <= 1)) - { + for (size_t i = 0; i < len; ++i) { + if ((this->m->state == st_top) != (this->m->length <= 1)) { throw std::logic_error( "Pl_RunLength::encode: state/length inconsistency"); } unsigned char ch = data[i]; if ((this->m->length > 0) && ((this->m->state == st_copying) || (this->m->length < 128)) && - (ch == this->m->buf[this->m->length-1])) - { - QTC::TC("libtests", "Pl_RunLength: switch to run", - (this->m->length == 128) ? 0 : 1); - if (this->m->state == st_copying) - { + (ch == this->m->buf[this->m->length - 1])) { + QTC::TC( + "libtests", + "Pl_RunLength: switch to run", + (this->m->length == 128) ? 0 : 1); + if (this->m->state == st_copying) { --this->m->length; flush_encode(); this->m->buf[0] = ch; @@ -65,15 +60,10 @@ Pl_RunLength::encode(unsigned char* data, size_t len) this->m->state = st_run; this->m->buf[this->m->length] = ch; ++this->m->length; - } - else - { - if ((this->m->length == 128) || (this->m->state == st_run)) - { + } else { + if ((this->m->length == 128) || (this->m->state == st_run)) { flush_encode(); - } - else if (this->m->length > 0) - { + } else if (this->m->length > 0) { this->m->state = st_copying; } this->m->buf[this->m->length] = ch; @@ -85,41 +75,33 @@ Pl_RunLength::encode(unsigned char* data, size_t len) void Pl_RunLength::decode(unsigned char* data, size_t len) { - for (size_t i = 0; i < len; ++i) - { + for (size_t i = 0; i < len; ++i) { unsigned char ch = data[i]; - switch (this->m->state) - { - case st_top: - if (ch < 128) - { + switch (this->m->state) { + case st_top: + if (ch < 128) { // length represents remaining number of bytes to copy this->m->length = 1U + ch; this->m->state = st_copying; - } - else if (ch > 128) - { + } else if (ch > 128) { // length represents number of copies of next byte this->m->length = 257U - ch; this->m->state = st_run; - } - else // ch == 128 + } else // ch == 128 { // EOD; stay in this state } break; - case st_copying: + case st_copying: this->getNext()->write(&ch, 1); - if (--this->m->length == 0) - { + if (--this->m->length == 0) { this->m->state = st_top; } break; - case st_run: - for (unsigned int j = 0; j < this->m->length; ++j) - { + case st_run: + for (unsigned int j = 0; j < this->m->length; ++j) { this->getNext()->write(&ch, 1); } this->m->state = st_top; @@ -131,30 +113,26 @@ Pl_RunLength::decode(unsigned char* data, size_t len) void Pl_RunLength::flush_encode() { - if (this->m->length == 128) - { - QTC::TC("libtests", "Pl_RunLength flush full buffer", - (this->m->state == st_copying ? 0 : - this->m->state == st_run ? 1 : - -1)); + if (this->m->length == 128) { + QTC::TC( + "libtests", + "Pl_RunLength flush full buffer", + (this->m->state == st_copying ? 0 + : this->m->state == st_run ? 1 + : -1)); } - if (this->m->length == 0) - { + if (this->m->length == 0) { QTC::TC("libtests", "Pl_RunLength flush empty buffer"); } - if (this->m->state == st_run) - { - if ((this->m->length < 2) || (this->m->length > 128)) - { + if (this->m->state == st_run) { + if ((this->m->length < 2) || (this->m->length > 128)) { throw std::logic_error( "Pl_RunLength: invalid length in flush_encode for run"); } unsigned char ch = static_cast(257 - this->m->length); this->getNext()->write(&ch, 1); this->getNext()->write(&this->m->buf[0], 1); - } - else if (this->m->length > 0) - { + } else if (this->m->length > 0) { unsigned char ch = static_cast(this->m->length - 1); this->getNext()->write(&ch, 1); this->getNext()->write(this->m->buf, this->m->length); @@ -170,8 +148,7 @@ Pl_RunLength::finish() // data, which means the stream was terminated early, but we will // just ignore this case since this is the only sensible thing to // do. - if (this->m->action == a_encode) - { + if (this->m->action == a_encode) { flush_encode(); unsigned char ch = 128; this->getNext()->write(&ch, 1); -- cgit v1.2.3-54-g00ecf