]>
git.saurik.com Git - apple/libc.git/blob - string/wcscoll-fbsd.c
ce09e41fd9d2f68518e58d6326f1c1c435d8c31a
2 * Copyright (c) 2002 Tim J. Robbins
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/cdefs.h>
28 __FBSDID("$FreeBSD: src/lib/libc/string/wcscoll.c,v 1.3 2004/04/07 09:47:56 tjr Exp $");
30 #include "xlocale_private.h"
38 #define NOTFORWARD (DIRECTIVE_BACKWARD | DIRECTIVE_POSITION)
41 wcscoll_l(const wchar_t *ws1
, const wchar_t *ws2
, locale_t loc
)
44 int len
, len2
, prim
, prim2
, sec
, sec2
, ret
, ret2
;
45 const wchar_t *t
, *t2
;
46 wchar_t *tt
= NULL
, *tt2
= NULL
;
47 wchar_t *tr
= NULL
, *tr2
= NULL
;
49 struct __collate_st_info
*info
;
51 NORMALIZE_LOCALE(loc
);
52 if (loc
->__collate_load_error
)
54 * Locale has no special collating order or could not be
55 * loaded, do a fast binary comparison.
57 return (wcscmp(ws1
, ws2
));
59 info
= &loc
->__lc_collate
->__info
;
63 if ((info
->directive
[0] & NOTFORWARD
) ||
64 (info
->directive
[1] & NOTFORWARD
) ||
65 (!(info
->flags
&& COLLATE_SUBST_DUP
) &&
66 (info
->subst_count
[0] > 0 || info
->subst_count
[1] > 0))) {
68 for(pass
= 0; pass
< info
->directive_count
; pass
++) {
69 direc
= info
->directive
[pass
];
70 if (pass
== 0 || !(info
->flags
& COLLATE_SUBST_DUP
)) {
72 tt
= __collate_substitute(ws1
, pass
, loc
);
74 tt2
= tt
? __collate_substitute(ws2
, pass
, loc
) : NULL
;
76 if (direc
& DIRECTIVE_BACKWARD
) {
78 tr
= __collate_wcsdup(tt
? tt
: ws1
);
80 fp
= tr
+ wcslen(tr
) - 1;
86 tr2
= __collate_wcsdup(tt2
? tt2
: ws2
);
88 fp
= tr2
+ wcslen(tr2
) - 1;
94 t
= (const wchar_t *)tr
;
95 t2
= (const wchar_t *)tr2
;
97 t
= (const wchar_t *)tt
;
98 t2
= (const wchar_t *)tt2
;
100 t
= (const wchar_t *)ws1
;
101 t2
= (const wchar_t *)ws2
;
103 if(direc
& DIRECTIVE_POSITION
) {
106 __collate_lookup_which(t
, &len
, &prim
, pass
, loc
);
113 prim
= COLLATE_MAX_PRIORITY
;
115 __collate_lookup_which(t2
, &len2
, &prim2
, pass
, loc
);
122 prim2
= COLLATE_MAX_PRIORITY
;
135 __collate_lookup_which(t
, &len
, &prim
, pass
, loc
);
146 __collate_lookup_which(t2
, &len2
, &prim2
, pass
, loc
);
180 /* optimized common case: order_start forward;forward and duplicate
181 * (or no) substitute tables */
182 tt
= __collate_substitute(ws1
, 0, loc
);
185 t
= (const wchar_t *)ws1
;
186 t2
= (const wchar_t *)ws2
;
188 tt2
= __collate_substitute(ws2
, 0, loc
);
189 t
= (const wchar_t *)tt
;
190 t2
= (const wchar_t *)tt2
;
195 __collate_lookup_l(t
, &len
, &prim
, &sec
, loc
);
206 __collate_lookup_l(t2
, &len2
, &prim2
, &sec2
, loc
);
245 wcscoll(const wchar_t *ws1
, const wchar_t *ws2
)
247 return wcscoll_l(ws1
, ws2
, __current_locale());