Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TextFlow: fix length calculation in case text starts with linebreak #2

Merged
merged 2 commits into from
Apr 21, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions TextFlow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ namespace TextFlow {
m_suffix = false;
auto width = m_column.m_width-indent();
m_end = m_pos;
if(!line().empty() && line()[m_pos] == '\n')
++m_end;
while( m_end < line().size() && line()[m_end] != '\n' )
++m_end;

Expand Down
16 changes: 16 additions & 0 deletions TextFlow_Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,22 @@ TEST_CASE( "another long string" ) {
" convallis posuere, libero nisi ultricies orci, nec lobortis." );
}

TEST_CASE( "message with linebreak at start" )
{
const auto message = std::string(
"\nthis is a message starting with linebreak"
);

auto col = Column( message )
.width(79)
.indent(2);

REQUIRE(col.toString() ==
" \n"
"this is a message starting with linebreak"
);
}

std::mt19937 rng;
std::uniform_int_distribution<std::mt19937::result_type> wordCharGenerator(33,126);
std::uniform_int_distribution<std::mt19937::result_type> wsGenerator(0, 11);
Expand Down