[gimp] libgimpbase: add gboolean gimp_is_canonical_identifier()
- From: Michael Natterer <mitch src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gimp] libgimpbase: add gboolean gimp_is_canonical_identifier()
- Date: Mon, 5 Aug 2019 21:23:41 +0000 (UTC)
commit 2f3a83754fbe2565151b9ee06c2151b2a0ed7d33
Author: Michael Natterer <mitch gimp org>
Date: Mon Aug 5 23:22:06 2019 +0200
libgimpbase: add gboolean gimp_is_canonical_identifier()
libgimpbase/gimpbase.def | 1 +
libgimpbase/gimputils.c | 50 ++++++++++++++++++++++++++++++++++++++++++++----
libgimpbase/gimputils.h | 1 +
3 files changed, 48 insertions(+), 4 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 82c711dd49..f6728b0f4a 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -73,6 +73,7 @@ EXPORTS
gimp_int8_array_get_type
gimp_int8_get_type
gimp_interpolation_type_get_type
+ gimp_is_canonical_identifier
gimp_join_style_get_type
gimp_locale_directory
gimp_locale_directory_file
diff --git a/libgimpbase/gimputils.c b/libgimpbase/gimputils.c
index 0f55be4ae7..4a3c8f3a87 100644
--- a/libgimpbase/gimputils.c
+++ b/libgimpbase/gimputils.c
@@ -627,6 +627,46 @@ gimp_escape_uline (const gchar *str)
return escaped;
}
+/**
+ * gimp_is_canonical_identifier:
+ * @identifier: The identifier string to check.
+ *
+ * Checks if @identifier is canonical and non-%NULL.
+ *
+ * Canonical identifiers are e.g. expected by the PDB for procedure
+ * and parameter names. Every character of the input string must be
+ * either '-', 'a-z', 'A-Z' or '0-9'.
+ *
+ * Returns: %TRUE if @identifier is canonical, %FALSE otherwise.
+ *
+ * Since: 3.0
+ **/
+gboolean
+gimp_is_canonical_identifier (const gchar *identifier)
+{
+ if (identifier)
+ {
+ const gchar *p;
+
+ for (p = identifier; *p != 0; p++)
+ {
+ const gchar c = *p;
+
+ if (! (c == '-' ||
+ (c >= '0' && c <= '9') ||
+ (c >= 'A' && c <= 'Z') ||
+ (c >= 'a' && c <= 'z')))
+ {
+ return FALSE;
+ }
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
/**
* gimp_canonicalize_identifier:
* @identifier: The identifier string to canonicalize.
@@ -637,9 +677,9 @@ gimp_escape_uline (const gchar *str)
* and parameter names. Every character of the input string that is
* not either '-', 'a-z', 'A-Z' or '0-9' will be replaced by a '-'.
*
- * Returns: The canonicalized identifier. This is a newly
- * allocated string that should be freed with g_free()
- * when no longer needed.
+ * Returns: The canonicalized identifier. This is a newly allocated
+ * string that should be freed with g_free() when no longer
+ * needed.
*
* Since: 2.4
**/
@@ -662,7 +702,9 @@ gimp_canonicalize_identifier (const gchar *identifier)
(c < '0' || c > '9') &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z'))
- *p = '-';
+ {
+ *p = '-';
+ }
}
}
diff --git a/libgimpbase/gimputils.h b/libgimpbase/gimputils.h
index ca7b730dcc..dcfb9dad6f 100644
--- a/libgimpbase/gimputils.h
+++ b/libgimpbase/gimputils.h
@@ -43,6 +43,7 @@ gboolean gimp_file_show_in_file_manager (GFile *file,
gchar * gimp_strip_uline (const gchar *str) G_GNUC_MALLOC;
gchar * gimp_escape_uline (const gchar *str) G_GNUC_MALLOC;
+gboolean gimp_is_canonical_identifier (const gchar *identifier);
gchar * gimp_canonicalize_identifier (const gchar *identifier) G_GNUC_MALLOC;
GimpEnumDesc * gimp_enum_get_desc (GEnumClass *enum_class,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]