#pragma ident "%Z%%M% %I% %E% SMI"
/*
* The contents of this file are subject to the Netscape Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is Mozilla Communicator client code, released
* March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998-1999 Netscape Communications Corporation. All
* Rights Reserved.
*
* Contributor(s):
*/
/* uft8.c - misc. utf8 "string" functions. */
#include "ldap-int.h"
= {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, 5, 6};
int
ldap_utf8len (const char* s)
/* Return the number of char's in the character at *s. */
{
return ldap_utf8next((char*)s) - s;
}
char*
ldap_utf8next (char* s)
/* Return a pointer to the character immediately following *s.
Handle any valid UTF-8 character, including '\0' and ASCII.
Try to handle a misaligned pointer or a malformed character.
*/
{
register unsigned char* next = (unsigned char*)s;
case 0: /* erroneous: s points to the middle of a character. */
case 1: ++next;
}
return (char*) next;
}
char*
ldap_utf8prev (char* s)
/* Return a pointer to the character immediately preceding *s.
Handle any valid UTF-8 character, including '\0' and ASCII.
Try to handle a misaligned pointer or a malformed character.
*/
{
register unsigned char* prev = (unsigned char*)s;
;
}
return (char*) prev;
}
int
/* Copy a character from src to dst; return the number of char's copied.
Handle any valid UTF-8 character, including '\0' and ASCII.
Try to handle a misaligned pointer or a malformed character.
*/
{
register const unsigned char* s = (const unsigned char*)src;
case 0: /* erroneous: s points to the middle of a character. */
case 1: *dst = *s++;
}
return s - (const unsigned char*)src;
}
/* Return the number of UTF-8 characters in the 0-terminated array s. */
{
register char* s = (char*)src;
size_t n;
for (n = 0; *s; LDAP_UTF8INC(s)) ++n;
return n;
}
unsigned long LDAP_CALL
{
register unsigned long c;
register const unsigned char* s = (const unsigned char*)*src;
case 0: /* erroneous: s points to the middle of a character. */
c = (*s++) & 0x3F; goto more5;
case 1: c = (*s++); break;
break;
}
*src = (const char*)s;
return c;
}
char*
{
const char *bp;
char *tok;
return NULL;
/* Skip leading delimiters; roughly, sp += strspn(sp, brk) */
cont:
goto cont;
}
if (sc == 0) { /* no non-delimiter characters */
return NULL;
}
/* Scan token; roughly, sp += strcspn(sp, brk)
* Note that brk must be 0-terminated; we stop if we see that, too.
*/
while (1) {
do {
if (sc == 0) {
} else {
*(LDAP_UTF8PREV(sp)) = 0;
}
return tok;
}
} while (bc != 0);
}
/* NOTREACHED */
}
int
ldap_utf8isalnum( char* s )
{
register unsigned char c = *(unsigned char*)s;
if (0x80 & c) return 0;
if (c >= 'A' && c <= 'Z') return 1;
if (c >= 'a' && c <= 'z') return 1;
if (c >= '0' && c <= '9') return 1;
return 0;
}
int
ldap_utf8isalpha( char* s )
{
register unsigned char c = *(unsigned char*)s;
if (0x80 & c) return 0;
if (c >= 'A' && c <= 'Z') return 1;
if (c >= 'a' && c <= 'z') return 1;
return 0;
}
int
ldap_utf8isdigit( char* s )
{
register unsigned char c = *(unsigned char*)s;
if (0x80 & c) return 0;
if (c >= '0' && c <= '9') return 1;
return 0;
}
int
ldap_utf8isxdigit( char* s )
{
register unsigned char c = *(unsigned char*)s;
if (0x80 & c) return 0;
if (c >= '0' && c <= '9') return 1;
if (c >= 'A' && c <= 'F') return 1;
if (c >= 'a' && c <= 'f') return 1;
return 0;
}
int
ldap_utf8isspace( char* s )
{
register unsigned char *c = (unsigned char*)s;
if (len == 0) {
return 0;
} else if (len == 1) {
switch (*c) {
case 0x09:
case 0x0A:
case 0x0B:
case 0x0C:
case 0x0D:
case 0x20:
return 1;
default:
return 0;
}
} else if (len == 2) {
if (*c == 0xc2) {
return *(c+1) == 0x80;
}
} else if (len == 3) {
if (*c == 0xE2) {
c++;
if (*c == 0x80) {
c++;
return (*c>=0x80 && *c<=0x8a);
}
} else if (*c == 0xE3) {
return (*(c+1)==0x80) && (*(c+2)==0x80);
} else if (*c==0xEF) {
return (*(c+1)==0xBB) && (*(c+2)==0xBF);
}
return 0;
}
/* should never reach here */
return 0;
}