home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / i18nv104.zip / SAMPLE / IS_W / IS_W.C < prev    next >
C/C++ Source or Header  |  1996-02-13  |  6KB  |  112 lines

  1. /*****************************************************************************/
  2. /***     Include files                                                     ***/
  3. /*****************************************************************************/
  4.  
  5. #include <stdio.h>                      /* Standard IO functions.            */
  6.  
  7. #include <wchar.h>                      /* XPG/4 library.                    */
  8. #include <locale.h>                     /* Locale definitions.               */
  9.  
  10. /*****************************************************************************/
  11. /***     Global defines                                                    ***/
  12. /*****************************************************************************/
  13.  
  14. #define UPPER_LIMIT    0xFF             /* Maximum character to check.       */
  15.  
  16. /*****************************************************************************/
  17. /***     wctype functions                                                  ***/
  18. /*****************************************************************************/
  19.  
  20. void do_wctype_functions()
  21. {
  22.   wctype_t lower_class;                 /* Character class var for lower.    */
  23.   wint_t ch;                            /* Character to check.               */
  24.  
  25.                                         /* Print header line.                */
  26.   printf("\n\nDemonstrating 'wctype' and 'iswctype'\n");
  27.   printf("-------------------------------------\n");
  28.  
  29.                                         /* Get the character class for lower */
  30.                                         /*  case characters.                 */
  31.   lower_class = wctype("lower");
  32.  
  33.                                         /* Loop through some characters.     */
  34.                                         /* For each character...             */
  35.                                         /*  If it is in the lower case class,*/
  36.                                         /*   Print out a message.            */
  37.   for (ch = 0; ch <= UPPER_LIMIT; ch++)
  38.       if (iswctype(ch, lower_class))
  39.          printf("%c is a lowercase character\n", ch);
  40. }
  41.  
  42. /*****************************************************************************/
  43. /***     Is functions for wide characters                                  ***/
  44. /*****************************************************************************/
  45.  
  46. void do_is_w_functions(void)
  47. {
  48.   wint_t ch;                            /* Character to check.               */
  49.  
  50.                                         /* Print out the current locale name.*/
  51.   printf("The current locale is: %s\n\n", setlocale(LC_CTYPE, NULL));
  52.  
  53.                                         /* Print a header banner.            */
  54.                                         /* For each character print the      */
  55.                                         /*  following information:           */
  56.                                         /*                                   */
  57.                                         /*  1) The char number (integer).    */
  58.                                         /*  2) The hex value of the number.  */
  59.                                         /*  3) The character (if printable). */
  60.                                         /*  4) Is it alphanumeric?           */
  61.                                         /*  5) Is it alphabetic?             */
  62.                                         /*  6) Is it a control character?    */
  63.                                         /*  7) Is it a digit?                */
  64.                                         /*  8) Is it a graph character?      */
  65.                                         /*  9) Is it lowercase?              */
  66.                                         /* 10) Is it a punctuation character?*/
  67.                                         /* 11) Is it a space character?      */
  68.                                         /* 12) Is it uppercase?              */
  69.                                         /* 13) Is it a hex digit? (0-9, A-F) */
  70.   printf("Char  Hex   Char  Alpha  Alpha  Cont  Dig  Graph Lower  ");
  71.   printf("Punct  Space  Upper  Hex\n");
  72.   printf("Num   Val         numer         Char                    ");
  73.   printf("                     Dig\n");
  74.   printf("--------------------------------------------------------");
  75.   printf("------------------------");
  76.  
  77.                                         /* For each wide character...        */
  78.                                         /* Print out the information using   */
  79.                                         /*  the proper "w_is" function.      */
  80.   for (ch = 0; ch <= UPPER_LIMIT; ++ch)
  81.   {
  82.     printf("\n%-5d ", ch);
  83.     printf("%#04x ", ch);
  84.     printf(" %c     ",  iswprint(ch)  ? ch   : ' ');
  85.     printf("%-6s ", iswalnum(ch)  ? "YES" : "NO");
  86.     printf("%-6s ", iswalpha(ch)  ? "YES"  : "NO");
  87.     printf("%-6s",  iswcntrl(ch)  ? "YES"  : "NO");
  88.     printf("%-5s",  iswdigit(ch)  ? "YES"  : "NO");
  89.     printf("%-6s",  iswgraph(ch)  ? "YES"  : "NO");
  90.     printf("%-7s",  iswlower(ch)  ? "YES"  : "NO");
  91.     printf("%-7s",  iswpunct(ch)  ? "YES" : "NO");
  92.     printf("%-8s",  iswspace(ch)  ? "YES"  : "NO");
  93.     printf("%-6s",  iswupper(ch)  ? "YES"  : "NO");
  94.     printf("%-6s",  iswxdigit(ch) ? "YES"  : "NO");
  95.   }
  96. }
  97.  
  98. /*****************************************************************************/
  99. /***     Main program                                                      ***/
  100. /*****************************************************************************/
  101.  
  102. void main(void)
  103. {
  104.                                         /* Set the locale based on env var.  */
  105.   setlocale(LC_ALL, "");
  106.  
  107.                                         /* Print out the wide char table.    */
  108.                                         /* Demonstrate the wctype functions. */
  109.   do_is_w_functions();
  110.   do_wctype_functions();
  111. }
  112.