wcwidth.h 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* Determine the number of screen columns needed for a character.
  2. Copyright (C) 2006, 2007 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2, or (at your option)
  6. any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software Foundation,
  13. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */
  14. #ifndef _gl_WCWIDTH_H
  15. #define _gl_WCWIDTH_H
  16. #if HAVE_WCHAR_T
  17. /* Get wcwidth if available, along with wchar_t. */
  18. # include <wchar.h>
  19. /* Get iswprint. */
  20. # include <wctype.h>
  21. # ifndef HAVE_DECL_WCWIDTH
  22. "this configure-time declaration test was not run"
  23. # endif
  24. # ifndef wcwidth
  25. # if !HAVE_WCWIDTH
  26. /* wcwidth doesn't exist, so assume all printable characters have
  27. width 1. */
  28. static inline int
  29. wcwidth (wchar_t wc)
  30. {
  31. return wc == 0 ? 0 : iswprint (wc) ? 1 : -1;
  32. }
  33. # elif !HAVE_DECL_WCWIDTH
  34. /* wcwidth exists but is not declared. */
  35. extern
  36. # ifdef __cplusplus
  37. "C"
  38. # endif
  39. int wcwidth (int /* actually wchar_t */);
  40. # endif
  41. # endif
  42. #endif /* HAVE_WCHAR_T */
  43. #endif /* _gl_WCWIDTH_H */