• R/O
  • SSH
  • HTTPS

comatz: Commit


Commit MetaInfo

Revisão11 (tree)
Hora2007-04-19 17:47:30
Autorkous

Mensagem de Log

* comatz/cm-char.[ch]: added.
* comatz/Makefile.am: added cm-char.[ch].

Mudança Sumário

Diff

--- comatz/trunk/ChangeLog (revision 10)
+++ comatz/trunk/ChangeLog (revision 11)
@@ -1,3 +1,8 @@
1+2007-04-19 Kouhei Sutou <kou@cozmixng.org>
2+
3+ * comatz/cm-char.[ch]: added.
4+ * comatz/Makefile.am: added cm-char.[ch].
5+
16 2007-04-04 Kouhei Sutou <kou@cozmixng.org>
27
38 * ./: make skeleton.
--- comatz/trunk/comatz/cm-char.h (nonexistent)
+++ comatz/trunk/comatz/cm-char.h (revision 11)
@@ -0,0 +1,66 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2 of the License, or (at your option) any later version.
10+ *
11+ * This library is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifndef __CM_CHAR_H__
23+#define __CM_CHAR_H__
24+
25+#include <glib-object.h>
26+
27+G_BEGIN_DECLS
28+
29+#define CM_TYPE_CHAR (cm_char_get_type())
30+#define CM_CHAR(o) (G_TYPE_CHECK_INSTANCE_CAST((o), CM_TYPE_CHAR, CmChar))
31+#define CM_IS_CHAR(o) (G_TYPE_CHECK_INSTANCE_TYPE((o), CM_TYPE_CHAR))
32+#define CM_CHAR_GET_IFACE(o) (G_TYPE_INSTANCE_GET_INTERFACE((o), CM_TYPE_CHAR, CmCharIFace))
33+
34+typedef struct _CmChar CmChar;
35+typedef struct _CmCharClass CmCharClass;
36+
37+struct _CmChar
38+{
39+ GObject *object;
40+};
41+
42+struct _CmCharClass
43+{
44+ GObjectClass parent;
45+};
46+
47+GType cm_char_get_type (void) G_GNUC_CONST;
48+
49+CmChar *cm_char_new (const gchar *reading,
50+ const gchar *utf8);
51+
52+const gchar *cm_char_get_reading (CmChar *chr);
53+const gchar *cm_char_get_utf8 (CmChar *chr);
54+
55+void cm_char_set_reading (CmChar *chr,
56+ const gchar *reading);
57+void cm_char_set_utf8 (CmChar *chr,
58+ const gchar *utf8);
59+
60+G_END_DECLS
61+
62+#endif /* __CM_CHAR_H__ */
63+
64+/*
65+vi:ts=4:nowrap:ai:expandtab
66+*/
--- comatz/trunk/comatz/Makefile.am (revision 10)
+++ comatz/trunk/comatz/Makefile.am (revision 11)
@@ -24,6 +24,7 @@
2424 INCLUDES = $(COMATZ_CFLAGS)
2525
2626 comatz_public_h_sources = \
27+ cm-char.h \
2728 cm-dict.h \
2829 cm-module.h \
2930 cm-module-impl.h
@@ -52,6 +53,7 @@
5253 libcomatz_la_SOURCES = \
5354 comatz.c \
5455 cm-module.c \
56+ cm-char.c \
5557 cm-dict.c \
5658 @enum_types_prefix@.c
5759
--- comatz/trunk/comatz/cm-char.c (nonexistent)
+++ comatz/trunk/comatz/cm-char.c (revision 11)
@@ -0,0 +1,220 @@
1+/* -*- mode: c; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2+
3+/*
4+ * Copyright (C) 2007 Kouhei Sutou <kou@cozmixng.org>
5+ *
6+ * This library is free software; you can redistribute it and/or
7+ * modify it under the terms of the GNU Lesser General Public
8+ * License as published by the Free Software Foundation; either
9+ * version 2 of the License, or (at your option) any later version.
10+ *
11+ * This library is distributed in the hope that it will be useful,
12+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
13+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+ * GNU Lesser General Public License for more details.
15+ *
16+ * You should have received a copy of the GNU Lesser General Public
17+ * License along with this program; if not, write to the
18+ * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19+ * Boston, MA 02111-1307 USA
20+ */
21+
22+#ifdef HAVE_CONFIG_H
23+# include "config.h"
24+#endif /* HAVE_CONFIG_H */
25+
26+#include <glib/gi18n.h>
27+
28+#include "cm-char.h"
29+
30+#define CM_CHAR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE ((obj), CM_TYPE_CHAR, CmCharPrivate))
31+
32+typedef struct _CmCharPrivate CmCharPrivate;
33+struct _CmCharPrivate
34+{
35+ gchar *reading;
36+ gchar *utf8;
37+};
38+
39+enum
40+{
41+ PROP_0,
42+ PROP_READING,
43+ PROP_UTF8
44+};
45+
46+G_DEFINE_TYPE (CmChar, cm_char, G_TYPE_OBJECT)
47+
48+static void dispose (GObject *object);
49+static void set_property (GObject *object,
50+ guint prop_id,
51+ const GValue *value,
52+ GParamSpec *pspec);
53+static void get_property (GObject *object,
54+ guint prop_id,
55+ GValue *value,
56+ GParamSpec *pspec);
57+
58+static void
59+cm_char_class_init (CmCharClass *klass)
60+{
61+ GObjectClass *gobject_class;
62+ GParamSpec *spec;
63+
64+ gobject_class = G_OBJECT_CLASS (klass);
65+
66+ gobject_class->dispose = dispose;
67+ gobject_class->set_property = set_property;
68+ gobject_class->get_property = get_property;
69+
70+ spec = g_param_spec_string("reading",
71+ N_("UTF8"),
72+ N_("UTF8 encoding of the character."),
73+ NULL,
74+ G_PARAM_READABLE | G_PARAM_WRITABLE);
75+ g_object_class_install_property(gobject_class, PROP_READING, spec);
76+
77+ spec = g_param_spec_string("utf8",
78+ N_("UTF8"),
79+ N_("UTF8 encoding of the character."),
80+ NULL,
81+ G_PARAM_READABLE | G_PARAM_WRITABLE);
82+ g_object_class_install_property(gobject_class, PROP_UTF8, spec);
83+
84+ g_type_class_add_private (gobject_class, sizeof(CmCharPrivate));
85+}
86+
87+static void
88+cm_char_init (CmChar *chr)
89+{
90+ CmCharPrivate *priv = CM_CHAR_GET_PRIVATE (chr);
91+ priv->reading = NULL;
92+ priv->utf8 = NULL;
93+}
94+
95+static void
96+dispose (GObject *object)
97+{
98+ CmCharPrivate *priv = CM_CHAR_GET_PRIVATE(object);
99+
100+ if (priv->reading)
101+ g_free(priv->reading);
102+ if (priv->utf8)
103+ g_free(priv->utf8);
104+
105+ priv->reading = NULL;
106+ priv->utf8 = NULL;
107+
108+ G_OBJECT_CLASS(cm_char_parent_class)->dispose(object);
109+}
110+
111+static void
112+set_property (GObject *object,
113+ guint prop_id,
114+ const GValue *value,
115+ GParamSpec *pspec)
116+{
117+ CmChar *chr;
118+
119+ chr = CM_CHAR(object);
120+ switch (prop_id) {
121+ case PROP_READING:
122+ cm_char_set_reading(chr, g_value_get_string(value));
123+ break;
124+ case PROP_UTF8:
125+ cm_char_set_utf8(chr, g_value_get_string(value));
126+ break;
127+ default:
128+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
129+ break;
130+ }
131+}
132+
133+static void
134+get_property (GObject *object,
135+ guint prop_id,
136+ GValue *value,
137+ GParamSpec *pspec)
138+{
139+ CmChar *chr;
140+ CmCharPrivate *priv;
141+
142+ chr = CM_CHAR(object);
143+ priv = CM_CHAR_GET_PRIVATE(chr);
144+
145+ switch (prop_id) {
146+ case PROP_READING:
147+ g_value_set_string(value, priv->reading);
148+ break;
149+ case PROP_UTF8:
150+ g_value_set_string(value, priv->utf8);
151+ break;
152+ default:
153+ G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
154+ break;
155+ }
156+}
157+
158+/**
159+ * cm_char_new:
160+ *
161+ * Create a new #CmChar.
162+ *
163+ * Return value: a new #CmChar
164+ */
165+CmChar*
166+cm_char_new (const gchar *reading, const gchar *utf8)
167+{
168+ return g_object_new(CM_TYPE_CHAR,
169+ "reading", reading,
170+ "utf8", utf8,
171+ NULL);
172+}
173+
174+const gchar *
175+cm_char_get_reading (CmChar *chr)
176+{
177+ g_return_val_if_fail(CM_IS_CHAR(chr), NULL);
178+ return CM_CHAR_GET_PRIVATE(chr)->reading;
179+}
180+
181+const gchar *
182+cm_char_get_utf8 (CmChar *chr)
183+{
184+ g_return_val_if_fail(CM_IS_CHAR(chr), NULL);
185+ return CM_CHAR_GET_PRIVATE(chr)->utf8;
186+}
187+
188+void
189+cm_char_set_reading (CmChar *chr, const gchar *reading)
190+{
191+ CmCharPrivate *priv;
192+ g_return_if_fail(CM_IS_CHAR(chr));
193+
194+ priv = CM_CHAR_GET_PRIVATE(chr);
195+ if (priv->reading)
196+ g_free(priv->reading);
197+ priv->reading = NULL;
198+
199+ if (reading)
200+ priv->reading = g_strdup(priv->reading);
201+}
202+
203+void
204+cm_char_set_utf8 (CmChar *chr, const gchar *utf8)
205+{
206+ CmCharPrivate *priv;
207+ g_return_if_fail(CM_IS_CHAR(chr));
208+
209+ priv = CM_CHAR_GET_PRIVATE(chr);
210+ if (priv->utf8)
211+ g_free(priv->utf8);
212+ priv->utf8 = NULL;
213+
214+ if (utf8)
215+ priv->utf8 = g_strdup(priv->utf8);
216+}
217+
218+/*
219+vi:ts=4:nowrap:ai:expandtab
220+*/
Show on old repository browser