Skip to content

Commit bd6630d

Browse files
committed
Add missing ctl::string append method
1 parent a120bc7 commit bd6630d

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

ctl/string.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,4 +383,10 @@ string::erase(const size_t pos, size_t count) noexcept
383383
return *this;
384384
}
385385

386+
void
387+
string::append(const ctl::string_view& s, size_t pos, size_t count) noexcept
388+
{
389+
append(s.substr(pos, count));
390+
}
391+
386392
} // namespace ctl

ctl/string.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ class string
125125
void append(char, size_t) noexcept;
126126
void append(unsigned long) noexcept;
127127
void append(const void*, size_t) noexcept;
128+
void append(const ctl::string_view&, size_t, size_t = npos) noexcept;
128129
string& insert(size_t, ctl::string_view) noexcept;
129130
string& erase(size_t = 0, size_t = npos) noexcept;
130131
string substr(size_t = 0, size_t = npos) const noexcept;
@@ -302,7 +303,7 @@ class string
302303
append(ch);
303304
}
304305

305-
void append(const ctl::string_view s) noexcept
306+
void append(const ctl::string_view& s) noexcept
306307
{
307308
append(s.p, s.n);
308309
}

test/ctl/string_test.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,5 +404,13 @@ main()
404404
}
405405
}
406406

407+
{
408+
String s = "love";
409+
String b;
410+
b.append(s, 1, 2);
411+
if (b != "ov")
412+
return 107;
413+
}
414+
407415
CheckForMemoryLeaks();
408416
}

0 commit comments

Comments
 (0)