Donny9 commented on code in PR #8802:
URL: https://github.com/apache/nuttx/pull/8802#discussion_r1136563771


##########
libs/libc/locale/lib_iconv.c:
##########
@@ -0,0 +1,1423 @@
+/****************************************************************************
+ * libs/libc/locale/lib_iconv.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 <iconv.h>
+#include <errno.h>
+#include <wchar.h>
+#include <string.h>
+#include <stdlib.h>
+#include <limits.h>
+#include <stdint.h>
+#include <locale.h>
+
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+#define UTF_32BE    0300
+#define UTF_16LE    0301
+#define UTF_16BE    0302
+#define UTF_32LE    0303
+#define UCS2BE      0304
+#define UCS2LE      0305
+#define WCHAR_T     0306
+#define US_ASCII    0307
+#define UTF_8       0310
+#define UTF_16      0312
+#define UTF_32      0313
+#define UCS2        0314
+#define EUC_JP      0320
+#define SHIFT_JIS   0321
+#define ISO2022_JP  0322
+#define GB18030     0330
+#define GBK         0331
+#define GB2312      0332
+#define BIG5        0340
+#define EUC_KR      0350
+
+/****************************************************************************
+ * Private Types
+ ****************************************************************************/
+
+struct stateful_cd
+{
+  iconv_t base_cd;
+  unsigned state;
+};
+
+/****************************************************************************
+ * Private Data
+ ****************************************************************************/
+
+/* Definitions of g_charmaps. Each charmap consists of:
+ * 1. Empty-string-terminated list of null-terminated aliases.
+ * 2. Special type code or number of elided quads of entries.
+ * 3. Character table (size determined by field 2), consisting
+ *    of 5 bytes for every 4 characters, interpreted as 10-bit
+ *    indices into the g_legacy_chars table.
+ */
+
+static const unsigned char g_charmaps[] =
+{
+  "utf8\0char\0\0\310"
+  "wchart\0\0\306"
+  "ucs2be\0\0\304"
+  "ucs2le\0\0\305"
+  "utf16be\0\0\302"
+  "utf16le\0\0\301"
+  "ucs4be\0utf32be\0\0\300"
+  "ucs4le\0utf32le\0\0\303"
+  "ascii\0usascii\0iso646\0iso646us\0\0\307"
+  "utf16\0\0\312"
+  "ucs4\0utf32\0\0\313"
+  "ucs2\0\0\314"
+#ifdef CONFIG_LIBC_LOCALE_JAPANESE
+  "eucjp\0\0\320"
+  "shiftjis\0sjis\0\0\321"
+  "iso2022jp\0\0\322"
+#endif
+#ifdef CONFIG_LIBC_LOCALE_CHINESE
+  "gb18030\0\0\330"
+  "gbk\0\0\331"
+  "gb2312\0\0\332"
+  "big5\0bigfive\0cp950\0big5hkscs\0\0\340"
+#endif
+#ifdef CONFIG_LIBC_LOCALE_KOREAN
+  "euckr\0ksc5601\0ksx1001\0cp949\0\0\350"
+#endif
+#ifdef CONFIG_LIBC_LOCALE_CODEPAGES
+  #include "codepages.h"
+#endif
+};
+
+/* Table of characters that appear in legacy 8-bit codepages,
+ * limited to 1024 slots (10 bit indices). The first 256 entries
+ * are elided since those characters are obviously all included.
+ */
+
+static const unsigned short g_legacy_chars[] =
+{
+  #include "legacychars.h"
+};
+
+#ifdef CONFIG_LIBC_LOCALE_JAPANESE
+static const unsigned short g_jis0208[84][94] =
+{
+  #include "jis0208.h"
+};
+
+static const unsigned short g_rev_jis[] =
+{
+  #include "revjis.h"
+};
+#endif
+
+#ifdef CONFIG_LIBC_LOCALE_CHINESE
+static const unsigned short g_gb18030[126][190] =
+{
+  #include "gb18030.h"
+};
+
+static const unsigned short g_big5[89][157] =
+{
+  #include "big5.h"
+};
+
+static const unsigned short g_hkscs[] =
+{
+  #include "hkscs.h"
+};
+#endif
+
+#ifdef CONFIG_LIBC_LOCALE_KOREAN
+static const unsigned short g_ksc[93][94] =
+{
+  #include "ksc.h"
+};
+#endif
+
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+static int fuzzycmp(FAR const unsigned char *a, FAR const unsigned char *b)
+{
+  for (; *a && *b; a++, b++)
+    {
+      while (*a && (*a | 32U) - 'a' > 26 && *a - '0' > 10U)
+        a++;
+
+      if ((*a | 32U) != *b)
+        {
+          return 1;
+        }
+    }
+
+  return *a != *b;
+}
+
+static size_t find_charmap(FAR const void *name)
+{
+  FAR const unsigned char *s;
+
+  if (*(FAR char *)name == 0)
+    {
+      /* "utf8" */
+
+      name = g_charmaps;
+    }
+
+  for (s = g_charmaps; *s; )

Review Comment:
   Done!



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to