1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; indent-offset: 4 -*- */
5 * Copyright (C) 2008 Vincent Geddes <vgeddes@gnome.org>
7 * This library is free software: you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation, either
10 * version 3 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include <st-symbol.h>
22 #include <st-hashed-collection.h>
23 #include <st-byte-array.h>
27 ST_DEFINE_VTABLE (st_symbol
, st_byte_array_vtable ());
30 symbol_equal (st_oop_t object
, st_oop_t another
)
32 if (object
== another
)
35 if (st_object_class (object
) == st_object_class (another
))
38 // now just do a string comparison
39 if (st_byte_array_vtable ()->equal (object
, another
))
52 st_symbol_vtable_init (st_vtable_t
* table
)
54 table
->equal
= symbol_equal
;
56 table
->is_symbol
= is_symbol
;
60 string_new (st_oop_t klass
, const char *bytes
)
62 int len
= strlen (bytes
);
64 st_oop_t string
= st_object_new_arrayed (klass
, len
);
66 guchar
*data
= st_byte_array_bytes (string
);
68 memcpy (data
, bytes
, len
);
74 st_string_new (const char *bytes
)
76 return string_new (st_string_class
, bytes
);
81 st_symbol_new (const char *bytes
)
83 st_oop_t element
= st_set_like (st_symbol_table
, st_string_new (bytes
));
85 if (element
== st_nil
) {
87 st_oop_t symbol
= string_new (st_symbol_class
, bytes
);
89 st_set_add (st_symbol_table
, symbol
);