tst-wctype.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  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, see
  15. <http://www.gnu.org/licenses/>. */
  16. #include <error.h>
  17. #include <locale.h>
  18. #include <stdio.h>
  19. #include <stdlib.h>
  20. #include <wchar.h>
  21. #include <wctype.h>
  22. int
  23. main (void)
  24. {
  25. wctype_t wct;
  26. wchar_t buf[1000];
  27. int result = 1;
  28. setlocale (LC_ALL, "");
  29. wprintf (L"locale = %s\n", setlocale (LC_CTYPE, NULL));
  30. wct = wctype ("jhira");
  31. if (wct == 0)
  32. error (EXIT_FAILURE, 0, "jhira: no such character class");
  33. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  34. {
  35. int n;
  36. wprintf (L"buf[] = \"%ls\"\n", buf);
  37. result = 0;
  38. for (n = 0; buf[n] != L'\0'; ++n)
  39. {
  40. wprintf (L"jhira(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  41. iswctype (buf[n], wct));
  42. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  43. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  44. }
  45. }
  46. wct = wctype ("jkata");
  47. if (wct == 0)
  48. error (EXIT_FAILURE, 0, "jkata: no such character class");
  49. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  50. {
  51. int n;
  52. wprintf (L"buf[] = \"%ls\"\n", buf);
  53. result = 0;
  54. for (n = 0; buf[n] != L'\0'; ++n)
  55. {
  56. wprintf (L"jkata(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  57. iswctype (buf[n], wct));
  58. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  59. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  60. }
  61. }
  62. wct = wctype ("jdigit");
  63. if (wct == 0)
  64. error (EXIT_FAILURE, 0, "jdigit: no such character class");
  65. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  66. {
  67. int n;
  68. wprintf (L"buf[] = \"%ls\"\n", buf);
  69. result = 0;
  70. for (n = 0; buf[n] != L'\0'; ++n)
  71. {
  72. wprintf (L"jdigit(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  73. iswctype (buf[n], wct));
  74. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  75. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  76. }
  77. }
  78. wct = wctype ("jspace");
  79. if (wct == 0)
  80. error (EXIT_FAILURE, 0, "jspace: no such character class");
  81. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  82. {
  83. int n;
  84. wprintf (L"buf[] = \"%ls\"\n", buf);
  85. result = 0;
  86. for (n = 0; buf[n] != L'\0'; ++n)
  87. {
  88. wprintf (L"jspace(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  89. iswctype (buf[n], wct));
  90. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  91. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  92. }
  93. }
  94. wct = wctype ("jkanji");
  95. if (wct == 0)
  96. error (EXIT_FAILURE, 0, "jkanji: no such character class");
  97. if (fgetws (buf, sizeof (buf) / sizeof (buf[0]), stdin) != NULL)
  98. {
  99. int n;
  100. wprintf (L"buf[] = \"%ls\"\n", buf);
  101. result = 0;
  102. for (n = 0; buf[n] != L'\0'; ++n)
  103. {
  104. wprintf (L"jkanji(U%04lx = %lc) = %d\n", (long) buf[n], buf[n],
  105. iswctype (buf[n], wct));
  106. result |= ((buf[n] < 0xff && iswctype (buf[n], wct))
  107. || (buf[n] > 0xff && !iswctype (buf[n], wct)));
  108. }
  109. }
  110. return result;
  111. }