[gnome-color-manager] Add gcm_utils_ensure_sensible_filename() and allow more chars than the alphanum_lcase
- From: Richard Hughes <rhughes src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gnome-color-manager] Add gcm_utils_ensure_sensible_filename() and allow more chars than the alphanum_lcase
- Date: Thu, 3 Dec 2009 11:14:06 +0000 (UTC)
commit 172702934e693e6863a51fd9a73fb266ce676b33
Author: Richard Hughes <richard hughsie com>
Date: Thu Dec 3 11:01:41 2009 +0000
Add gcm_utils_ensure_sensible_filename() and allow more chars than the alphanum_lcase
src/gcm-calibrate.c | 2 +-
src/gcm-utils.c | 36 +++++++++++++++++++++++++++++++++++-
src/gcm-utils.h | 1 +
3 files changed, 37 insertions(+), 2 deletions(-)
---
diff --git a/src/gcm-calibrate.c b/src/gcm-calibrate.c
index a39b2a8..0156fa1 100644
--- a/src/gcm-calibrate.c
+++ b/src/gcm-calibrate.c
@@ -391,7 +391,7 @@ gcm_calibrate_display_neutralise (GcmCalibrate *calibrate, GError **error)
type = gcm_calibrate_get_display_type (calibrate);
/* make a suitable filename */
- gcm_utils_alphanum_lcase (priv->basename);
+ gcm_utils_ensure_sensible_filename (priv->basename);
egg_debug ("using filename basename of %s", priv->basename);
/* argument array */
diff --git a/src/gcm-utils.c b/src/gcm-utils.c
index 4172f48..63d3d12 100644
--- a/src/gcm-utils.c
+++ b/src/gcm-utils.c
@@ -580,6 +580,30 @@ gcm_utils_alphanum_lcase (gchar *data)
}
/**
+ * gcm_utils_ensure_sensible_filename:
+ **/
+void
+gcm_utils_ensure_sensible_filename (gchar *data)
+{
+ guint i;
+
+ g_return_if_fail (data != NULL);
+
+ /* replace unsafe chars, and make lowercase */
+ for (i=0; data[i] != '\0'; i++) {
+ if (data[i] != ' ' &&
+ data[i] != '-' &&
+ data[i] != '(' &&
+ data[i] != ')' &&
+ data[i] != '[' &&
+ data[i] != ']' &&
+ data[i] != ',' &&
+ !g_ascii_isalnum (data[i]))
+ data[i] = '_';
+ }
+}
+
+/**
* gcm_utils_get_default_config_location:
**/
gchar *
@@ -650,7 +674,7 @@ gcm_utils_test (EggTest *test)
egg_test_assert (test, ret);
/************************************************************/
- egg_test_title (test, "Make sensible filename");
+ egg_test_title (test, "Make sensible id");
filename = g_strdup ("Hello\n\rWorld!");
gcm_utils_alphanum_lcase (filename);
if (g_strcmp0 (filename, "hello__world_") == 0)
@@ -660,6 +684,16 @@ gcm_utils_test (EggTest *test)
g_free (filename);
/************************************************************/
+ egg_test_title (test, "Make sensible filename");
+ filename = g_strdup ("Hel lo\n\rWo-(r)ld!");
+ gcm_utils_ensure_sensible_filename (filename);
+ if (g_strcmp0 (filename, "Hel lo__Wo-(r)ld_") == 0)
+ egg_test_success (test, NULL);
+ else
+ egg_test_failed (test, "failed to get filename: %s", filename);
+ g_free (filename);
+
+ /************************************************************/
egg_test_title (test, "get default config location (when in make check)");
filename = gcm_utils_get_default_config_location ();
if (g_strcmp0 (filename, "/tmp/device-profiles.conf") == 0)
diff --git a/src/gcm-utils.h b/src/gcm-utils.h
index f946af5..2447675 100644
--- a/src/gcm-utils.h
+++ b/src/gcm-utils.h
@@ -47,6 +47,7 @@ gboolean gcm_gnome_help (const gchar *link_id);
gboolean gcm_utils_output_is_lcd_internal (const gchar *output_name);
gboolean gcm_utils_output_is_lcd (const gchar *output_name);
void gcm_utils_alphanum_lcase (gchar *string);
+void gcm_utils_ensure_sensible_filename (gchar *string);
gchar *gcm_utils_get_default_config_location (void);
#endif /* __GCM_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]