[ros-diffs] [gschneider] 38181: - 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

gschneider at svn.reactos.org gschneider at svn.reactos.org
Thu Dec 18 22:17:23 CET 2008


Author: gschneider
Date: Thu Dec 18 15:17:22 2008
New Revision: 38181

URL: http://svn.reactos.org/svn/reactos?rev=38181&view=rev
Log:
- 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

Modified:
    trunk/reactos/lib/sdk/crt/mbstring/ismblead.c
    trunk/reactos/lib/sdk/crt/mbstring/mbclen.c
    trunk/reactos/lib/sdk/crt/mbstring/mbslen.c
    trunk/reactos/lib/sdk/crt/mbstring/mbsnextc.c
    trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c

Modified: trunk/reactos/lib/sdk/crt/mbstring/ismblead.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/ismblead.c?rev=38181&r1=38180&r2=38181&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/ismblead.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/ismblead.c [iso-8859-1] Thu Dec 18 15:17:22 2008
@@ -13,8 +13,6 @@
 
 #include <precomp.h>
 #include <mbctype.h>
-
-size_t _mbclen2(const unsigned int s);
 
 /*
  * @implemented

Modified: trunk/reactos/lib/sdk/crt/mbstring/mbclen.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbclen.c?rev=38181&r1=38180&r2=38181&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbclen.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbclen.c [iso-8859-1] Thu Dec 18 15:17:22 2008
@@ -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 @@
  *
  * @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;
 }

Modified: trunk/reactos/lib/sdk/crt/mbstring/mbslen.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbslen.c?rev=38181&r1=38180&r2=38181&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbslen.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbslen.c [iso-8859-1] Thu Dec 18 15:17:22 2008
@@ -1,18 +1,32 @@
+/*
+ * 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
+ *
+ */
+
 #include <mbstring.h>
-
-size_t _mbclen2(const unsigned int s);
 
 /*
  * @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;
 }

Modified: trunk/reactos/lib/sdk/crt/mbstring/mbsnextc.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbsnextc.c?rev=38181&r1=38180&r2=38181&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbsnextc.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbsnextc.c [iso-8859-1] Thu Dec 18 15:17:22 2008
@@ -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;
 }

Modified: trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c
URL: http://svn.reactos.org/svn/reactos/trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c?rev=38181&r1=38180&r2=38181&view=diff
==============================================================================
--- trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c [iso-8859-1] (original)
+++ trunk/reactos/lib/sdk/crt/mbstring/mbstrlen.c [iso-8859-1] Thu Dec 18 15:17:22 2008
@@ -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;
 }



More information about the Ros-diffs mailing list