]> git.sur5r.net Git - openldap/blobdiff - include/ldap_pvt_uc.h
Regenerated with new OL_ARG_ENABLE
[openldap] / include / ldap_pvt_uc.h
index 6b8264a86f54f0088d6408d3981fa63e1cd4631e..56fa45283a227ff60c501d0082692a76ecc353f7 100644 (file)
@@ -1,50 +1,45 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2000 The OpenLDAP Foundation, Redwood City, California, USA
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms are permitted only
- * as authorized by the OpenLDAP Public License.  A copy of this
- * license is available at http://www.OpenLDAP.org/license.html or
- * in file LICENSE in the top-level directory of the distribution.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
+
 /*
  * ldap_pvt_uc.h - Header for Unicode functions.
  * These are meant to be used by the OpenLDAP distribution only.
+ * These should be named ldap_pvt_....()
  */
 
 #ifndef _LDAP_PVT_UC_H
 #define _LDAP_PVT_UC_H 1
 
-#include <ldap_cdefs.h>
 #include <lber.h>                              /* get ber_slen_t */
 
-#ifdef _MSC_VER
+#include <ac/bytes.h>
 #include "../libraries/liblunicode/ucdata/ucdata.h"
-#else
-#include "../libraries/liblunicode/ucdata.h"
-#endif
 
 LDAP_BEGIN_DECL
 
-/*  
+/*
  * UTF-8 (in utf-8.c)
  */
 
-typedef ber_int_t ldap_ucs4_t;
-#define LDAP_UCS4_INVALID (0x80000000U)
-
-typedef short ldap_ucs2_t;
-
-/* UCDATA uses UCS-2 passed in an unsigned long */
-typedef unsigned long ldap_unicode_t;
+/* UCDATA uses UCS-2 passed in a 4 byte unsigned int */
+typedef ac_uint4 ldap_unicode_t;
 
-/* conversion routines  */
-LDAP_F( ldap_ucs4_t ) ldap_utf8_to_ucs4( const char * p );
-LDAP_F( int ) ldap_ucs4_to_utf8( ldap_ucs4_t c, char *buf );
+/* Convert a string with csize octets per character to UTF-8 */
+LDAP_F( int ) ldap_ucs_to_utf8s LDAP_P((
+       struct berval *ucs, int csize, struct berval *utf8s ));
 
-#define ldap_utf8_to_unicode( p ) ldap_utf8_to_ucs4((p))
-#define ldap_unicode_to_utf8( c, buf ) ldap_ucs4_to_ucs4((c),(buf))
 
 /* returns the number of bytes in the UTF-8 string */
 LDAP_F (ber_len_t) ldap_utf8_bytes( const char * );
@@ -54,6 +49,12 @@ LDAP_F (ber_len_t) ldap_utf8_chars( const char * );
 LDAP_F (int) ldap_utf8_offset( const char * );
 /* returns the length (in bytes) indicated by the UTF-8 character */
 LDAP_F (int) ldap_utf8_charlen( const char * );
+
+/* returns the length (in bytes) indicated by the UTF-8 character
+ * also checks that shortest possible encoding was used
+ */
+LDAP_F (int) ldap_utf8_charlen2( const char * );
+
 /* copies a UTF-8 character and returning number of bytes copied */
 LDAP_F (int) ldap_utf8_copy( char *, const char *);
 
@@ -82,13 +83,25 @@ LDAP_F (char *) ldap_utf8_strpbrk( const char* str, const char *set);
 LDAP_F (char*) ldap_utf8_strtok( char* sp, const char* sep, char **last);
 
 /* Optimizations */
-#define LDAP_UTF8_ISASCII(p) ( * (const unsigned char *) (p) < 0x80 )
+LDAP_V (const char) ldap_utf8_lentab[128];
+LDAP_V (const char) ldap_utf8_mintab[32];
+
+#define LDAP_UTF8_ISASCII(p) ( !(*(const unsigned char *)(p) & 0x80 ) )
 #define LDAP_UTF8_CHARLEN(p) ( LDAP_UTF8_ISASCII(p) \
-       ? 1 : ldap_utf8_charlen((p)) )
+       ? 1 : ldap_utf8_lentab[*(const unsigned char *)(p) ^ 0x80] )
+
+/* This is like CHARLEN but additionally validates to make sure
+ * the char used the shortest possible encoding.
+ * 'l' is used to temporarily hold the result of CHARLEN.
+ */
+#define LDAP_UTF8_CHARLEN2(p, l) ( ( ( l = LDAP_UTF8_CHARLEN( p )) < 3 || \
+       ( ldap_utf8_mintab[*(const unsigned char *)(p) & 0x1f] & (p)[1] ) ) ? \
+       l : 0 )
+
 #define LDAP_UTF8_OFFSET(p) ( LDAP_UTF8_ISASCII(p) \
        ? 1 : ldap_utf8_offset((p)) )
 
-#define LDAP_UTF8_COPY(d,s) (  LDAP_UTF8_ISASCII(s) \
+#define LDAP_UTF8_COPY(d,s) ( LDAP_UTF8_ISASCII(s) \
        ? (*(d) = *(s), 1) : ldap_utf8_copy((d),(s)) )
 
 #define LDAP_UTF8_NEXT(p) (    LDAP_UTF8_ISASCII(p) \
@@ -126,9 +139,23 @@ LDAP_LUNICODE_F(void) ucstr2upper(
        ldap_unicode_t *,
        ber_len_t );
 
-LDAP_LUNICODE_F(char *) UTF8normalize(
-       const char *,
-       char casefold );
+#define LDAP_UTF8_NOCASEFOLD   0x0U
+#define LDAP_UTF8_CASEFOLD     0x1U
+#define LDAP_UTF8_ARG1NFC      0x2U
+#define LDAP_UTF8_ARG2NFC      0x4U
+#define LDAP_UTF8_APPROX       0x8U
+
+LDAP_LUNICODE_F(struct berval *) UTF8bvnormalize(
+       struct berval *,
+       struct berval *,
+       unsigned,
+       void *memctx );
+
+LDAP_LUNICODE_F(int) UTF8bvnormcmp(
+       struct berval *,
+       struct berval *,
+       unsigned,
+       void *memctx );
 
 LDAP_END_DECL