Author: gschneider
Date: Thu Dec 18 14:26:57 2008
New Revision: 38178
URL:
http://svn.reactos.org/svn/reactos?rev=38178&view=rev
Log:
- Update _mbsbtype and _mbsninc functions
- Fixes 17 msvcrt string tests, 16 to go
Modified:
trunk/reactos/lib/sdk/crt/mbstring/mbbtype.c
trunk/reactos/lib/sdk/crt/mbstring/mbsninc.c
Modified: trunk/reactos/lib/sdk/crt/mbstring/mbbtype.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbbty…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbbtype.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbbtype.c [iso-8859-1] Thu Dec 18 14:26:57 2008
@@ -1,11 +1,13 @@
/*
* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS system libraries
- * FILE: lib/msvcrt/mbstring/mbbtype.c
+ * FILE: lib/sdk/crt/mbstring/mbbtype.c
* PURPOSE: Determines the type of a multibyte character
- * PROGRAMER: Ariadne
- * UPDATE HISTORY:
- * 12/04/99: Created
+ * PROGRAMERS:
+ * Copyright 1999 Ariadne
+ * Copyright 1999 Alexandre Julliard
+ * Copyright 2000 Jon Griffths
+ *
*/
#include <precomp.h>
@@ -48,7 +50,28 @@
*/
int _mbsbtype( const unsigned char *str, size_t n )
{
- if ( str == NULL )
- return -1;
- return _mbbtype(*(str+n),1);
+ int lead = 0;
+ const unsigned char *end = str + n;
+
+ /* Lead bytes can also be trail bytes so we need to analyse the string.
+ * Also we must return _MBC_ILLEGAL for chars past the end of the string
+ */
+ while (str < end) /* Note: we skip the last byte - will check after the loop */
+ {
+ if (!*str)
+ return _MBC_ILLEGAL;
+ lead = !lead && _ismbblead(*str);
+ str++;
+ }
+
+ if (lead)
+ if (_ismbbtrail(*str))
+ return _MBC_TRAIL;
+ else
+ return _MBC_ILLEGAL;
+ else
+ if (_ismbblead(*str))
+ return _MBC_LEAD;
+ else
+ return _MBC_SINGLE;
}
Modified: trunk/reactos/lib/sdk/crt/mbstring/mbsninc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbsni…
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbsninc.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbsninc.c [iso-8859-1] Thu Dec 18 14:26:57 2008
@@ -1,3 +1,16 @@
+/*
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS system libraries
+ * FILE: lib/sdk/crt/mbstring/mbsninc.c
+ * PURPOSE:
+ * PROGRAMERS:
+ * Copyright 1999 Alexandre Julliard
+ * Copyright 2000 Jon Griffths
+ *
+ */
+
+#include <precomp.h>
+
#include <mbstring.h>
/*
@@ -5,12 +18,20 @@
*/
unsigned char * _mbsninc(const unsigned char *str, size_t n)
{
- unsigned char *s = (unsigned char *)str;
- while(*s != 0 && n > 0) {
- if (!_ismbblead(*s) )
- n--;
- s++;
- }
+ if(!str)
+ return NULL;
- return s;
+ while (n > 0 && *str)
+ {
+ if (_ismbblead(*str))
+ {
+ if (!*(str+1))
+ break;
+ str++;
+ }
+ str++;
+ n--;
+ }
+
+ return (unsigned char*)str;
}