- Update _mbclen, mblen, _mbslen, _mbsnextc and _mbstrlen which should rely on the leadbyte mechanism

- Fixes 9 msvcrt string tests, 7 failures tbd
- Remove leftover function declaration from ismblead.c

svn path=/trunk/; revision=38181
This commit is contained in:
Gregor Schneider 2008-12-18 21:17:22 +00:00
parent 589af34558
commit 5fe4b4b425
5 changed files with 83 additions and 46 deletions

View file

@ -14,8 +14,6 @@
#include <precomp.h>
#include <mbctype.h>
size_t _mbclen2(const unsigned int s);
/*
* @implemented
*/

View file

@ -1,18 +1,30 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbclen.c
* PURPOSE: Determines the length of a multi byte character
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
#include <mbstring.h>
#include <stdlib.h>
int isleadbyte(int byte);
/*
* @implemented
*/
size_t _mbclen(const unsigned char *s)
{
return (_ismbblead(*s>>8) && _ismbbtrail(*s&0x00FF)) ? 2 : 1;
return _ismbblead(*s) ? 2 : 1;
}
size_t _mbclen2(const unsigned int s)
{
return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1;
return (_ismbblead(s>>8) && _ismbbtrail(s&0x00FF)) ? 2 : 1;
}
/*
@ -20,14 +32,11 @@ size_t _mbclen2(const unsigned int s)
*
* @implemented
*/
int mblen( const char *s, size_t count )
int mblen( const char *str, size_t size )
{
size_t l;
if ( s == NULL )
return 0;
l = _mbclen((const unsigned char *)s);
if ( l < count )
return -1;
return l;
if (str && *str && size)
{
return !isleadbyte(*str) ? 1 : (size>1 ? 2 : -1);
}
return 0;
}

View file

@ -1,18 +1,32 @@
#include <mbstring.h>
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbslen.c
* PURPOSE: Determines the length of a multi byte string
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
size_t _mbclen2(const unsigned int s);
#include <mbstring.h>
/*
* @implemented
*/
size_t _mbslen(const unsigned char *str)
{
int i = 0;
unsigned char *s;
if (str == 0)
return 0;
for (s = (unsigned char *)str; *s; s+=_mbclen2(*s),i++);
return i;
size_t len = 0;
while(*str)
{
if (_ismbblead(*str))
{
str++;
if (!*str) /* count only full chars */
break;
}
str++;
len++;
}
return len;
}

View file

@ -1,20 +1,23 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbsnextc.c
* PURPOSE: Finds the next character in a string
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
#include <precomp.h>
#include <mbstring.h>
/*
* @implemented
*/
unsigned int _mbsnextc (const unsigned char *src)
unsigned int _mbsnextc (const unsigned char *str)
{
unsigned char *char_src = (unsigned char *)src;
unsigned short *short_src = (unsigned short *)src;
if (src == NULL)
return 0;
if (!_ismbblead(*src))
return *char_src;
else
return *short_src;
return 0;
if(_ismbblead(*str))
return *str << 8 | str[1];
return *str;
}

View file

@ -1,19 +1,32 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
* FILE: lib/sdk/crt/mbstring/mbstrlen.c
* PURPOSE: Determines the length of a multi byte string, current locale
* PROGRAMERS:
* Copyright 1999 Alexandre Julliard
* Copyright 2000 Jon Griffths
*
*/
#include <mbstring.h>
#include <stdlib.h>
int isleadbyte(int byte);
/*
* @implemented
*/
size_t _mbstrlen( const char *string )
size_t _mbstrlen( const char *str )
{
char *s = (char *)string;
size_t i = 0;
while ( *s != 0 ) {
if ( _ismbblead(*s) )
s++;
s++;
i++;
}
return i;
size_t len = 0;
while(*str)
{
/* FIXME: According to the documentation we are supposed to test for
* multi-byte character validity. Whatever that means
*/
str += isleadbyte(*str) ? 2 : 1;
len++;
}
return len;
}