Remove gobjectmodule
[pygobject.git] / gi / pygi-util.c
blobc06806b54086d3a2cc3d39b9011708385e241506
1 /* -*- Mode: C; c-basic-offset: 4 -*-
2 * pygtk- Python bindings for the GTK toolkit.
3 * Copyright (C) 1998-2003 James Henstridge
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 #include "pygi-util.h"
21 PyObject *
22 pyg_integer_richcompare(PyObject *v, PyObject *w, int op)
24 PyObject *result;
25 gboolean t;
27 switch (op) {
28 case Py_EQ: t = PYGLIB_PyLong_AS_LONG(v) == PYGLIB_PyLong_AS_LONG(w); break;
29 case Py_NE: t = PYGLIB_PyLong_AS_LONG(v) != PYGLIB_PyLong_AS_LONG(w); break;
30 case Py_LE: t = PYGLIB_PyLong_AS_LONG(v) <= PYGLIB_PyLong_AS_LONG(w); break;
31 case Py_GE: t = PYGLIB_PyLong_AS_LONG(v) >= PYGLIB_PyLong_AS_LONG(w); break;
32 case Py_LT: t = PYGLIB_PyLong_AS_LONG(v) < PYGLIB_PyLong_AS_LONG(w); break;
33 case Py_GT: t = PYGLIB_PyLong_AS_LONG(v) > PYGLIB_PyLong_AS_LONG(w); break;
34 default: g_assert_not_reached();
37 result = t ? Py_True : Py_False;
38 Py_INCREF(result);
39 return result;
42 /**
43 * pyg_constant_strip_prefix:
44 * @name: the constant name.
45 * @strip_prefix: the prefix to strip.
47 * Advances the pointer @name by strlen(@strip_prefix) characters. If
48 * the resulting name does not start with a letter or underscore, the
49 * @name pointer will be rewound. This is to ensure that the
50 * resulting name is a valid identifier. Hence the returned string is
51 * a pointer into the string @name.
53 * Returns: the stripped constant name.
55 const gchar *
56 pyg_constant_strip_prefix(const gchar *name, const gchar *strip_prefix)
58 size_t prefix_len;
59 guint i;
61 prefix_len = strlen(strip_prefix);
63 /* Check so name starts with strip_prefix, if it doesn't:
64 * return the rest of the part which doesn't match
66 for (i = 0; i < prefix_len; i++) {
67 if (name[i] != strip_prefix[i] && name[i] != '_') {
68 return &name[i];
72 /* strip off prefix from value name, while keeping it a valid
73 * identifier */
74 for (i = prefix_len + 1; i > 0; i--) {
75 if (g_ascii_isalpha(name[i - 1]) || name[i - 1] == '_') {
76 return &name[i - 1];
79 return name;