File tree Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Expand file tree Collapse file tree 2 files changed +26
-0
lines changed Original file line number Diff line number Diff line change 15
15
#define str_init str___INIT
16
16
#define str_equal str___EQUAL
17
17
#define str_find str___FIND
18
+ #define str_copy str___COPY
18
19
#include <vec.h>
19
20
#undef str_init
21
+ #undef str_copy
20
22
#undef str_equal
21
23
#undef str_find
22
24
#undef vec_char
@@ -46,6 +48,14 @@ str_append(str* self, const char* s)
46
48
self -> value [start + i ] = s [i ];
47
49
}
48
50
51
+ static inline str
52
+ str_copy (str * s )
53
+ {
54
+ str other = str_init ("" );
55
+ str_append (& other , s -> value );
56
+ return other ;
57
+ }
58
+
49
59
static inline void
50
60
str_insert_str (str * self , size_t index , const char * s )
51
61
{
Original file line number Diff line number Diff line change @@ -52,12 +52,28 @@ char_compare(char* a, char* b)
52
52
return *a > *b;
53
53
}
54
54
55
+ static void
56
+ test_zero_size_copy (void )
57
+ {
58
+ str a = str_init (" " );
59
+ str b = str_copy (&a);
60
+ std::string aa = " " ;
61
+ std::string bb = aa;
62
+ assert (aa.size () == a.size );
63
+ assert (bb.size () == b.size );
64
+ assert (aa.capacity () == a.capacity );
65
+ assert (bb.capacity () == b.capacity );
66
+ str_free (&a);
67
+ str_free (&b);
68
+ }
69
+
55
70
int
56
71
main (void )
57
72
{
58
73
#ifdef SRAND
59
74
srand (time (NULL ));
60
75
#endif
76
+ test_zero_size_copy ();
61
77
const size_t loops = TEST_RAND (TEST_MAX_LOOPS);
62
78
for (size_t loop = 0 ; loop < loops; loop++)
63
79
{
You can’t perform that action at this time.
0 commit comments