forked from osmocom/wireshark
Rename the strnatcmp.c routines and make them use the g_ascii_XXX() routines.
Rename strnatcmp()/strnatcasecmp() to ws_ascii_XXX(), and make them use the g_ascii_XXX() routines rather than ctype.h routines, to eliminate locale-dependent behavior. (If you want locale-dependent "natural order" sorting, you probably want "dictionary order" sorting, which is more complicated than just natural order sorting.) Change-Id: I837f2776b2a909b547dc9a6072e497911b5380e5 Reviewed-on: https://code.wireshark.org/review/4985 Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
parent
d2f4b6fd3d
commit
4acf4955f5
|
@ -800,7 +800,7 @@ string_compare(gconstpointer a, gconstpointer b)
|
|||
static gint
|
||||
string_nat_compare(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return strnatcmp(((const struct string_elem *)a)->sstr,
|
||||
return ws_ascii_strnatcmp(((const struct string_elem *)a)->sstr,
|
||||
((const struct string_elem *)b)->sstr);
|
||||
}
|
||||
|
||||
|
|
|
@ -149,8 +149,8 @@ string_compare(gconstpointer a, gconstpointer b)
|
|||
static gint
|
||||
string_nat_compare(gconstpointer a, gconstpointer b)
|
||||
{
|
||||
return strnatcmp(((const struct string_elem *)a)->sstr,
|
||||
((const struct string_elem *)b)->sstr);
|
||||
return ws_ascii_strnatcmp(((const struct string_elem *)a)->sstr,
|
||||
((const struct string_elem *)b)->sstr);
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -32,10 +32,17 @@
|
|||
* negative chars in their default char type.
|
||||
*/
|
||||
|
||||
#include <ctype.h>
|
||||
/*
|
||||
* Modified 2014-10-29 to use the g_ascii_XXX() routines; this avoids
|
||||
* locale-dependent behavior. The routine names were changed to
|
||||
* ws_ascii_XXX() to reflect this.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "strnatcmp.h"
|
||||
|
||||
|
||||
|
@ -44,21 +51,21 @@
|
|||
static int
|
||||
nat_isdigit(nat_char a)
|
||||
{
|
||||
return isdigit((unsigned char) a);
|
||||
return g_ascii_isdigit(a);
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
nat_isspace(nat_char a)
|
||||
{
|
||||
return isspace((unsigned char) a);
|
||||
return g_ascii_isspace(a);
|
||||
}
|
||||
|
||||
|
||||
static nat_char
|
||||
nat_toupper(nat_char a)
|
||||
{
|
||||
return toupper((unsigned char) a);
|
||||
return g_ascii_toupper(a);
|
||||
}
|
||||
|
||||
|
||||
|
@ -172,14 +179,14 @@ static int strnatcmp0(nat_char const *a, nat_char const *b, int fold_case)
|
|||
}
|
||||
|
||||
|
||||
int strnatcmp(nat_char const *a, nat_char const *b)
|
||||
int ws_ascii_strnatcmp(nat_char const *a, nat_char const *b)
|
||||
{
|
||||
return strnatcmp0(a, b, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Compare, recognizing numeric string and ignoring case. */
|
||||
int strnatcasecmp(nat_char const *a, nat_char const *b)
|
||||
int ws_ascii_strnatcasecmp(nat_char const *a, nat_char const *b)
|
||||
{
|
||||
return strnatcmp0(a, b, 1);
|
||||
}
|
||||
|
|
|
@ -37,8 +37,8 @@ extern "C" {
|
|||
* functions in strnatcmp.c */
|
||||
typedef char nat_char;
|
||||
|
||||
WS_DLL_PUBLIC int strnatcmp(nat_char const *a, nat_char const *b);
|
||||
WS_DLL_PUBLIC int strnatcasecmp(nat_char const *a, nat_char const *b);
|
||||
WS_DLL_PUBLIC int ws_ascii_strnatcmp(nat_char const *a, nat_char const *b);
|
||||
WS_DLL_PUBLIC int ws_ascii_strnatcasecmp(nat_char const *a, nat_char const *b);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue