diff options
author | Richard Hughes <richard@hughsie.com> | 2009-02-27 12:50:05 +0000 |
---|---|---|
committer | Richard Hughes <richard@hughsie.com> | 2009-02-27 12:50:05 +0000 |
commit | 665523726ae43f08f2d5d9fe3ec9b327fe75c85d (patch) | |
tree | 0ade8efd5accc4d6034e882ac8ae0a0121cfea3d | |
parent | 842842c4796dffb5db21409a4436200299629100 (diff) | |
download | upower-665523726ae43f08f2d5d9fe3ec9b327fe75c85d.tar.gz |
trivial: remove egg-string
-rw-r--r-- | devkit-power-gobject/Makefile.am | 2 | ||||
-rw-r--r-- | devkit-power-gobject/dkp-device.c | 7 | ||||
-rw-r--r-- | devkit-power-gobject/dkp-enum.c | 41 | ||||
l--------- | devkit-power-gobject/egg-string.c | 1 | ||||
l--------- | devkit-power-gobject/egg-string.h | 1 | ||||
-rw-r--r-- | src/dkp-csr.c | 5 | ||||
-rw-r--r-- | src/dkp-daemon.c | 13 | ||||
-rw-r--r-- | src/dkp-device.c | 13 | ||||
-rw-r--r-- | src/dkp-hid.c | 3 | ||||
-rw-r--r-- | src/dkp-qos.c | 3 | ||||
-rw-r--r-- | src/dkp-supply.c | 1 | ||||
-rw-r--r-- | src/dkp-wakeups.c | 3 | ||||
-rw-r--r-- | src/dkp-wup.c | 3 | ||||
-rw-r--r-- | src/egg-string.c | 540 | ||||
-rw-r--r-- | src/egg-string.h | 52 |
15 files changed, 41 insertions, 647 deletions
diff --git a/devkit-power-gobject/Makefile.am b/devkit-power-gobject/Makefile.am index 043464e..52011e7 100644 --- a/devkit-power-gobject/Makefile.am +++ b/devkit-power-gobject/Makefile.am @@ -28,8 +28,6 @@ libdevkit_power_include_HEADERS = \ libdevkit_power_gobject_la_SOURCES = \ egg-debug.c \ egg-debug.h \ - egg-string.c \ - egg-string.h \ devicekit-power.h \ dkp-client.c \ dkp-client.h \ diff --git a/devkit-power-gobject/dkp-device.c b/devkit-power-gobject/dkp-device.c index 5f47015..c0e2ad2 100644 --- a/devkit-power-gobject/dkp-device.c +++ b/devkit-power-gobject/dkp-device.c @@ -28,7 +28,6 @@ #include <string.h> #include "egg-debug.h" -#include "egg-string.h" #include "dkp-device.h" #include "dkp-stats-obj.h" @@ -379,11 +378,11 @@ dkp_device_print (const DkpDevice *device) strftime (time_buf, sizeof time_buf, "%c", time_tm); g_print (" native-path: %s\n", device->priv->native_path); - if (!egg_strzero (device->priv->vendor)) + if (device->priv->vendor != NULL) g_print (" vendor: %s\n", device->priv->vendor); - if (!egg_strzero (device->priv->model)) + if (device->priv->model != NULL) g_print (" model: %s\n", device->priv->model); - if (!egg_strzero (device->priv->serial)) + if (device->priv->serial != NULL) g_print (" serial: %s\n", device->priv->serial); g_print (" power supply: %s\n", dkp_device_print_bool_to_text (device->priv->power_supply)); g_print (" updated: %s (%d seconds ago)\n", time_buf, (int) (time (NULL) - device->priv->update_time)); diff --git a/devkit-power-gobject/dkp-enum.c b/devkit-power-gobject/dkp-enum.c index 6f22dd0..f2954f1 100644 --- a/devkit-power-gobject/dkp-enum.c +++ b/devkit-power-gobject/dkp-enum.c @@ -22,7 +22,6 @@ #include <glib.h> #include <string.h> #include "egg-debug.h" -#include "egg-string.h" #include "dkp-enum.h" @@ -76,21 +75,21 @@ dkp_device_type_from_text (const gchar *type) { if (type == NULL) return DKP_DEVICE_TYPE_UNKNOWN; - if (egg_strequal (type, "line-power")) + if (g_strcmp0 (type, "line-power") == 0) return DKP_DEVICE_TYPE_LINE_POWER; - if (egg_strequal (type, "battery")) + if (g_strcmp0 (type, "battery") == 0) return DKP_DEVICE_TYPE_BATTERY; - if (egg_strequal (type, "ups")) + if (g_strcmp0 (type, "ups") == 0) return DKP_DEVICE_TYPE_UPS; - if (egg_strequal (type, "monitor")) + if (g_strcmp0 (type, "monitor") == 0) return DKP_DEVICE_TYPE_MONITOR; - if (egg_strequal (type, "mouse")) + if (g_strcmp0 (type, "mouse") == 0) return DKP_DEVICE_TYPE_MOUSE; - if (egg_strequal (type, "keyboard")) + if (g_strcmp0 (type, "keyboard") == 0) return DKP_DEVICE_TYPE_KEYBOARD; - if (egg_strequal (type, "pda")) + if (g_strcmp0 (type, "pda") == 0) return DKP_DEVICE_TYPE_PDA; - if (egg_strequal (type, "phone")) + if (g_strcmp0 (type, "phone") == 0) return DKP_DEVICE_TYPE_PHONE; return DKP_DEVICE_TYPE_UNKNOWN; } @@ -133,13 +132,13 @@ dkp_device_state_from_text (const gchar *state) { if (state == NULL) return DKP_DEVICE_STATE_UNKNOWN; - if (egg_strequal (state, "charging")) + if (g_strcmp0 (state, "charging") == 0) return DKP_DEVICE_STATE_CHARGING; - if (egg_strequal (state, "discharging")) + if (g_strcmp0 (state, "discharging") == 0) return DKP_DEVICE_STATE_DISCHARGING; - if (egg_strequal (state, "empty")) + if (g_strcmp0 (state, "empty") == 0) return DKP_DEVICE_STATE_EMPTY; - if (egg_strequal (state, "fully-charged")) + if (g_strcmp0 (state, "fully-charged") == 0) return DKP_DEVICE_STATE_FULLY_CHARGED; return DKP_DEVICE_STATE_UNKNOWN; } @@ -188,17 +187,17 @@ dkp_device_technology_from_text (const gchar *technology) { if (technology == NULL) return DKP_DEVICE_TECHNOLOGY_UNKNOWN; - if (egg_strequal (technology, "lithium-ion")) + if (g_strcmp0 (technology, "lithium-ion") == 0) return DKP_DEVICE_TECHNOLOGY_LITHIUM_ION; - if (egg_strequal (technology, "lithium-polymer")) + if (g_strcmp0 (technology, "lithium-polymer") == 0) return DKP_DEVICE_TECHNOLOGY_LITHIUM_POLYMER; - if (egg_strequal (technology, "lithium-iron-phosphate")) + if (g_strcmp0 (technology, "lithium-iron-phosphate") == 0) return DKP_DEVICE_TECHNOLOGY_LITHIUM_IRON_PHOSPHATE; - if (egg_strequal (technology, "lead-acid")) + if (g_strcmp0 (technology, "lead-acid") == 0) return DKP_DEVICE_TECHNOLOGY_LEAD_ACID; - if (egg_strequal (technology, "nickel-cadmium")) + if (g_strcmp0 (technology, "nickel-cadmium") == 0) return DKP_DEVICE_TECHNOLOGY_NICKEL_CADMIUM; - if (egg_strequal (technology, "nickel-metal-hydride")) + if (g_strcmp0 (technology, "nickel-metal-hydride") == 0) return DKP_DEVICE_TECHNOLOGY_NICKEL_METAL_HYDRIDE; return DKP_DEVICE_TECHNOLOGY_UNKNOWN; } @@ -222,9 +221,9 @@ dkp_qos_type_to_text (DkpQosType type) DkpQosType dkp_qos_type_from_text (const gchar *type) { - if (egg_strequal (type, "network")) + if (g_strcmp0 (type, "network") == 0) return DKP_QOS_TYPE_NETWORK; - if (egg_strequal (type, "cpu_dma")) + if (g_strcmp0 (type, "cpu_dma") == 0) return DKP_QOS_TYPE_CPU_DMA; return DKP_QOS_TYPE_UNKNOWN; } diff --git a/devkit-power-gobject/egg-string.c b/devkit-power-gobject/egg-string.c deleted file mode 120000 index 6ad7909..0000000 --- a/devkit-power-gobject/egg-string.c +++ /dev/null @@ -1 +0,0 @@ -../src/egg-string.c
\ No newline at end of file diff --git a/devkit-power-gobject/egg-string.h b/devkit-power-gobject/egg-string.h deleted file mode 120000 index d7e801b..0000000 --- a/devkit-power-gobject/egg-string.h +++ /dev/null @@ -1 +0,0 @@ -../src/egg-string.h
\ No newline at end of file diff --git a/src/dkp-csr.c b/src/dkp-csr.c index bace336..668a4fb 100644 --- a/src/dkp-csr.c +++ b/src/dkp-csr.c @@ -35,7 +35,6 @@ #include "sysfs-utils.h" #include "egg-debug.h" -#include "egg-string.h" #include "dkp-enum.h" #include "dkp-csr.h" @@ -148,9 +147,9 @@ dkp_csr_coldplug (DkpDevice *device) goto out; /* which one? */ - if (egg_strequal (type, "mouse")) + if (g_strcmp0 (type, "mouse") == 0) g_object_set (device, "type", DKP_DEVICE_TYPE_MOUSE, NULL); - else if (egg_strequal (type, "keyboard")) + else if (g_strcmp0 (type, "keyboard") == 0) g_object_set (device, "type", DKP_DEVICE_TYPE_KEYBOARD, NULL); else { egg_debug ("not a recognised csr device"); diff --git a/src/dkp-daemon.c b/src/dkp-daemon.c index 1d95f2f..fdcd21e 100644 --- a/src/dkp-daemon.c +++ b/src/dkp-daemon.c @@ -33,7 +33,6 @@ #include <devkit-gobject/devkit-gobject.h> #include "egg-debug.h" -#include "egg-string.h" #include "dkp-polkit.h" #include "dkp-daemon.h" @@ -430,7 +429,7 @@ gpk_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d) gboolean ret; subsys = devkit_device_get_subsystem (d); - if (egg_strequal (subsys, "power_supply")) { + if (g_strcmp0 (subsys, "power_supply") == 0) { /* are we a valid power supply */ device = DKP_DEVICE (dkp_supply_new ()); @@ -442,7 +441,7 @@ gpk_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d) /* no valid power supply object */ device = NULL; - } else if (egg_strequal (subsys, "tty")) { + } else if (g_strcmp0 (subsys, "tty") == 0) { /* try to detect a Watts Up? Pro monitor */ device = DKP_DEVICE (dkp_wup_new ()); @@ -454,7 +453,7 @@ gpk_daemon_device_get (DkpDaemon *daemon, DevkitDevice *d) /* no valid TTY object ;-( */ device = NULL; - } else if (egg_strequal (subsys, "usb")) { + } else if (g_strcmp0 (subsys, "usb") == 0) { /* see if this is a CSR mouse or keyboard */ device = DKP_DEVICE (dkp_csr_new ()); @@ -548,13 +547,13 @@ gpk_daemon_device_event_signal_handler (DevkitClient *client, const char *action { DkpDaemon *daemon = DKP_DAEMON (user_data); - if (egg_strequal (action, "add")) { + if (g_strcmp0 (action, "add") == 0) { egg_debug ("add %s", devkit_device_get_native_path (device)); gpk_daemon_device_add (daemon, device, TRUE); - } else if (egg_strequal (action, "remove")) { + } else if (g_strcmp0 (action, "remove") == 0) { egg_debug ("remove %s", devkit_device_get_native_path (device)); gpk_daemon_device_remove (daemon, device); - } else if (egg_strequal (action, "change")) { + } else if (g_strcmp0 (action, "change") == 0) { egg_debug ("change %s", devkit_device_get_native_path (device)); gpk_daemon_device_changed (daemon, device, FALSE); } else { diff --git a/src/dkp-device.c b/src/dkp-device.c index 03362f6..31711fc 100644 --- a/src/dkp-device.c +++ b/src/dkp-device.c @@ -36,7 +36,6 @@ #include "sysfs-utils.h" #include "egg-debug.h" -#include "egg-string.h" #include "dkp-supply.h" #include "dkp-device.h" @@ -525,9 +524,9 @@ dkp_device_get_statistics (DkpDevice *device, const gchar *type, DBusGMethodInvo } /* get the correct data */ - if (egg_strequal (type, "charging")) + if (g_strcmp0 (type, "charging") == 0) array = dkp_history_get_profile_data (device->priv->history, TRUE); - else if (egg_strequal (type, "discharging")) + else if (g_strcmp0 (type, "discharging") == 0) array = dkp_history_get_profile_data (device->priv->history, FALSE); /* maybe the device doesn't support histories */ @@ -590,13 +589,13 @@ dkp_device_get_history (DkpDevice *device, const gchar *type_string, guint times } /* get the correct data */ - if (egg_strequal (type_string, "rate")) + if (g_strcmp0 (type_string, "rate") == 0) type = DKP_HISTORY_TYPE_RATE; - else if (egg_strequal (type_string, "charge")) + else if (g_strcmp0 (type_string, "charge") == 0) type = DKP_HISTORY_TYPE_CHARGE; - else if (egg_strequal (type_string, "time-full")) + else if (g_strcmp0 (type_string, "time-full") == 0) type = DKP_HISTORY_TYPE_TIME_FULL; - else if (egg_strequal (type_string, "time-empty")) + else if (g_strcmp0 (type_string, "time-empty") == 0) type = DKP_HISTORY_TYPE_TIME_EMPTY; /* something recognised */ diff --git a/src/dkp-hid.c b/src/dkp-hid.c index afb3aea..901bd01 100644 --- a/src/dkp-hid.c +++ b/src/dkp-hid.c @@ -48,7 +48,6 @@ #include "sysfs-utils.h" #include "egg-debug.h" -#include "egg-string.h" #include "dkp-enum.h" #include "dkp-hid.h" @@ -299,7 +298,7 @@ dkp_hid_coldplug (DkpDevice *device) /* get the type */ type = devkit_device_get_property (d, "DKP_BATTERY_TYPE"); - if (type == NULL || !egg_strequal (type, "ups")) + if (type == NULL || g_strcmp0 (type, "ups") != 0) goto out; /* get the device file */ diff --git a/src/dkp-qos.c b/src/dkp-qos.c index df0e5b6..7ef0a54 100644 --- a/src/dkp-qos.c +++ b/src/dkp-qos.c @@ -33,7 +33,6 @@ #include <string.h> #include "egg-debug.h" -#include "egg-string.h" #include "dkp-qos.h" #include "dkp-marshal.h" @@ -379,7 +378,7 @@ dkp_qos_cancel_request (DkpQos *qos, guint cookie, DBusGMethodInvocation *contex } /* are we not the sender? */ - if (!egg_strequal (sender, obj->sender)) { + if (g_strcmp0 (sender, obj->sender) != 0) { caller = dkp_polkit_get_caller (qos->priv->polkit, context); if (caller == NULL) goto out; diff --git a/src/dkp-supply.c b/src/dkp-supply.c index c38ff93..5f0b934 100644 --- a/src/dkp-supply.c +++ b/src/dkp-supply.c @@ -34,7 +34,6 @@ #include "sysfs-utils.h" #include "egg-debug.h" -#include "egg-string.h" #include "dkp-enum.h" #include "dkp-supply.h" diff --git a/src/dkp-wakeups.c b/src/dkp-wakeups.c index 97b22a7..019c136 100644 --- a/src/dkp-wakeups.c +++ b/src/dkp-wakeups.c @@ -28,7 +28,6 @@ #include <stdio.h> #include "egg-debug.h" -#include "egg-string.h" #include "dkp-wakeups.h" #include "dkp-daemon.h" @@ -532,7 +531,7 @@ dkp_wakeups_poll_userspace_cb (DkpWakeups *wakeups) } else { /* try to get a better command line */ obj->cmdline = dkp_wakeups_get_cmdline (pid); - if (egg_strzero (obj->cmdline)) + if (obj->cmdline == NULL || obj->cmdline[0] == '\0') obj->cmdline = g_strdup (string); obj->is_userspace = TRUE; } diff --git a/src/dkp-wup.c b/src/dkp-wup.c index f97fe26..f5b27bf 100644 --- a/src/dkp-wup.c +++ b/src/dkp-wup.c @@ -42,7 +42,6 @@ #include "sysfs-utils.h" #include "egg-debug.h" -#include "egg-string.h" #include "dkp-enum.h" #include "dkp-wup.h" @@ -310,7 +309,7 @@ dkp_wup_coldplug (DkpDevice *device) /* get the type */ type = devkit_device_get_property (d, "DKP_MONITOR_TYPE"); - if (type == NULL || !egg_strequal (type, "wup")) + if (type == NULL || g_strcmp0 (type, "wup") != 0) goto out; /* get the device file */ diff --git a/src/egg-string.c b/src/egg-string.c deleted file mode 100644 index 2e860df..0000000 --- a/src/egg-string.c +++ /dev/null @@ -1,540 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com> - * - * Licensed under the GNU General Public License Version 2 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/** - * SECTION:pk-common - * @short_description: Common utility functions for PackageKit - * - * This file contains functions that may be useful. - */ - -#include "config.h" - -#include <stdlib.h> -#include <stdio.h> - -#include <string.h> -#include <sys/types.h> -#include <sys/utsname.h> -#include <sys/stat.h> - -#ifdef HAVE_UNISTD_H -#include <unistd.h> -#endif /* HAVE_UNISTD_H */ - -#include <glib.h> - -#include "egg-debug.h" -#include "egg-string.h" - -/** - * egg_strnumber: - * @text: The text the validate - * - * Tests a string to see if it is a number. Both positive and negative numbers - * are allowed. - * - * Return value: %TRUE if the string represents a numeric value - **/ -gboolean -egg_strnumber (const gchar *text) -{ - guint i; - guint length; - - /* check explicitly */ - if (egg_strzero (text)) - return FALSE; - - /* max length is 10 */ - length = egg_strlen (text, 10); - if (length == 10) { - egg_warning ("input too long: %s", text); - return FALSE; - } - - for (i=0; i<length; i++) { - if (i == 0 && text[i] == '-') { - /* negative sign */ - } else if (g_ascii_isdigit (text[i]) == FALSE) { - egg_warning ("not a number '%c' in text!", text[i]); - return FALSE; - } - } - return TRUE; -} - -/** - * egg_strtoint: - * @text: The text the convert - * @value: The return numeric return value, or 0 if invalid. - * - * Converts a string into a signed integer value in a safe way. - * - * Return value: %TRUE if the string was converted correctly - **/ -gboolean -egg_strtoint (const gchar *text, gint *value) -{ - gboolean ret; - ret = egg_strnumber (text); - if (!ret) { - *value = 0; - return FALSE; - } - /* ITS4: ignore, we've already checked for validity */ - *value = atoi (text); - return TRUE; -} - -/** - * egg_strtouint: - * @text: The text the convert - * @value: The return numeric return value, or 0 if invalid. - * - * Converts a string into a unsigned integer value in a safe way. - * - * Return value: %TRUE if the string was converted correctly - **/ -gboolean -egg_strtouint (const gchar *text, guint *value) -{ - gboolean ret; - gint temp; - ret = egg_strtoint (text, &temp); - if (ret == FALSE || temp < 0) { - *value = 0; - return FALSE; - } - *value = (guint) temp; - return TRUE; -} - -/** - * egg_strzero: - * @text: The text to check - * - * This function is a much safer way of doing "if (strlen (text) == 0))" - * as it does not rely on text being NULL terminated. It's also much - * quicker as it only checks the first byte rather than scanning the whole - * string just to verify it's not zero length. - * - * Return value: %TRUE if the string was converted correctly - **/ -gboolean -egg_strzero (const gchar *text) -{ - if (text == NULL) - return TRUE; - if (text[0] == '\0') - return TRUE; - return FALSE; -} - -/** - * egg_strlen: - * @text: The text to check - * @len: The maximum length of the string - * - * This function is a much safer way of doing strlen as it checks for NULL and - * a stupidly long string. - * - * Return value: the length of the string, or len if the string is too long. - **/ -guint -egg_strlen (const gchar *text, guint len) -{ - guint i; - - /* common case */ - if (text == NULL || text[0] == '\0') - return 0; - - /* only count up to len */ - for (i=1; i<len; i++) { - if (text[i] == '\0') - break; - } - return i; -} - -/** - * egg_strequal: - * @id1: the first item of text to test - * @id2: the second item of text to test - * - * This function is a much safer way of doing strcmp as it checks for - * NULL first, and returns boolean TRUE, not zero for success. - * - * Return value: %TRUE if the string are both non-%NULL and the same. - **/ -gboolean -egg_strequal (const gchar *id1, const gchar *id2) -{ - if (id1 == NULL || id2 == NULL) - return FALSE; - return (strcmp (id1, id2) == 0); -} - -/** - * egg_strvequal: - * @id1: the first item of text to test - * @id2: the second item of text to test - * - * This function will check to see if the GStrv arrays are string equal - * - * Return value: %TRUE if the arrays are the same, or are both %NULL - **/ -gboolean -egg_strvequal (gchar **id1, gchar **id2) -{ - guint i; - guint length1; - guint length2; - - if (id1 == NULL && id2 == NULL) - return TRUE; - - if (id1 == NULL || id2 == NULL) { - egg_debug ("GStrv compare invalid '%p' and '%p'", id1, id2); - return FALSE; - } - - /* check different sizes */ - length1 = g_strv_length (id1); - length2 = g_strv_length (id2); - if (length1 != length2) - return FALSE; - - /* text equal each one */ - for (i=0; i<length1; i++) { - if (!egg_strequal (id1[i], id2[i])) - return FALSE; - } - - return TRUE; -} - -/** - * egg_strreplace: - * @text: The input text to make safe - * @find: What to search for - * @replace: What to replace with - * - * Replaces chars in the text with a replacement. - * The %find and %replace variables to not have to be of the same length - * - * Return value: the new string (copied) - **/ -gchar * -egg_strreplace (const gchar *text, const gchar *find, const gchar *replace) -{ - gchar **array; - gchar *retval; - - /* common case, not found */ - if (strstr (text, find) == NULL) { - return g_strdup (text); - } - - /* split apart and rejoin with new delimiter */ - array = g_strsplit (text, find, 0); - retval = g_strjoinv (replace, array); - g_strfreev (array); - return retval; -} - -/*************************************************************************** - *** MAKE CHECK TESTS *** - ***************************************************************************/ -#ifdef EGG_TEST -#include "egg-test.h" - -void -egg_string_test (EggTest *test) -{ - gboolean ret; - gchar *text_safe; - const gchar *temp; - guint length; - gint value; - guint uvalue; - gchar **id1; - gchar **id2; - - if (!egg_test_start (test, "EggString")) - return; - - /************************************************************ - **************** String equal ****************** - ************************************************************/ - egg_test_title (test, "egg_strequal same argument"); - temp = "dave"; - if (egg_strequal (temp, temp)) - egg_test_success (test, NULL); - else - egg_test_failed (test, "incorrect ret when both same"); - - /************************************************************/ - egg_test_title (test, "egg_strequal both const"); - if (egg_strequal ("dave", "dave")) - egg_test_success (test, NULL); - else - egg_test_failed (test, "incorrect ret when both same"); - - /************************************************************ - **************** String array equal ****************** - ************************************************************/ - egg_test_title (test, "egg_strvequal same argument"); - id1 = g_strsplit ("the quick brown fox", " ", 0); - if (egg_strvequal (id1, id1)) - egg_test_success (test, NULL); - else - egg_test_failed (test, "incorrect ret when both same"); - g_strfreev (id1); - - /************************************************************/ - egg_test_title (test, "egg_strvequal same"); - id1 = g_strsplit ("the quick brown fox", " ", 0); - id2 = g_strsplit ("the quick brown fox", " ", 0); - if (egg_strvequal (id1, id2)) - egg_test_success (test, NULL); - else - egg_test_failed (test, "incorrect ret when both same"); - g_strfreev (id1); - g_strfreev (id2); - - /************************************************************/ - egg_test_title (test, "egg_strvequal different lengths"); - id1 = g_strsplit ("the quick brown", " ", 0); - id2 = g_strsplit ("the quick brown fox", " ", 0); - if (!egg_strvequal (id1, id2)) - egg_test_success (test, NULL); - else - egg_test_failed (test, "incorrect ret when both same"); - g_strfreev (id1); - g_strfreev (id2); - - /************************************************************/ - egg_test_title (test, "egg_strvequal different"); - id1 = g_strsplit ("the quick brown fox", " ", 0); - id2 = g_strsplit ("richard hughes maintainer dude", " ", 0); - if (!egg_strvequal (id1, id2)) - egg_test_success (test, NULL); - else - egg_test_failed (test, "same when different"); - g_strfreev (id1); - g_strfreev (id2); - - /************************************************************ - **************** Zero ****************** - ************************************************************/ - temp = NULL; - egg_test_title (test, "test strzero (null)"); - ret = egg_strzero (NULL); - if (ret) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed null"); - - /************************************************************/ - egg_test_title (test, "test strzero (null first char)"); - ret = egg_strzero (""); - if (ret) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed null"); - - /************************************************************/ - egg_test_title (test, "test strzero (long string)"); - ret = egg_strzero ("Richard"); - if (!ret) - egg_test_success (test, NULL); - else - egg_test_failed (test, "zero length word!"); - - /************************************************************/ - egg_test_title (test, "id strcmp pass"); - ret = egg_strequal ("moo;0.0.1;i386;fedora", "moo;0.0.1;i386;fedora"); - egg_test_assert (test, ret); - - /************************************************************/ - egg_test_title (test, "id strcmp fail"); - ret = egg_strequal ("moo;0.0.1;i386;fedora", "moo;0.0.2;i386;fedora"); - egg_test_assert (test, !ret); - - /************************************************************ - **************** strlen ****************** - ************************************************************/ - egg_test_title (test, "strlen bigger"); - length = egg_strlen ("123456789", 20); - if (length == 9) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the strlen %i", length); - - /************************************************************/ - egg_test_title (test, "strlen smaller"); - length = egg_strlen ("123456789", 5); - if (length == 5) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the strlen %i", length); - - /************************************************************/ - egg_test_title (test, "strlen correct"); - length = egg_strlen ("123456789", 9); - if (length == 9) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the strlen %i", length); - - /************************************************************ - **************** Replace ****************** - ************************************************************/ - egg_test_title (test, "replace start"); - text_safe = egg_strreplace ("richard\nhughes", "r", "e"); - if (egg_strequal (text_safe, "eichaed\nhughes")) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the replace '%s'", text_safe); - g_free (text_safe); - - /************************************************************/ - egg_test_title (test, "replace none"); - text_safe = egg_strreplace ("richard\nhughes", "dave", "e"); - if (egg_strequal (text_safe, "richard\nhughes")) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the replace '%s'", text_safe); - g_free (text_safe); - - /************************************************************/ - egg_test_title (test, "replace end"); - text_safe = egg_strreplace ("richard\nhughes", "s", "e"); - if (egg_strequal (text_safe, "richard\nhughee")) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the replace '%s'", text_safe); - g_free (text_safe); - - /************************************************************/ - egg_test_title (test, "replace unicode"); - text_safe = egg_strreplace ("richard\n- hughes", "\n- ", "\n• "); - if (egg_strequal (text_safe, "richard\n• hughes")) - egg_test_success (test, NULL); - else - egg_test_failed (test, "failed the replace '%s'", text_safe); - g_free (text_safe); - - /************************************************************ - ************** Check for numbers **************** - ************************************************************/ - egg_test_title (test, "check number valid"); - ret = egg_strnumber ("123"); - egg_test_assert (test, ret); - - /************************************************************/ - egg_test_title (test, "check number valid"); - ret = egg_strnumber ("-123"); - egg_test_assert (test, ret); - - /************************************************************/ - egg_test_title (test, "check number zero"); - ret = egg_strnumber ("0"); - egg_test_assert (test, ret); - - /************************************************************/ - egg_test_title (test, "check number oversize"); - ret = egg_strnumber ("123456891234"); - egg_test_assert (test, !ret); - - /************************************************************/ - egg_test_title (test, "check number NULL"); - ret = egg_strnumber (NULL); - egg_test_assert (test, !ret); - - /************************************************************/ - egg_test_title (test, "check number blank"); - ret = egg_strnumber (""); - egg_test_assert (test, !ret); - - /************************************************************/ - egg_test_title (test, "check number not negative"); - ret = egg_strnumber ("503-"); - egg_test_assert (test, !ret); - - /************************************************************/ - egg_test_title (test, "check number positive"); - ret = egg_strnumber ("+503"); - egg_test_assert (test, !ret); - - /************************************************************/ - egg_test_title (test, "check number random chars"); - ret = egg_strnumber ("dave"); - egg_test_assert (test, !ret); - - /************************************************************ - ************** Convert numbers **************** - ************************************************************/ - egg_test_title (test, "convert valid number"); - ret = egg_strtoint ("234", &value); - if (ret && value == 234) - egg_test_success (test, NULL); - else - egg_test_failed (test, "value is %i", value); - - /************************************************************/ - egg_test_title (test, "convert negative valid number"); - ret = egg_strtoint ("-234", &value); - if (ret && value == -234) - egg_test_success (test, NULL); - else - egg_test_failed (test, "value is %i", value); - - /************************************************************/ - egg_test_title (test, "don't convert invalid number"); - ret = egg_strtoint ("dave", &value); - if (ret == FALSE && value == 0) - egg_test_success (test, NULL); - else - egg_test_failed (test, "value is %i", value); - - /************************************************************/ - egg_test_title (test, "convert valid uint number"); - ret = egg_strtouint ("234", &uvalue); - if (ret && uvalue == 234) - egg_test_success (test, NULL); - else - egg_test_failed (test, "value is %i", uvalue); - - /************************************************************/ - egg_test_title (test, "convert invalid uint number"); - ret = egg_strtouint ("-234", &uvalue); - if (ret == FALSE && uvalue == 0) - egg_test_success (test, NULL); - else - egg_test_failed (test, "value is %i", uvalue); - - egg_test_end (test); -} -#endif - diff --git a/src/egg-string.h b/src/egg-string.h deleted file mode 100644 index 5414907..0000000 --- a/src/egg-string.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- - * - * Copyright (C) 2007-2008 Richard Hughes <richard@hughsie.com> - * - * Licensed under the GNU General Public License Version 2 - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef __EGG_STRING_H -#define __EGG_STRING_H - -#include <glib.h> - -G_BEGIN_DECLS - -guint egg_strlen (const gchar *text, - guint len) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strzero (const gchar *text) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strequal (const gchar *id1, - const gchar *id2) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strvequal (gchar **id1, - gchar **id2) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strnumber (const gchar *text) - G_GNUC_WARN_UNUSED_RESULT; -gboolean egg_strtoint (const gchar *text, - gint *value); -gboolean egg_strtouint (const gchar *text, - guint *value); -gchar *egg_strreplace (const gchar *text, - const gchar *find, - const gchar *replace); - -G_END_DECLS - -#endif /* __EGG_STRING_H */ |