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/BufferInputSource.cc | 66 +++++++++++++++++--------------------------- 1 file changed, 26 insertions(+), 40 deletions(-) (limited to 'libqpdf/BufferInputSource.cc') diff --git a/libqpdf/BufferInputSource.cc b/libqpdf/BufferInputSource.cc index 66b34f54..25e0d7c1 100644 --- a/libqpdf/BufferInputSource.cc +++ b/libqpdf/BufferInputSource.cc @@ -1,15 +1,14 @@ #include #include -#include -#include #include #include #include +#include +#include -BufferInputSource::Members::Members(bool own_memory, - std::string const& description, - Buffer* buf) : +BufferInputSource::Members::Members( + bool own_memory, std::string const& description, Buffer* buf) : own_memory(own_memory), description(description), buf(buf), @@ -22,14 +21,14 @@ BufferInputSource::Members::~Members() { } -BufferInputSource::BufferInputSource(std::string const& description, - Buffer* buf, bool own_memory) : +BufferInputSource::BufferInputSource( + std::string const& description, Buffer* buf, bool own_memory) : m(new Members(own_memory, description, buf)) { } -BufferInputSource::BufferInputSource(std::string const& description, - std::string const& contents) : +BufferInputSource::BufferInputSource( + std::string const& description, std::string const& contents) : m(new Members(true, description, 0)) { this->m->buf = new Buffer(contents.length()); @@ -40,8 +39,7 @@ BufferInputSource::BufferInputSource(std::string const& description, BufferInputSource::~BufferInputSource() { - if (this->m->own_memory) - { + if (this->m->own_memory) { delete this->m->buf; } } @@ -49,13 +47,11 @@ BufferInputSource::~BufferInputSource() qpdf_offset_t BufferInputSource::findAndSkipNextEOL() { - if (this->m->cur_offset < 0) - { + if (this->m->cur_offset < 0) { throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); } qpdf_offset_t end_pos = this->m->max_offset; - if (this->m->cur_offset >= end_pos) - { + if (this->m->cur_offset >= end_pos) { this->last_offset = end_pos; this->m->cur_offset = end_pos; return end_pos; @@ -66,24 +62,19 @@ BufferInputSource::findAndSkipNextEOL() unsigned char const* end = buffer + end_pos; unsigned char const* p = buffer + this->m->cur_offset; - while ((p < end) && !((*p == '\r') || (*p == '\n'))) - { + while ((p < end) && !((*p == '\r') || (*p == '\n'))) { ++p; } - if (p < end) - { + if (p < end) { result = p - buffer; this->m->cur_offset = result + 1; ++p; while ((this->m->cur_offset < end_pos) && - ((*p == '\r') || (*p == '\n'))) - { + ((*p == '\r') || (*p == '\n'))) { ++p; ++this->m->cur_offset; } - } - else - { + } else { this->m->cur_offset = end_pos; result = end_pos; } @@ -105,30 +96,28 @@ BufferInputSource::tell() void BufferInputSource::seek(qpdf_offset_t offset, int whence) { - switch (whence) - { - case SEEK_SET: + switch (whence) { + case SEEK_SET: this->m->cur_offset = offset; break; - case SEEK_END: + case SEEK_END: QIntC::range_check(this->m->max_offset, offset); this->m->cur_offset = this->m->max_offset + offset; break; - case SEEK_CUR: + case SEEK_CUR: QIntC::range_check(this->m->cur_offset, offset); this->m->cur_offset += offset; break; - default: + default: throw std::logic_error( "INTERNAL ERROR: invalid argument to BufferInputSource::seek"); break; } - if (this->m->cur_offset < 0) - { + if (this->m->cur_offset < 0) { throw std::runtime_error( this->m->description + ": seek before beginning of buffer"); } @@ -143,20 +132,18 @@ BufferInputSource::rewind() size_t BufferInputSource::read(char* buffer, size_t length) { - if (this->m->cur_offset < 0) - { + if (this->m->cur_offset < 0) { throw std::logic_error("INTERNAL ERROR: BufferInputSource offset < 0"); } qpdf_offset_t end_pos = this->m->max_offset; - if (this->m->cur_offset >= end_pos) - { + if (this->m->cur_offset >= end_pos) { this->last_offset = end_pos; return 0; } this->last_offset = this->m->cur_offset; - size_t len = std::min( - QIntC::to_size(end_pos - this->m->cur_offset), length); + size_t len = + std::min(QIntC::to_size(end_pos - this->m->cur_offset), length); memcpy(buffer, this->m->buf->getBuffer() + this->m->cur_offset, len); this->m->cur_offset += QIntC::to_offset(len); return len; @@ -165,8 +152,7 @@ BufferInputSource::read(char* buffer, size_t length) void BufferInputSource::unreadCh(char ch) { - if (this->m->cur_offset > 0) - { + if (this->m->cur_offset > 0) { --this->m->cur_offset; } } -- cgit v1.2.3-54-g00ecf