Blame lib/wcwidth.c

Packit Service fdd496
/* Determine the number of screen columns needed for a character.
Packit Service fdd496
   Copyright (C) 2006-2007, 2010-2017 Free Software Foundation, Inc.
Packit Service fdd496
Packit Service fdd496
   This program is free software: you can redistribute it and/or modify
Packit Service fdd496
   it under the terms of the GNU General Public License as published by
Packit Service fdd496
   the Free Software Foundation; either version 3 of the License, or
Packit Service fdd496
   (at your option) any later version.
Packit Service fdd496
Packit Service fdd496
   This program is distributed in the hope that it will be useful,
Packit Service fdd496
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service fdd496
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
Packit Service fdd496
   GNU General Public License for more details.
Packit Service fdd496
Packit Service fdd496
   You should have received a copy of the GNU General Public License
Packit Service fdd496
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
Packit Service fdd496
Packit Service fdd496
#include <config.h>
Packit Service fdd496
Packit Service fdd496
/* Specification.  */
Packit Service fdd496
#include <wchar.h>
Packit Service fdd496
Packit Service fdd496
/* Get iswprint.  */
Packit Service fdd496
#include <wctype.h>
Packit Service fdd496
Packit Service fdd496
#include "localcharset.h"
Packit Service fdd496
#include "streq.h"
Packit Service fdd496
#include "uniwidth.h"
Packit Service fdd496
Packit Service fdd496
int
Packit Service fdd496
wcwidth (wchar_t wc)
Packit Service fdd496
#undef wcwidth
Packit Service fdd496
{
Packit Service fdd496
  /* In UTF-8 locales, use a Unicode aware width function.  */
Packit Service fdd496
  const char *encoding = locale_charset ();
Packit Service fdd496
  if (STREQ_OPT (encoding, "UTF-8", 'U', 'T', 'F', '-', '8', 0, 0, 0 ,0))
Packit Service fdd496
    {
Packit Service fdd496
      /* We assume that in a UTF-8 locale, a wide character is the same as a
Packit Service fdd496
         Unicode character.  */
Packit Service fdd496
      return uc_width (wc, encoding);
Packit Service fdd496
    }
Packit Service fdd496
  else
Packit Service fdd496
    {
Packit Service fdd496
      /* Otherwise, fall back to the system's wcwidth function.  */
Packit Service fdd496
#if HAVE_WCWIDTH
Packit Service fdd496
      return wcwidth (wc);
Packit Service fdd496
#else
Packit Service fdd496
      return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
Packit Service fdd496
#endif
Packit Service fdd496
    }
Packit Service fdd496
}