summaryrefslogtreecommitdiffstats
path: root/libqpdf/bits.icc
diff options
context:
space:
mode:
authorJay Berkenbilt <ejb@ql.org>2022-02-08 15:18:08 +0100
committerJay Berkenbilt <ejb@ql.org>2022-02-08 17:51:15 +0100
commitcb769c62e55599e9f980001830bc61d9fcaa64a9 (patch)
tree0bf980c385a61cbc8720cf990762ffc1200f9d6a /libqpdf/bits.icc
parent716381f65a2b2dc72f8da2426ba71aeab02c507f (diff)
downloadqpdf-cb769c62e55599e9f980001830bc61d9fcaa64a9.tar.zst
WHITESPACE ONLY -- expand tabs in source code
This comment expands all tabs using an 8-character tab-width. You should ignore this commit when using git blame or use git blame -w. In the early days, I used to use tabs where possible for indentation, since emacs did this automatically. In recent years, I have switched to only using spaces, which means qpdf source code has been a mixture of spaces and tabs. I have avoided cleaning this up because of not wanting gratuitous whitespaces change to cloud the output of git blame, but I changed my mind after discussing with users who view qpdf source code in editors/IDEs that have other tab widths by default and in light of the fact that I am planning to start applying automatic code formatting soon.
Diffstat (limited to 'libqpdf/bits.icc')
-rw-r--r--libqpdf/bits.icc128
1 files changed, 64 insertions, 64 deletions
diff --git a/libqpdf/bits.icc b/libqpdf/bits.icc
index 3fb9dfa1..14c4640d 100644
--- a/libqpdf/bits.icc
+++ b/libqpdf/bits.icc
@@ -18,7 +18,7 @@
#ifdef BITS_READ
static unsigned long long
read_bits(unsigned char const*& p, size_t& bit_offset,
- size_t& bits_available, size_t bits_wanted)
+ size_t& bits_available, size_t bits_wanted)
{
// View p as a stream of bits:
@@ -29,67 +29,67 @@ read_bits(unsigned char const*& p, size_t& bit_offset,
if (bits_wanted > bits_available)
{
- throw std::runtime_error(
+ throw std::runtime_error(
"overflow reading bit stream: wanted = " +
QUtil::uint_to_string(bits_wanted) + "; available = " +
QUtil::uint_to_string(bits_available));
}
if (bits_wanted > 32)
{
- throw std::out_of_range("read_bits: too many bits requested");
+ throw std::out_of_range("read_bits: too many bits requested");
}
unsigned long result = 0;
#ifdef BITS_TESTING
if (bits_wanted == 0)
{
- QTC::TC("libtests", "bits zero bits wanted");
+ QTC::TC("libtests", "bits zero bits wanted");
}
#endif
while (bits_wanted > 0)
{
- // Grab bits from the first byte clearing anything before
- // bit_offset.
- unsigned char byte = static_cast<unsigned char>(
+ // Grab bits from the first byte clearing anything before
+ // bit_offset.
+ unsigned char byte = static_cast<unsigned char>(
*p & ((1U << (bit_offset + 1U)) - 1U));
- // There are bit_offset + 1 bits available in the first byte.
- size_t to_copy = std::min(bits_wanted, bit_offset + 1);
- size_t leftover = (bit_offset + 1) - to_copy;
+ // There are bit_offset + 1 bits available in the first byte.
+ size_t to_copy = std::min(bits_wanted, bit_offset + 1);
+ size_t leftover = (bit_offset + 1) - to_copy;
#ifdef BITS_TESTING
- QTC::TC("libtests", "bits bit_offset",
- ((bit_offset == 0) ? 0 :
- (bit_offset == 7) ? 1 :
- 2));
- QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0);
+ QTC::TC("libtests", "bits bit_offset",
+ ((bit_offset == 0) ? 0 :
+ (bit_offset == 7) ? 1 :
+ 2));
+ QTC::TC("libtests", "bits leftover", (leftover > 0) ? 1 : 0);
#endif
- // Right shift so that all the bits we want are right justified.
- byte = static_cast<unsigned char>(byte >> leftover);
-
- // Copy the bits into result
- result <<= to_copy;
- result |= byte;
-
- // Update pointers
- if (leftover)
- {
- bit_offset = leftover - 1;
- }
- else
- {
- bit_offset = 7;
- ++p;
- }
- bits_wanted -= to_copy;
- bits_available -= to_copy;
+ // Right shift so that all the bits we want are right justified.
+ byte = static_cast<unsigned char>(byte >> leftover);
+
+ // Copy the bits into result
+ result <<= to_copy;
+ result |= byte;
+
+ // Update pointers
+ if (leftover)
+ {
+ bit_offset = leftover - 1;
+ }
+ else
+ {
+ bit_offset = 7;
+ ++p;
+ }
+ bits_wanted -= to_copy;
+ bits_available -= to_copy;
#ifdef BITS_TESTING
- QTC::TC("libtests", "bits iterations",
- ((bits_wanted > 8) ? 0 :
- (bits_wanted > 0) ? 1 :
- 2));
+ QTC::TC("libtests", "bits iterations",
+ ((bits_wanted > 8) ? 0 :
+ (bits_wanted > 0) ? 1 :
+ 2));
#endif
}
@@ -100,50 +100,50 @@ read_bits(unsigned char const*& p, size_t& bit_offset,
#ifdef BITS_WRITE
static void
write_bits(unsigned char& ch, size_t& bit_offset,
- unsigned long long val, size_t bits, Pipeline* pipeline)
+ unsigned long long val, size_t bits, Pipeline* pipeline)
{
if (bits > 32)
{
- throw std::out_of_range("write_bits: too many bits requested");
+ throw std::out_of_range("write_bits: too many bits requested");
}
// bit_offset + 1 is the number of bits left in ch
#ifdef BITS_TESTING
if (bits == 0)
{
- QTC::TC("libtests", "bits write zero bits");
+ QTC::TC("libtests", "bits write zero bits");
}
#endif
while (bits > 0)
{
- size_t bits_to_write = std::min(bits, bit_offset + 1);
- unsigned char newval = static_cast<unsigned char>(
- (val >> (bits - bits_to_write)) & ((1U << bits_to_write) - 1));
- size_t bits_left_in_ch = bit_offset + 1 - bits_to_write;
- newval = static_cast<unsigned char>(newval << bits_left_in_ch);
- ch |= newval;
- if (bits_left_in_ch == 0)
- {
+ size_t bits_to_write = std::min(bits, bit_offset + 1);
+ unsigned char newval = static_cast<unsigned char>(
+ (val >> (bits - bits_to_write)) & ((1U << bits_to_write) - 1));
+ size_t bits_left_in_ch = bit_offset + 1 - bits_to_write;
+ newval = static_cast<unsigned char>(newval << bits_left_in_ch);
+ ch |= newval;
+ if (bits_left_in_ch == 0)
+ {
#ifdef BITS_TESTING
- QTC::TC("libtests", "bits write pipeline");
+ QTC::TC("libtests", "bits write pipeline");
#endif
- pipeline->write(&ch, 1);
- bit_offset = 7;
- ch = 0;
- }
- else
- {
+ pipeline->write(&ch, 1);
+ bit_offset = 7;
+ ch = 0;
+ }
+ else
+ {
#ifdef BITS_TESTING
- QTC::TC("libtests", "bits write leftover");
+ QTC::TC("libtests", "bits write leftover");
#endif
- bit_offset -= bits_to_write;
- }
- bits -= bits_to_write;
+ bit_offset -= bits_to_write;
+ }
+ bits -= bits_to_write;
#ifdef BITS_TESTING
- QTC::TC("libtests", "bits write iterations",
- ((bits > 8) ? 0 :
- (bits > 0) ? 1 :
- 2));
+ QTC::TC("libtests", "bits write iterations",
+ ((bits > 8) ? 0 :
+ (bits > 0) ? 1 :
+ 2));
#endif
}