ldap_utf8.h 3.4 KB

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