1/*	$NetBSD: ldap_utf8.h,v 1.3 2021/08/14 16:14:55 christos Exp $	*/
2
3/* $OpenLDAP$ */
4/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 *
6 * Copyright 1998-2021 The OpenLDAP Foundation.
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
11 * Public License.
12 *
13 * A copy of this license is available in file LICENSE in the
14 * top-level directory of the distribution or, alternatively, at
15 * <http://www.OpenLDAP.org/license.html>.
16 */
17/* This notice applies to changes, created by or for Novell, Inc.,
18 * to preexisting works for which notices appear elsewhere in this file.
19 *
20 * Copyright (C) 2000 Novell, Inc. All Rights Reserved.
21 *
22 * THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND TREATIES.
23 * USE, MODIFICATION, AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO VERSION
24 * 2.0.1 OF THE OPENLDAP PUBLIC LICENSE, A COPY OF WHICH IS AVAILABLE AT
25 * HTTP://WWW.OPENLDAP.ORG/LICENSE.HTML OR IN THE FILE "LICENSE" IN THE
26 * TOP-LEVEL DIRECTORY OF THE DISTRIBUTION. ANY USE OR EXPLOITATION OF THIS
27 * WORK OTHER THAN AS AUTHORIZED IN VERSION 2.0.1 OF THE OPENLDAP PUBLIC
28 * LICENSE, OR OTHER PRIOR WRITTEN CONSENT FROM NOVELL, COULD SUBJECT THE
29 * PERPETRATOR TO CRIMINAL AND CIVIL LIABILITY.
30 */
31/* Note: A verbatim copy of version 2.0.1 of the OpenLDAP Public License
32 * can be found in the file "build/LICENSE-2.0.1" in this distribution
33 * of OpenLDAP Software.
34 */
35
36#ifndef _LDAP_UTF8_H
37#define _LDAP_UTF8_H
38
39#include <lber_types.h>	/* get ber_*_t */
40
41/*
42 * UTF-8 Utility Routines
43 */
44
45LDAP_BEGIN_DECL
46
47#define LDAP_UCS4_INVALID (0x80000000U)
48typedef ber_int_t ldap_ucs4_t;
49
50
51/* LDAP_MAX_UTF8_LEN is 3 or 6 depending on size of wchar_t */
52#define LDAP_MAX_UTF8_LEN  ( sizeof(wchar_t) * 3/2 )
53
54/* Unicode conversion routines  */
55LDAP_F( ldap_ucs4_t ) ldap_x_utf8_to_ucs4( LDAP_CONST char * p );
56LDAP_F( int ) ldap_x_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
57
58
59/*
60 * Wide Char / UTF-8 Conversion Routines
61 */
62
63/* UTF-8 character to Wide Char */
64LDAP_F(int) ldap_x_utf8_to_wc LDAP_P((
65	wchar_t *wchar, LDAP_CONST char *utf8char ));
66
67/* UTF-8 string to Wide Char string */
68LDAP_F(int) ldap_x_utf8s_to_wcs LDAP_P((
69	wchar_t *wcstr, LDAP_CONST char *utf8str, size_t count ));
70
71/* Wide Char to UTF-8 character */
72LDAP_F(int) ldap_x_wc_to_utf8 LDAP_P((
73	char *utf8char, wchar_t wchar, size_t count ));
74
75/* Wide Char string to UTF-8 string */
76LDAP_F(int) ldap_x_wcs_to_utf8s LDAP_P((
77	char *utf8str, LDAP_CONST wchar_t *wcstr, size_t count ));
78
79/*
80 * MultiByte Char / UTF-8 Conversion Routines
81 */
82
83/* UTF-8 character to MultiByte character */
84LDAP_F(int) ldap_x_utf8_to_mb LDAP_P((
85	char *mbchar, LDAP_CONST char *utf8char,
86	int (*ldap_f_wctomb)( char *mbchar, wchar_t wchar )));
87
88/* UTF-8 string to MultiByte string */
89LDAP_F(int) ldap_x_utf8s_to_mbs LDAP_P((
90	char *mbstr, LDAP_CONST char *utf8str, size_t count,
91	size_t (*ldap_f_wcstombs)( char *mbstr,
92		LDAP_CONST wchar_t *wcstr, size_t count) ));
93
94/* MultiByte character to UTF-8 character */
95LDAP_F(int) ldap_x_mb_to_utf8 LDAP_P((
96	char *utf8char, LDAP_CONST char *mbchar, size_t mbsize,
97	int (*ldap_f_mbtowc)( wchar_t *wchar,
98		LDAP_CONST char *mbchar, size_t count) ));
99
100/* MultiByte string to UTF-8 string */
101LDAP_F(int) ldap_x_mbs_to_utf8s LDAP_P((
102	char *utf8str, LDAP_CONST char *mbstr, size_t count,
103	size_t (*ldap_f_mbstowcs)( wchar_t *wcstr,
104		LDAP_CONST char *mbstr, size_t count) ));
105
106LDAP_END_DECL
107
108#endif /* _LDAP_UTF8_H */
109