Edit

thodg/libiconv/lib/iconv_open2.h

Branch :

  • Show log

    Commit

  • Author : Bruno Haible
    Date : 2024-12-15 12:52:18
    Hash : 9f28054d
    Message : Implement the //NON_IDENTICAL_DISCARD suffix from POSIX:2024. * include/iconv.h.in (ICONV_GET_DISCARD_INVALID, ICONV_SET_DISCARD_INVALID, ICONV_GET_DISCARD_NON_IDENTICAL, ICONV_SET_DISCARD_NON_IDENTICAL): New macros. * lib/converters.h (struct conv_struct): Change type of discard_ilseq to 'unsigned int'. (DISCARD_INVALID, DISCARD_UNCONVERTIBLE): New macros. * lib/iconv.c (iconv_open, iconv_open_into): Change type of discard_ilseq to 'unsigned int'. (iconvctl): Implement ICONV_GET_DISCARD_INVALID, ICONV_SET_DISCARD_INVALID, ICONV_GET_DISCARD_NON_IDENTICAL, ICONV_SET_DISCARD_NON_IDENTICAL. Change the implementation of ICONV_GET_DISCARD_ILSEQ, ICONV_SET_DISCARD_ILSEQ to test/set both bits. * lib/iconv_open1.h: Update comment. Recognize //NON_IDENTICAL_DISCARD. * lib/iconv_open2.h: Update comment. * lib/loop_unicode.h (mb_to_uc_write_replacement): Test the DISCARD_UNCONVERTIBLE bit of discard_ilseq. (unicode_loop_convert): Test the respective bit of discard_ilseq. (unicode_loop_reset): Test the DISCARD_UNCONVERTIBLE bit of discard_ilseq. * lib/loop_wchar.h (wchar_from_loop_convert, wchar_to_loop_convert): Test the DISCARD_INVALID bit of discard_ilseq. * man/iconv_open.3: Mention the //NON_IDENTICAL_DISCARD suffix. Mark as conforming to POSIX:2024. * man/iconv.3: Likewise. * man/iconv_close.3: Mark as conforming to POSIX:2024. * man/iconv.1: Likewise. * man/iconvctl.3: Document ICONV_GET_DISCARD_INVALID, ICONV_SET_DISCARD_INVALID, ICONV_GET_DISCARD_NON_IDENTICAL, ICONV_SET_DISCARD_NON_IDENTICAL. Revise the description of ICONV_GET_DISCARD_ILSEQ, ICONV_SET_DISCARD_ILSEQ. * tests/test-discard.c (test_default, test_translit, test_ignore, test_ignore_translit): Test also the ICONV_GET_DISCARD_INVALID, ICONV_GET_DISCARD_NON_IDENTICAL accessors. (test_nid, test_nid_translit, test_invd, test_invd_translit): New functions. (main): Add test cases with //NON_IDENTICAL_DISCARD suffix. * NEWS: Mention the change.

  • lib/iconv_open2.h
  • /*
     * Copyright (C) 1999-2024 Free Software Foundation, Inc.
     * This file is part of the GNU LIBICONV Library.
     *
     * The GNU LIBICONV Library is free software; you can redistribute it
     * and/or modify it under the terms of the GNU Lesser General Public
     * License as published by the Free Software Foundation; either version 2.1
     * of the License, or (at your option) any later version.
     *
     * The GNU LIBICONV Library is distributed in the hope that it will be
     * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
     * Lesser General Public License for more details.
     *
     * You should have received a copy of the GNU Lesser General Public
     * License along with the GNU LIBICONV Library; see the file COPYING.LIB.
     * If not, see <https://www.gnu.org/licenses/>.
     */
    
    /* Part 2 of iconv_open.
       Input:
         struct conv_struct * cd;
         unsigned int from_index;
         int from_wchar;
         unsigned int from_surface;
         unsigned int to_index;
         int to_wchar;
         unsigned int to_surface;
         int transliterate;
         unsigned int discard_ilseq;
       Output: none.
       Side effects: Fills cd.
     */
    
      cd->iindex = from_index;
      cd->ifuncs = all_encodings[from_index].ifuncs;
      cd->oindex = to_index;
      cd->ofuncs = all_encodings[to_index].ofuncs;
      cd->oflags = all_encodings[to_index].oflags;
      /* Initialize the loop functions. */
    #if HAVE_MBRTOWC
      if (to_wchar) {
    #if HAVE_WCRTOMB
        if (from_wchar) {
          cd->lfuncs.loop_convert = wchar_id_loop_convert;
          cd->lfuncs.loop_reset = wchar_id_loop_reset;
        } else
    #endif
        {
          cd->lfuncs.loop_convert = wchar_to_loop_convert;
          cd->lfuncs.loop_reset = wchar_to_loop_reset;
        }
      } else
    #endif
      {
    #if HAVE_WCRTOMB
        if (from_wchar) {
          cd->lfuncs.loop_convert = wchar_from_loop_convert;
          cd->lfuncs.loop_reset = wchar_from_loop_reset;
        } else
    #endif
        {
          cd->lfuncs.loop_convert = unicode_loop_convert;
          cd->lfuncs.loop_reset = unicode_loop_reset;
        }
      }
      /* Initialize the surfaces. */
      cd->isurface = from_surface;
      cd->osurface = to_surface;
      /* Initialize the states. */
      memset(&cd->ibyteorder,'\0',sizeof(state_t));
      memset(&cd->istate,'\0',sizeof(state_t));
      memset(&cd->ostate,'\0',sizeof(state_t));
      /* Initialize the operation flags. */
      cd->transliterate = transliterate;
      cd->discard_ilseq = discard_ilseq;
      cd->fallbacks.mb_to_uc_fallback = NULL;
      cd->fallbacks.uc_to_mb_fallback = NULL;
      cd->fallbacks.mb_to_wc_fallback = NULL;
      cd->fallbacks.wc_to_mb_fallback = NULL;
      cd->fallbacks.data = NULL;
      cd->hooks.uc_hook = NULL;
      cd->hooks.wc_hook = NULL;
      cd->hooks.data = NULL;
      /* Initialize additional fields. */
      if (from_wchar != to_wchar) {
        struct wchar_conv_struct * wcd = (struct wchar_conv_struct *) cd;
    #if HAVE_WCRTOMB || HAVE_MBRTOWC
        memset(&wcd->state,'\0',sizeof(mbstate_t));
    #endif
      }
      /* Done. */