Skip to content

Commit

Permalink
Merge pull request #11 from SolidWallOfCode/txnbox-2
Browse files Browse the repository at this point in the history
Fixes from txn_box work.
  • Loading branch information
SolidWallOfCode authored Jun 15, 2019
2 parents 6f73462 + 6c9af0e commit aaf66ad
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
12 changes: 7 additions & 5 deletions swoc++/include/swoc/TextView.h
Original file line number Diff line number Diff line change
Expand Up @@ -1288,7 +1288,7 @@ TextView::rtrim(std::string_view const &delimiters)
const char *spot = this->data_end();
const char *limit = this->data();

while (limit < spot && valid[static_cast<uint8_t>(*--spot)])
while (limit < spot-- && valid[static_cast<uint8_t>(*spot)])
;

this->remove_suffix(this->data_end() - (spot + 1));
Expand All @@ -1308,7 +1308,9 @@ TextView::trim(std::string_view const &delimiters)
;
this->remove_prefix(spot - this->data());

for (spot = this->data_end(), limit = this->data(); limit < spot && valid[static_cast<uint8_t>(*--spot)];)
spot = this->data_end();
limit = this->data();
while (limit < spot-- && valid[static_cast<uint8_t>(*spot)])
;
this->remove_suffix(this->data_end() - (spot + 1));

Expand Down Expand Up @@ -1337,9 +1339,9 @@ template <typename F>
TextView::self_type &
TextView::rtrim_if(F const &pred)
{
const char *spot;
const char *limit;
for (spot = this->data_end(), limit = this->data(); limit < spot && pred(*--spot);)
const char *spot = this->data_end();
const char *limit = this->data();
while (limit < spot-- && pred(*spot))
;
this->remove_suffix(this->data_end() - (spot + 1));
return *this;
Expand Down
2 changes: 1 addition & 1 deletion swoc++/include/swoc/bwf_fwd.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ namespace swoc
{
class BufferWriter;
class FixedBufferWriter;
template < size_t N > class LocalBufferWriter;
template <size_t N> class LocalBufferWriter;

namespace bwf
{
Expand Down
3 changes: 2 additions & 1 deletion unit_tests/test_MemArena.cc
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,8 @@ TEST_CASE("MemArena esoterica", "[libswoc][MemArena]")
}

{
std::unique_ptr<MemArena, void (*)(MemArena *)> arena(MemArena::construct_self_contained(), [](MemArena *arena) -> void { arena->~MemArena(); });
std::unique_ptr<MemArena, void (*)(MemArena *)> arena(MemArena::construct_self_contained(),
[](MemArena *arena) -> void { arena->~MemArena(); });
static constexpr unsigned MAX = 512;
std::uniform_int_distribution<unsigned> length_gen{6, MAX};
char buffer[MAX];
Expand Down
13 changes: 13 additions & 0 deletions unit_tests/test_TextView.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

using swoc::TextView;
using namespace std::literals;
using namespace swoc::literals;

TEST_CASE("TextView Constructor", "[libswoc][TextView]")
{
Expand Down Expand Up @@ -80,6 +81,18 @@ TEST_CASE("TextView Trimming", "[libswoc][TextView]")
REQUIRE("More Text" == TextView{tv2}.rtrim_if(&isdigit));
REQUIRE(" Evil Dave Rulz " == TextView(tv).rtrim('.'));
REQUIRE("Evil Dave Rulz" == TextView(tv).trim(" ."));

tv.assign("\r\n");
tv.rtrim_if([](char c) -> bool { return c == '\r' || c == '\n'; });
REQUIRE(tv.size() == 0);

tv.assign("...");
tv.rtrim('.');
REQUIRE(tv.size() == 0);

tv.assign(".,,.;.");
tv.rtrim(";,."_tv);
REQUIRE(tv.size() == 0);
}

TEST_CASE("TextView Find", "[libswoc][TextView]")
Expand Down

0 comments on commit aaf66ad

Please sign in to comment.