Change string_collate() so NULL and empty strings are equal.
This commit is contained in:
parent
4bb4304683
commit
df8c954331
@ -1029,7 +1029,7 @@ ag_db_get_chart_data_by_id(AgDb *db, guint row_id, GError **err)
|
|||||||
* @str2: the second string
|
* @str2: the second string
|
||||||
*
|
*
|
||||||
* A wrapper function around g_utf8_collate() that can handle NULL values. NULL
|
* A wrapper function around g_utf8_collate() that can handle NULL values. NULL
|
||||||
* precedes any strings (even "").
|
* and empty strings ("") are considered equal.
|
||||||
*
|
*
|
||||||
* Returns: -1 if str1 is ordered before str2, 1 if str2 comes first, or 0 if
|
* Returns: -1 if str1 is ordered before str2, 1 if str2 comes first, or 0 if
|
||||||
* they are identical
|
* they are identical
|
||||||
@ -1037,6 +1037,13 @@ ag_db_get_chart_data_by_id(AgDb *db, guint row_id, GError **err)
|
|||||||
static gint
|
static gint
|
||||||
string_collate(const gchar *str1, const gchar *str2)
|
string_collate(const gchar *str1, const gchar *str2)
|
||||||
{
|
{
|
||||||
|
if (
|
||||||
|
((str1 == NULL) && str2 && (*str2 == '\0'))
|
||||||
|
|| (str1 && (*str1 == '\0') && (str2 == NULL))
|
||||||
|
) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (((str1 == NULL) || (str2 == NULL)) && (str1 != str2)) {
|
if (((str1 == NULL) || (str2 == NULL)) && (str1 != str2)) {
|
||||||
return (str1 == NULL) ? -1 : 1;
|
return (str1 == NULL) ? -1 : 1;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user