summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorache <ache@FreeBSD.org>1996-06-09 14:56:08 +0000
committerache <ache@FreeBSD.org>1996-06-09 14:56:08 +0000
commitec6853868b71426ea726e839f93e1cc8f3c5b761 (patch)
treeb328dc5a7b9ebe2656d1aaacc4c7a2a0c75a8664 /lib
parent2fe7739b977266bf3a61a8078e5a5ffb70b3cc6d (diff)
downloadFreeBSD-src-ec6853868b71426ea726e839f93e1cc8f3c5b761.zip
FreeBSD-src-ec6853868b71426ea726e839f93e1cc8f3c5b761.tar.gz
Use better approximation if collate info not available.
Fix bug: strxfrm+strcmp != strcoll, if collate info not available
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/string/strcoll.311
-rw-r--r--lib/libc/string/strcoll.c22
-rw-r--r--lib/libc/string/strxfrm.c24
3 files changed, 41 insertions, 16 deletions
diff --git a/lib/libc/string/strcoll.3 b/lib/libc/string/strcoll.3
index 08f48ad..c81762e 100644
--- a/lib/libc/string/strcoll.3
+++ b/lib/libc/string/strcoll.3
@@ -53,13 +53,10 @@ lexicographically compares the null-terminated strings
.Fa s1
and
.Fa s2
-according to the current locale collation if any, otherwise call
-.Fa strcmp ,
-and returns an integer greater than, equal to, or less than 0,
-according as
-.Fa s1
-is greater than, equal to, or less than
-.Fa s2 .
+according to the current locale collation if any, otherwise some
+approximation procedure is used based on available
+.Xr ctype 3
+information.
.Sh SEE ALSO
.Xr setlocale 3 ,
.Xr strcmp 3 ,
diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c
index 915e649..c8fff23 100644
--- a/lib/libc/string/strcoll.c
+++ b/lib/libc/string/strcoll.c
@@ -24,11 +24,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: strcoll.c,v 1.3 1995/02/18 01:38:58 ache Exp $
+ * $Id: strcoll.c,v 1.4 1995/04/16 22:43:45 ache Exp $
*/
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "collate.h"
int
@@ -38,8 +39,23 @@ strcoll(s, s2)
int len, len2, prim, prim2, sec, sec2, ret, ret2;
char *tt, *t, *tt2, *t2;
- if (__collate_load_error)
- return strcasecmp(s, s2);
+ if (__collate_load_error) {
+ register const u_char
+ *us1 = (const u_char *)s,
+ *us2 = (const u_char *)s2;
+
+ while (tolower(*us1) == tolower(*us2)) {
+ if (*us1 == '\0')
+ return (0);
+ if (isupper(*us1) && islower(*us2))
+ return (-1);
+ else if (islower(*us1) && isupper(*us2))
+ return (1);
+ *us1++;
+ *us2++;
+ }
+ return (tolower(*us1) - tolower(*us2));
+ }
len = len2 = 1;
ret = ret2 = 0;
diff --git a/lib/libc/string/strxfrm.c b/lib/libc/string/strxfrm.c
index eb02c13..236c3ac 100644
--- a/lib/libc/string/strxfrm.c
+++ b/lib/libc/string/strxfrm.c
@@ -24,11 +24,12 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $Id: strxfrm.c,v 1.3 1995/02/18 01:39:00 ache Exp $
+ * $Id: strxfrm.c,v 1.4 1995/02/18 11:36:33 ache Exp $
*/
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include "collate.h"
size_t
@@ -50,14 +51,25 @@ strxfrm(dest, src, len)
if (__collate_load_error) {
size_t slen = strlen(src);
+ u_char *us;
- if (slen < len) {
+ if (slen < len)
strcpy(d, src);
- return slen;
+ else {
+ slen = len - 1;
+ strncpy(d, src, slen);
+ d[slen] = '\0';
}
- strncpy(d, src, len - 1);
- d[len - 1] = '\0';
- return len - 1;
+ for (us = d; *us; us++) {
+ if (isupper(*us)) {
+ if (tolower(*us) < *us)
+ *us = tolower(*us) - 1;
+ /* assume it not started from 0 */
+ else
+ *us = tolower(*us);
+ }
+ }
+ return slen;
}
ss = s = __collate_substitute(src);
OpenPOWER on IntegriCloud