File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ class FixedString : public UMemory {
30
30
31
31
FixedString (const FixedString&) = delete ;
32
32
33
+ FixedString (std::string_view init) {
34
+ size_t size = init.size ();
35
+ if (reserve (size + 1 )) {
36
+ uprv_memcpy (ptr, init.data (), size);
37
+ ptr[size] = ' \0 ' ;
38
+ }
39
+ }
40
+
33
41
FixedString& operator =(const FixedString& other) {
34
42
*this = other.data ();
35
43
return *this ;
Original file line number Diff line number Diff line change 888
888
StringTest::TestFixedString () {
889
889
static_assert (std::is_default_constructible_v<FixedString>);
890
890
static_assert (!std::is_copy_constructible_v<FixedString>);
891
+ static_assert (std::is_constructible_v<FixedString, std::string_view>);
891
892
static_assert (std::is_copy_assignable_v<FixedString>);
892
893
static_assert (std::is_assignable_v<FixedString, std::string_view>);
893
894
static_assert (!std::is_move_constructible_v<FixedString>);
@@ -910,6 +911,11 @@ StringTest::TestFixedString() {
910
911
911
912
static constexpr char text[] = " foo" ;
912
913
914
+ FixedString init (text);
915
+ assertFalse (" initialized is empty" , init.isEmpty ());
916
+ assertFalse (" initialized alias is nullptr" , init.getAlias () == nullptr );
917
+ assertEquals (" initialized data is text" , text, init.data ());
918
+
913
919
s = text;
914
920
assertFalse (" assigned is empty" , s.isEmpty ());
915
921
assertFalse (" assigned alias is nullptr" , s.getAlias () == nullptr );
You can’t perform that action at this time.
0 commit comments