pkarashchenko commented on code in PR #6666:
URL: https://github.com/apache/incubator-nuttx/pull/6666#discussion_r927044320


##########
libs/libc/wchar/lib_mbrtowc.c:
##########
@@ -32,15 +32,52 @@
  * Included Files
  ****************************************************************************/
 
-#include <nuttx/config.h>
-
-#include <stdlib.h>
-#include <stdio.h>
 #include <errno.h>
-#include <string.h>
 #include <wchar.h>
 
-#ifdef CONFIG_LIBC_WCHAR
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Implemented according to https://en.wikipedia.org/wiki/UTF-8 */
+
+#define SA        0xc2u
+#define SB        0xf4u
+
+/* Upper 6 state bits are a negative integer offset to bound-check next byte
+ * equivalent to: (((b) - 0x80) | ((b) + offset)) & ~0x3f
+ */
+
+#define OOB(c, b) (((((b) >> 3) - 0x10) | \
+                   (((b) >> 3) + ((int32_t)(c) >> 26))) & ~7)
+
+/* Interval [a,b). Either a must be 80 or b must be c0, lower 3 bits clear. */
+
+#define R(a, b)   ((uint32_t)(((a) == 0x80 ? 0x40u - (b) : 0u - (a)) << 23))
+
+#define C(x)      ((x) < 2 ? -1 : (R(0x80, 0xc0) | (x)))
+#define D(x)      C((x) + 16)
+#define E(x)      (((x) == 0 ? R(0xa0, 0xc0) : \
+                    (x) == 0xd ? R(0x80, 0xa0) : R(0x80, 0xc0)) \
+                   | (R(0x80, 0xc0) >> 6) \
+                   | (x))
+#define F(x)      (((x) >= 5 ? 0 : \
+                    (x) == 0 ? R(0x90, 0xc0) : \
+                    (x) == 4 ? R(0x80, 0x90) : R(0x80, 0xc0)) \
+                   | (R(0x80, 0xc0) >> 6) \
+                   | (R(0x80, 0xc0) >> 12) \
+                   | (x))
+
+static const uint32_t g_bittab[] =

Review Comment:
   missing "Private Data" section



##########
libs/libc/wchar/lib_mbsinit.c:
##########
@@ -0,0 +1,42 @@
+/****************************************************************************
+ * libs/libc/wchar/lib_mbsinit.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <wchar.h>
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: mbsinit
+ *
+ * Description:
+ *   test for initial shift state
+ *
+ ****************************************************************************/
+
+int mbsinit(FAR const mbstate_t *st)
+{
+  return !st || !*(FAR uint32_t *)st;

Review Comment:
   Optional
   ```suggestion
     return st == NULL || !*(FAR uint32_t *)st;
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to