1
2
3
4
5
6
7
8
9
10
11
12
13#include "qemu/osdep.h"
14#include "qapi/qmp/qstring.h"
15#include "qobject-internal.h"
16
17
18
19
20
21
22QString *qstring_new(void)
23{
24 return qstring_from_str("");
25}
26
27
28
29
30
31
32QString *qstring_from_substr(const char *str, size_t start, size_t end)
33{
34 QString *qstring;
35
36 assert(start <= end);
37 qstring = g_malloc(sizeof(*qstring));
38 qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
39 qstring->string = g_strndup(str + start, end - start);
40 return qstring;
41}
42
43
44
45
46
47
48QString *qstring_from_str(const char *str)
49{
50 return qstring_from_substr(str, 0, strlen(str));
51}
52
53
54
55
56
57
58
59QString *qstring_from_gstring(GString *gstr)
60{
61 QString *qstring;
62
63 qstring = g_malloc(sizeof(*qstring));
64 qobject_init(QOBJECT(qstring), QTYPE_QSTRING);
65 qstring->string = g_string_free(gstr, false);
66 return qstring;
67}
68
69
70
71
72
73
74
75
76const char *qstring_get_str(const QString *qstring)
77{
78 return qstring->string;
79}
80
81
82
83
84bool qstring_is_equal(const QObject *x, const QObject *y)
85{
86 return !strcmp(qobject_to(QString, x)->string,
87 qobject_to(QString, y)->string);
88}
89
90
91
92
93
94void qstring_destroy_obj(QObject *obj)
95{
96 QString *qs;
97
98 assert(obj != NULL);
99 qs = qobject_to(QString, obj);
100 g_free((char *)qs->string);
101 g_free(qs);
102}
103