tst-wctype.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* Test program for iswctype() function in ja_JP locale.
  2. Copyright (C) 2000 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include <error.h>
  18. #include <locale.h>
  19. #include <stdio.h>
  20. #include <stdlib.h>
  21. #include <wchar.h>
  22. #include <wctype.h>
  23. int
  24. main (void)
  25. {
  26. wctype_t wct;
  27. wchar_t buf[1000];
  28. int result = 1;
  29. setlocale (LC_ALL, "");
  30. wprintf (L"locale = %s\n", setlocale (LC_CTYPE, NULL));
  31. wct = wctype ("jhira");
  32. if (wct == 0)
  33. error (EXIT_FAILURE, 0, "jhira: no such character class");
  34. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  35. {
  36. int n;
  37. wprintf (L"buf[] = \"%ls\"\n", buf);
  38. result = 0;
  39. for (n = 0; buf[n] != L'\0'; ++n)
  40. {
  41. wprintf (L"jhira(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  42. iswctype (buf[n], wct));
  43. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  44. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  45. }
  46. }
  47. wct = wctype ("jkata");
  48. if (wct == 0)
  49. error (EXIT_FAILURE, 0, "jkata: no such character class");
  50. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  51. {
  52. int n;
  53. wprintf (L"buf[] = \"%ls\"\n", buf);
  54. result = 0;
  55. for (n = 0; buf[n] != L'\0'; ++n)
  56. {
  57. wprintf (L"jkata(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  58. iswctype (buf[n], wct));
  59. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  60. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  61. }
  62. }
  63. wct = wctype ("jdigit");
  64. if (wct == 0)
  65. error (EXIT_FAILURE, 0, "jdigit: no such character class");
  66. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  67. {
  68. int n;
  69. wprintf (L"buf[] = \"%ls\"\n", buf);
  70. result = 0;
  71. for (n = 0; buf[n] != L'\0'; ++n)
  72. {
  73. wprintf (L"jdigit(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  74. iswctype (buf[n], wct));
  75. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  76. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  77. }
  78. }
  79. wct = wctype ("jspace");
  80. if (wct == 0)
  81. error (EXIT_FAILURE, 0, "jspace: no such character class");
  82. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  83. {
  84. int n;
  85. wprintf (L"buf[] = \"%ls\"\n", buf);
  86. result = 0;
  87. for (n = 0; buf[n] != L'\0'; ++n)
  88. {
  89. wprintf (L"jspace(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  90. iswctype (buf[n], wct));
  91. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  92. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  93. }
  94. }
  95. wct = wctype ("jkanji");
  96. if (wct == 0)
  97. error (EXIT_FAILURE, 0, "jkanji: no such character class");
  98. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  99. {
  100. int n;
  101. wprintf (L"buf[] = \"%ls\"\n", buf);
  102. result = 0;
  103. for (n = 0; buf[n] != L'\0'; ++n)
  104. {
  105. wprintf (L"jkanji(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  106. iswctype (buf[n], wct));
  107. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  108. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  109. }
  110. }
  111. return result;
  112. }