Skip to content

Commit e109bcb

Browse files
committed
Fix split iteration meets empty parts
1 parent 973321e commit e109bcb

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

common/estring.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,16 @@ class estring_view : public std::string_view
163163
_part = _host->find_part(_part.end() + 1);
164164
return *this;
165165
}
166-
iterator& operator++(int)
166+
iterator operator++(int)
167167
{
168168
auto ret = *this;
169169
++(*this);
170170
return ret;
171171
}
172172
bool operator == (const iterator& rhs) const
173173
{
174-
return _part == rhs._part;
174+
return _part.data() == rhs._part.data() &&
175+
_part.length() == rhs._part.length();
175176
}
176177
bool operator != (const iterator& rhs) const
177178
{

common/test/test.cpp

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -863,6 +863,51 @@ TEST(estring, test)
863863
EXPECT_EQ(a[1], "q3r1234");
864864
EXPECT_EQ(a[2], "poiu");
865865

866+
sp = s.split(cs, false);
867+
it = sp.begin();
868+
front = *it;
869+
remainder = it.remainder();
870+
LOG_DEBUG(VALUE(front), VALUE(remainder));
871+
EXPECT_EQ(front, "alskdjf");
872+
EXPECT_EQ(remainder, ";;,q3r1234;poiu");
873+
it ++;
874+
front = *it;
875+
remainder = it.remainder();
876+
LOG_DEBUG(VALUE(front), VALUE(remainder));
877+
EXPECT_EQ(front, "");
878+
EXPECT_EQ(remainder, ";,q3r1234;poiu");
879+
it ++;
880+
front = *it;
881+
remainder = it.remainder();
882+
LOG_DEBUG(VALUE(front), VALUE(remainder));
883+
EXPECT_EQ(front, "");
884+
EXPECT_EQ(remainder, ",q3r1234;poiu");
885+
it ++;
886+
front = *it;
887+
remainder = it.remainder();
888+
LOG_DEBUG(VALUE(front), VALUE(remainder));
889+
EXPECT_EQ(front, "");
890+
EXPECT_EQ(remainder, "q3r1234;poiu");
891+
it ++;
892+
front = *it;
893+
remainder = it.remainder();
894+
LOG_DEBUG(VALUE(front), VALUE(remainder));
895+
EXPECT_EQ(front, "q3r1234");
896+
EXPECT_EQ(remainder, "poiu");
897+
898+
a.clear();
899+
for (auto x: sp)
900+
{
901+
a.push_back(x);
902+
LOG_DEBUG(x);
903+
}
904+
905+
EXPECT_EQ(a.size(), 6);
906+
EXPECT_EQ(a[0], "alskdjf");
907+
EXPECT_EQ(a[4], "q3r1234");
908+
EXPECT_EQ(a[5], "poiu");
909+
910+
866911
auto sv = s;//.view();
867912
EXPECT_TRUE(sv.starts_with("alskdjf"));
868913
EXPECT_FALSE(sv.starts_with("alsk32"));

0 commit comments

Comments
 (0)