Skip to content

Commit

Permalink
Remove trailing whitespace and formatting iostream
Browse files Browse the repository at this point in the history
  • Loading branch information
tttapa committed Apr 29, 2021
1 parent 9b47409 commit 45a91d8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
6 changes: 3 additions & 3 deletions include/pybind11/iostream.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class pythonbuf : public std::streambuf {
return sync() == 0 ? traits_type::not_eof(c) : traits_type::eof();
}

// Computes how many bytes at the end of the buffer are part of an
// Computes how many bytes at the end of the buffer are part of an
// incomplete sequence of UTF-8 bytes.
// Precondition: pbase() < pptr()
size_t utf8_remainder() const {
Expand Down Expand Up @@ -71,15 +71,15 @@ class pythonbuf : public std::streambuf {
const auto dist = static_cast<size_t>(leading - rpptr);
size_t remainder = 0;

if (dist == 0)
if (dist == 0)
remainder = 1; // 1-byte code point is impossible
else if (dist == 1)
remainder = is_leading_2b(*leading) ? 0 : dist + 1;
else if (dist == 2)
remainder = is_leading_3b(*leading) ? 0 : dist + 1;
// else if (dist >= 3), at least 4 bytes before encountering an UTF-8
// leading byte, either no remainder or invalid UTF-8.
// Invalid UTF-8 will cause an exception later when converting
// Invalid UTF-8 will cause an exception later when converting
// to a Python string, so that's not handled here.
return remainder;
}
Expand Down
10 changes: 10 additions & 0 deletions tests/test_iostream.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def test_captured_large_string(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_2byte_offset0(capsys):
msg = "\u07FF"
msg = "" + msg * (1024 // len(msg) + 1)
Expand All @@ -77,6 +78,7 @@ def test_captured_utf8_2byte_offset0(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_2byte_offset1(capsys):
msg = "\u07FF"
msg = "1" + msg * (1024 // len(msg) + 1)
Expand All @@ -86,6 +88,7 @@ def test_captured_utf8_2byte_offset1(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_3byte_offset0(capsys):
msg = "\uFFFF"
msg = "" + msg * (1024 // len(msg) + 1)
Expand All @@ -95,6 +98,7 @@ def test_captured_utf8_3byte_offset0(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_3byte_offset1(capsys):
msg = "\uFFFF"
msg = "1" + msg * (1024 // len(msg) + 1)
Expand All @@ -104,6 +108,7 @@ def test_captured_utf8_3byte_offset1(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_3byte_offset2(capsys):
msg = "\uFFFF"
msg = "12" + msg * (1024 // len(msg) + 1)
Expand All @@ -113,6 +118,7 @@ def test_captured_utf8_3byte_offset2(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_4byte_offset0(capsys):
msg = "\U0010FFFF"
msg = "" + msg * (1024 // len(msg) + 1)
Expand All @@ -122,6 +128,7 @@ def test_captured_utf8_4byte_offset0(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_4byte_offset1(capsys):
msg = "\U0010FFFF"
msg = "1" + msg * (1024 // len(msg) + 1)
Expand All @@ -131,6 +138,7 @@ def test_captured_utf8_4byte_offset1(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_4byte_offset2(capsys):
msg = "\U0010FFFF"
msg = "12" + msg * (1024 // len(msg) + 1)
Expand All @@ -140,6 +148,7 @@ def test_captured_utf8_4byte_offset2(capsys):
assert stdout == msg
assert stderr == ""


def test_captured_utf8_4byte_offset3(capsys):
msg = "\U0010FFFF"
msg = "123" + msg * (1024 // len(msg) + 1)
Expand All @@ -149,6 +158,7 @@ def test_captured_utf8_4byte_offset3(capsys):
assert stdout == msg
assert stderr == ""


def test_guard_capture(capsys):
msg = "I've been redirected to Python, I hope!"
m.guard_output(msg)
Expand Down

0 comments on commit 45a91d8

Please sign in to comment.