blob: beb58ef4f62a88272fd408160a6b6ef620b306b3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
|
// file : xsde/cxx/string-sequence.cxx
// author : Boris Kolpackov <boris@codesynthesis.com>
// copyright : Copyright (c) 2005-2009 Code Synthesis Tools CC
// license : GNU GPL v2 + exceptions; see accompanying LICENSE file
#include <string.h> // memcpy, strlen, strcmp
#include <xsde/cxx/string-sequence.hxx>
namespace xsde
{
namespace cxx
{
void string_sequence::
clear ()
{
for (size_t i = 0; i < size_; ++i)
delete[] static_cast<char**> (data_)[i];
size_ = 0;
}
#ifdef XSDE_EXCEPTIONS
void string_sequence::
push_back_copy (const char* cs)
{
if (capacity_ < size_ + 1)
grow_ (0, sizeof (char*), 0);
size_t n = strlen (cs) + 1;
char* s = new char[n];
memcpy (s, cs, n);
static_cast<char**> (data_)[size_++] = s;
}
#else
string_sequence::error string_sequence::
push_back_copy (const char* cs)
{
error r = error_none;
if (capacity_ < size_ + 1)
r = grow_ (0, sizeof (char*), 0);
if (r == error_none)
{
size_t n = strlen (cs) + 1;
char* s = new char[n];
if (s != 0)
{
memcpy (s, cs, n);
static_cast<char**> (data_)[size_++] = s;
}
else
r = error_no_memory;
}
return r;
}
#endif
bool
operator== (const string_sequence& x, const string_sequence& y)
{
if (x.size () != y.size ())
return false;
for (size_t i = 0; i < x.size (); ++i)
if (strcmp (x[i], y[i]) != 0)
return false;
return true;
}
}
}
|