version 1.7, 2015/04/01 22:38:08 |
version 1.8, 2019/05/15 09:07:46 |
|
|
#include "bwstring.h" |
#include "bwstring.h" |
#include "sort.h" |
#include "sort.h" |
|
|
bool byte_sort; |
|
size_t sort_mb_cur_max = 1; |
|
|
|
static wchar_t **wmonths; |
static wchar_t **wmonths; |
static char **cmonths; |
static char **cmonths; |
|
|
|
|
|
|
if (len1 <= offset) |
if (len1 <= offset) |
return (len2 <= offset) ? 0 : -1; |
return (len2 <= offset) ? 0 : -1; |
else { |
|
if (len2 <= offset) |
if (len2 <= offset) |
return 1; |
return 1; |
else { |
|
len1 -= offset; |
len1 -= offset; |
len2 -= offset; |
len2 -= offset; |
|
|
if (sort_mb_cur_max == 1) { |
if (sort_mb_cur_max == 1) { |
const unsigned char *s1, *s2; |
const unsigned char *s1, *s2; |
|
int res; |
|
|
s1 = bws1->data.cstr + offset; |
s1 = bws1->data.cstr + offset; |
s2 = bws2->data.cstr + offset; |
s2 = bws2->data.cstr + offset; |
|
|
if (byte_sort) { |
|
int res = 0; |
|
|
|
if (len1 > len2) { |
if (len1 > len2) { |
res = memcmp(s1, s2, len2); |
res = memcmp(s1, s2, len2); |
if (!res) |
if (!res) |
|
|
res = memcmp(s1, s2, len1); |
res = memcmp(s1, s2, len1); |
|
|
return res; |
return res; |
|
|
} else { |
|
int res = 0; |
|
size_t i, maxlen; |
|
|
|
i = 0; |
|
maxlen = len1; |
|
|
|
if (maxlen > len2) |
|
maxlen = len2; |
|
|
|
while (i < maxlen) { |
|
/* goto next non-zero part: */ |
|
while ((i < maxlen) && |
|
!s1[i] && !s2[i]) |
|
++i; |
|
|
|
if (i >= maxlen) |
|
break; |
|
|
|
if (s1[i] == 0) { |
|
if (s2[i] == 0) |
|
/* NOTREACHED */ |
|
err(2, "bwscoll error 01"); |
|
else |
|
return -1; |
|
} else if (s2[i] == 0) |
|
return 1; |
|
|
|
res = strcoll((const char *)(s1 + i), (const char *)(s2 + i)); |
|
if (res) |
|
return res; |
|
|
|
while ((i < maxlen) && |
|
s1[i] && s2[i]) |
|
++i; |
|
|
|
if (i >= maxlen) |
|
break; |
|
|
|
if (s1[i] == 0) { |
|
if (s2[i] == 0) { |
|
++i; |
|
continue; |
|
} else |
|
return -1; |
|
} else if (s2[i] == 0) |
|
return 1; |
|
else |
|
/* NOTREACHED */ |
|
err(2, "bwscoll error 02"); |
|
} |
|
|
|
if (len1 < len2) |
|
return -1; |
|
else if (len1 > len2) |
|
return 1; |
|
|
|
return 0; |
|
} |
|
} else { |
} else { |
const wchar_t *s1, *s2; |
const wchar_t *s1, *s2; |
size_t i, maxlen; |
size_t i, maxlen; |
|
|
return 0; |
return 0; |
return len1 < len2 ? -1 : 1; |
return len1 < len2 ? -1 : 1; |
} |
} |
} |
|
} |
|
} |
} |
|
|
/* |
/* |