combining.c revision 226031
191094Sdes/*
292289Sdes * Copyright (c) 2008 Kungliga Tekniska H��gskolan
391094Sdes * (Royal Institute of Technology, Stockholm, Sweden).
491094Sdes * All rights reserved.
591094Sdes *
699158Sdes * Redistribution and use in source and binary forms, with or without
799158Sdes * modification, are permitted provided that the following conditions
899158Sdes * are met:
991094Sdes *
1091094Sdes * 1. Redistributions of source code must retain the above copyright
1191094Sdes *    notice, this list of conditions and the following disclaimer.
1291094Sdes *
1391094Sdes * 2. Redistributions in binary form must reproduce the above copyright
1491094Sdes *    notice, this list of conditions and the following disclaimer in the
1591094Sdes *    documentation and/or other materials provided with the distribution.
1691094Sdes *
1791094Sdes * 3. Neither the name of the Institute nor the names of its contributors
1891094Sdes *    may be used to endorse or promote products derived from this software
1991094Sdes *    without specific prior written permission.
2091094Sdes *
2191094Sdes * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
2291094Sdes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2391094Sdes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2491094Sdes * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
2591094Sdes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2691094Sdes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2791094Sdes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2891094Sdes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2991094Sdes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3091094Sdes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3191094Sdes * SUCH DAMAGE.
3291094Sdes */
3391094Sdes
3499158Sdes#include "windlocl.h"
3591094Sdes
3691094Sdes#include <stdlib.h>
3791094Sdes
3891094Sdes#include "combining_table.h"
3991094Sdes
4091094Sdesstatic int
4191094Sdestranslation_cmp(const void *key, const void *data)
4291094Sdes{
4391094Sdes    const struct translation *t1 = (const struct translation *)key;
4491100Sdes    const struct translation *t2 = (const struct translation *)data;
4591100Sdes
4691094Sdes    return t1->key - t2->key;
4791094Sdes}
4891094Sdes
4991094Sdesint
5091094Sdes_wind_combining_class(uint32_t code_point)
5191094Sdes{
5291094Sdes    struct translation ts = {code_point};
5391094Sdes    void *s = bsearch(&ts, _wind_combining_table, _wind_combining_table_size,
5491094Sdes		      sizeof(_wind_combining_table[0]),
5591094Sdes		      translation_cmp);
5691094Sdes    if (s != NULL) {
5791094Sdes	const struct translation *t = (const struct translation *)s;
5891094Sdes	return t->combining_class;
5991094Sdes    } else {
6091094Sdes	return 0;
6191094Sdes    }
6291094Sdes}
6391094Sdes