@@ -53,23 +53,24 @@ inline const void* tMemsrch(const void* haystack, int haystackNumBytes, const vo
53
53
// straight UTF conversions (not null-terminated). String termination is not part of UTF, but it's common to support it.
54
54
// Null-terminated versions of the functions have an 's' appended. The 'c' versions are for dealing with individual
55
55
// codepoints. Note these functions return exactly -1 if a < b, 0 if equal, and 1 if a > b. This is in contrast to the
56
- // standard strcmp functions that only guarantee returning < 0, 0, or > 0. That is, implementations are free to return
57
- // either the ASCII difference of the strings or normalize the returns to -1, 0, 1.
56
+ // standard strcmp functions that only guarantee returning < 0, 0, or > 0. That is, standard implementations are free to
57
+ // return either the ASCII difference of the strings or normalize the returns to -1, 0, 1, but it's not helpful as you
58
+ // can't be sure of which choice an implementation may have made.
58
59
const int tCharInvalid = 0xFF ;
59
60
inline int tStrcmp (const char * a, const char * b) { tAssert (a && b); int r = strcmp (a, b); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
61
+ inline int tStrcmp (const char8_t * a, const char8_t * b) { return tStrcmp ((const char *)a, (const char *)b); }
60
62
inline int tStrncmp (const char * a, const char * b, int n) { tAssert (a && b && n >= 0 ); int r = strncmp (a, b, n); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
61
- inline int tStrcmp (const char8_t * a, const char8_t * b) { tAssert (a && b); int r = strcmp ((const char *)a, (const char *)b); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
62
- inline int tStrncmp (const char8_t * a, const char8_t * b, int n) { tAssert (a && b && n >= 0 ); int r = strncmp ((const char *)a, (const char *)b, n); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
63
+ inline int tStrncmp (const char8_t * a, const char8_t * b, int n) { return tStrncmp ((const char *)a, (const char *)b, n); }
63
64
#if defined(PLATFORM_WINDOWS)
64
65
inline int tStricmp (const char * a, const char * b) { tAssert (a && b); int r = stricmp (a, b); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
66
+ inline int tStricmp (const char8_t * a, const char8_t * b) { return tStricmp ((const char *)a, (const char *)b); }
65
67
inline int tStrnicmp (const char * a, const char * b, int n) { tAssert (a && b && n >= 0 ); int r = strnicmp (a, b, n); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
66
- inline int tStricmp (const char8_t * a, const char8_t * b) { tAssert (a && b); int r = stricmp ((const char *)a, (const char *)b); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
67
- inline int tStrnicmp (const char8_t * a, const char8_t * b, int n) { tAssert (a && b && n >= 0 ); int r = strnicmp ((const char *)a, (const char *)b, n); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
68
+ inline int tStrnicmp (const char8_t * a, const char8_t * b, int n) { return tStrnicmp ((const char *)a, (const char *)b, n); }
68
69
#else
69
70
inline int tStricmp (const char * a, const char * b) { tAssert (a && b); int r = strcasecmp (a, b); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
71
+ inline int tStricmp (const char8_t * a, const char8_t * b) { return tStricmp ((const char *)a, (const char *)b); }
70
72
inline int tStrnicmp (const char * a, const char * b, int n) { tAssert (a && b && n >= 0 ); int r = strncasecmp (a, b, n); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
71
- inline int tStricmp (const char8_t * a, const char8_t * b) { tAssert (a && b); int r = strcasecmp ((const char *)a, (const char *)b); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
72
- inline int tStrnicmp (const char8_t * a, const char8_t * b, int n) { tAssert (a && b && n >= 0 ); int r = strncasecmp ((const char *)a, (const char *)b, n); return (r < 0 ) ? -1 : ((r > 0 ) ? 1 : 0 ); }
73
+ inline int tStrnicmp (const char8_t * a, const char8_t * b, int n) { return tStrnicmp ((const char *)a, (const char *)b, n); }
73
74
#endif
74
75
75
76
// These are similar to the above but assume the strings represent filesystem paths and so choose between a case
@@ -80,6 +81,12 @@ int tPstrncmp(const char* a, const char* b, int n);
80
81
int tPstrcmp (const char8_t * a, const char8_t * b);
81
82
int tPstrncmp (const char8_t * a, const char8_t * b, int n);
82
83
84
+ // These do a 'natural' string compare by treating groups of base 10 digits as separate objects to be compared by
85
+ // numeric value rather than alpha-numerically based on the encoding. This results in strings like "page10" coming
86
+ // after "page2" because 10 > 2.
87
+ int tNstrcmp (const char * a, const char * b);
88
+ inline int tNstrcmp (const char8_t * a, const char8_t * b) { return tNstrcmp ((const char *)a, (const char *)b); }
89
+
83
90
inline int tStrlen (const char * s) { tAssert (s); return int (strlen (s)); }
84
91
inline constexpr int tStrlenCT (const char * s) { return *s ? 1 + tStrlenCT (s + 1 ) : 0 ; }
85
92
inline char * tStrcpy (char * dst, const char * src) { tAssert (dst && src); return strcpy (dst, src); }
0 commit comments