117530Sache/*
217530Sache * Copyright (C) 1996 by Andrey A. Chernov, Moscow, Russia.
317530Sache * All rights reserved.
417530Sache *
5227753Stheraven * Copyright (c) 2011 The FreeBSD Foundation
6227753Stheraven * All rights reserved.
7227753Stheraven * Portions of this software were developed by David Chisnall
8227753Stheraven * under sponsorship from the FreeBSD Foundation.
9227753Stheraven *
1017530Sache * Redistribution and use in source and binary forms, with or without
1117530Sache * modification, are permitted provided that the following conditions
1217530Sache * are met:
1317530Sache * 1. Redistributions of source code must retain the above copyright
1417530Sache *    notice, this list of conditions and the following disclaimer.
1517530Sache * 2. Redistributions in binary form must reproduce the above copyright
1617530Sache *    notice, this list of conditions and the following disclaimer in the
1717530Sache *    documentation and/or other materials provided with the distribution.
1817530Sache *
1917530Sache * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND
2017530Sache * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2117530Sache * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2217530Sache * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2317530Sache * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2417530Sache * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2517530Sache * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2617530Sache * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2717530Sache * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2817530Sache * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2917530Sache * SUCH DAMAGE.
3017530Sache */
3117530Sache
3292986Sobrien#include <sys/cdefs.h>
3392986Sobrien__FBSDID("$FreeBSD: releng/11.0/lib/libc/locale/collcmp.c 301461 2016-06-05 19:12:52Z pfg $");
3492986Sobrien
3517530Sache#include <string.h>
36290494Sbapt#include <wchar.h>
37227753Stheraven#include <xlocale.h>
38118396Sache#include "collate.h"
3917551Sache
4018331Sache/*
41118378Sache * Compare two characters using collate
4218331Sache */
4318331Sache
44301461Spfgint __collate_range_cmp(struct xlocale_collate *table, char c1, char c2)
4517551Sache{
46301461Spfg	char s1[2], s2[2];
47301461Spfg
48301461Spfg	s1[0] = c1;
49301461Spfg	s1[1] = '\0';
50301461Spfg	s2[0] = c2;
51301461Spfg	s2[1] = '\0';
52301461Spfg	struct _xlocale l = {{0}};
53301461Spfg	l.components[XLC_COLLATE] = (struct xlocale_component *)table;
54301461Spfg	return (strcoll_l(s1, s2, &l));
55301461Spfg}
56301461Spfg
57301461Spfgint __wcollate_range_cmp(struct xlocale_collate *table, wchar_t c1, wchar_t c2)
58301461Spfg{
59290494Sbapt	wchar_t s1[2], s2[2];
6017530Sache
6117551Sache	s1[0] = c1;
62301461Spfg	s1[1] = L'\0';
6317551Sache	s2[0] = c2;
64301461Spfg	s2[1] = L'\0';
65227753Stheraven	struct _xlocale l = {{0}};
66227753Stheraven	l.components[XLC_COLLATE] = (struct xlocale_component *)table;
67290494Sbapt	return (wcscoll_l(s1, s2, &l));
6817530Sache}
69