libgimpbase: add gboolean gimp_is_canonical_identifier()

This commit is contained in:
Michael Natterer 2019-08-05 23:22:06 +02:00
parent 550ec68cff
commit 2f3a83754f
3 changed files with 48 additions and 4 deletions

View File

@ -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

View File

@ -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,9 +702,11 @@ gimp_canonicalize_identifier (const gchar *identifier)
(c < '0' || c > '9') &&
(c < 'A' || c > 'Z') &&
(c < 'a' || c > 'z'))
{
*p = '-';
}
}
}
return canonicalized;
}

View File

@ -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,