Subversion Repositories Kolibri OS

Rev

Rev 4874 | Blame | Compare with Previous | Last modification | View Log | RSS feed

  1. /* Copyright (c) 2002 Red Hat Incorporated.
  2.    All rights reserved.
  3.  
  4.    Redistribution and use in source and binary forms, with or without
  5.    modification, are permitted provided that the following conditions are met:
  6.  
  7.      Redistributions of source code must retain the above copyright
  8.      notice, this list of conditions and the following disclaimer.
  9.  
  10.      Redistributions in binary form must reproduce the above copyright
  11.      notice, this list of conditions and the following disclaimer in the
  12.      documentation and/or other materials provided with the distribution.
  13.  
  14.      The name of Red Hat Incorporated may not be used to endorse
  15.      or promote products derived from this software without specific
  16.      prior written permission.
  17.  
  18.    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  19.    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  20.    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  21.    ARE DISCLAIMED.  IN NO EVENT SHALL RED HAT INCORPORATED BE LIABLE FOR ANY
  22.    DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23.    (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24.    LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25.    ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26.    (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS  
  27.    SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. */
  29.  
  30. /*
  31. FUNCTION
  32.         <<iswalpha>>---alphabetic wide character test
  33.  
  34. INDEX
  35.         iswalpha
  36.  
  37. ANSI_SYNOPSIS
  38.         #include <wctype.h>
  39.         int iswalpha(wint_t <[c]>);
  40.  
  41. TRAD_SYNOPSIS
  42.         #include <wctype.h>
  43.         int iswalpha(<[c]>)
  44.         wint_t <[c]>;
  45.  
  46. DESCRIPTION
  47. <<iswalpha>> is a function which classifies wide-character values that
  48. are alphabetic.
  49.  
  50. RETURNS
  51. <<iswalpha>> returns non-zero if <[c]> is an alphabetic wide character.
  52.  
  53. PORTABILITY
  54. <<iswalpha>> is C99.
  55.  
  56. No supporting OS subroutines are required.
  57. */
  58. #include <_ansi.h>
  59. #include <newlib.h>
  60. #include <wctype.h>
  61. #include <string.h>
  62. #include <ctype.h>
  63. #include "local.h"
  64.  
  65. #ifdef _MB_CAPABLE
  66. #include "utf8alpha.h"
  67. #endif /* _MB_CAPABLE */
  68.  
  69. int
  70. _DEFUN(iswalpha,(c), wint_t c)
  71. {
  72. #ifdef _MB_CAPABLE
  73.   unsigned const char *table;
  74.   unsigned char *ptr;
  75.   unsigned char ctmp;
  76.   int size;
  77.   wint_t x;
  78.  
  79.   c = _jp2uc (c);
  80.  
  81.   /* Based on and tested against Unicode 5.2
  82.      See utf8alpha.h for a description how to fetch the data. */
  83.   x = (c >> 8);
  84.   /* for some large sections, all characters are alphabetic so handle them here */
  85.   if ((x >= 0x34 && x <= 0x4c) ||
  86.       (x >= 0x4e && x <= 0x9e) ||
  87.       (x >= 0xac && x <= 0xd6) ||
  88.       (x >= 0x120 && x <= 0x122) ||
  89.       (x >= 0x130 && x <= 0x133) ||
  90.       (x >= 0x200 && x <= 0x2a5) ||
  91.       (x >= 0x2a7 && x <= 0x2b6))
  92.     return 1;
  93.  
  94.   switch (x)
  95.     {
  96.     case 0x00:
  97.       table = u0;
  98.       size = sizeof(u0);
  99.       break;
  100.     case 0x01:
  101.     case 0x11:
  102.     case 0x15:
  103.     case 0x1e:
  104.     case 0xa0:
  105.     case 0xa1:
  106.     case 0xa2:
  107.     case 0xa3:
  108.     case 0xa5:
  109.     case 0xf9:
  110.     case 0xfc:
  111.     case 0x2f8:
  112.     case 0x2f9:
  113.       return 1;
  114.     case 0x02:
  115.       table = u2;
  116.       size = sizeof(u2);
  117.       break;
  118.     case 0x03:
  119.       table = u3;
  120.       size = sizeof(u3);
  121.       break;
  122.     case 0x04:
  123.       table = u4;
  124.       size = sizeof(u4);
  125.       break;
  126.     case 0x05:
  127.       table = u5;
  128.       size = sizeof(u5);
  129.       break;
  130.     case 0x06:
  131.       table = u6;
  132.       size = sizeof(u6);
  133.       break;
  134.     case 0x07:
  135.       table = u7;
  136.       size = sizeof(u7);
  137.       break;
  138.     case 0x08:
  139.       table = u8;
  140.       size = sizeof(u8);
  141.       break;
  142.     case 0x09:
  143.       table = u9;
  144.       size = sizeof(u9);
  145.       break;
  146.     case 0x0a:
  147.       table = ua;
  148.       size = sizeof(ua);
  149.       break;
  150.     case 0x0b:
  151.       table = ub;
  152.       size = sizeof(ub);
  153.       break;
  154.     case 0x0c:
  155.       table = uc;
  156.       size = sizeof(uc);
  157.       break;
  158.     case 0x0d:
  159.       table = ud;
  160.       size = sizeof(ud);
  161.       break;
  162.     case 0x0e:
  163.       table = ue;
  164.       size = sizeof(ue);
  165.       break;
  166.     case 0x0f:
  167.       table = uf;
  168.       size = sizeof(uf);
  169.       break;
  170.     case 0x10:
  171.       table = u10;
  172.       size = sizeof(u10);
  173.       break;
  174.     case 0x12:
  175.       table = u12;
  176.       size = sizeof(u12);
  177.       break;
  178.     case 0x13:
  179.       table = u13;
  180.       size = sizeof(u13);
  181.       break;
  182.     case 0x14:
  183.       table = u14;
  184.       size = sizeof(u14);
  185.       break;
  186.     case 0x16:
  187.       table = u16;
  188.       size = sizeof(u16);
  189.       break;
  190.     case 0x17:
  191.       table = u17;
  192.       size = sizeof(u17);
  193.       break;
  194.     case 0x18:
  195.       table = u18;
  196.       size = sizeof(u18);
  197.       break;
  198.     case 0x19:
  199.       table = u19;
  200.       size = sizeof(u19);
  201.       break;
  202.     case 0x1a:
  203.       table = u1a;
  204.       size = sizeof(u1a);
  205.       break;
  206.     case 0x1b:
  207.       table = u1b;
  208.       size = sizeof(u1b);
  209.       break;
  210.     case 0x1c:
  211.       table = u1c;
  212.       size = sizeof(u1c);
  213.       break;
  214.     case 0x1d:
  215.       table = u1d;
  216.       size = sizeof(u1d);
  217.       break;
  218.     case 0x1f:
  219.       table = u1f;
  220.       size = sizeof(u1f);
  221.       break;
  222.     case 0x20:
  223.       table = u20;
  224.       size = sizeof(u20);
  225.       break;
  226.     case 0x21:
  227.       table = u21;
  228.       size = sizeof(u21);
  229.       break;
  230.     case 0x24:
  231.       table = u24;
  232.       size = sizeof(u24);
  233.       break;
  234.     case 0x2c:
  235.       table = u2c;
  236.       size = sizeof(u2c);
  237.       break;
  238.     case 0x2d:
  239.       table = u2d;
  240.       size = sizeof(u2d);
  241.       break;
  242.     case 0x2e:
  243.       table = u2e;
  244.       size = sizeof(u2e);
  245.       break;
  246.     case 0x30:
  247.       table = u30;
  248.       size = sizeof(u30);
  249.       break;
  250.     case 0x31:
  251.       table = u31;
  252.       size = sizeof(u31);
  253.       break;
  254.     case 0x4d:
  255.       table = u4d;
  256.       size = sizeof(u4d);
  257.       break;
  258.     case 0x9f:
  259.       table = u9f;
  260.       size = sizeof(u9f);
  261.       break;
  262.     case 0xa4:
  263.       table = ua4;
  264.       size = sizeof(ua4);
  265.       break;
  266.     case 0xa6:
  267.       table = ua6;
  268.       size = sizeof(ua6);
  269.       break;
  270.     case 0xa7:
  271.       table = ua7;
  272.       size = sizeof(ua7);
  273.       break;
  274.     case 0xa8:
  275.       table = ua8;
  276.       size = sizeof(ua8);
  277.       break;
  278.     case 0xa9:
  279.       table = ua9;
  280.       size = sizeof(ua9);
  281.       break;
  282.     case 0xaa:
  283.       table = uaa;
  284.       size = sizeof(uaa);
  285.       break;
  286.     case 0xab:
  287.       table = uab;
  288.       size = sizeof(uab);
  289.       break;
  290.     case 0xd7:
  291.       table = ud7;
  292.       size = sizeof(ud7);
  293.       break;
  294.     case 0xfa:
  295.       table = ufa;
  296.       size = sizeof(ufa);
  297.       break;
  298.     case 0xfb:
  299.       table = ufb;
  300.       size = sizeof(ufb);
  301.       break;
  302.     case 0xfd:
  303.       table = ufd;
  304.       size = sizeof(ufd);
  305.       break;
  306.     case 0xfe:
  307.       table = ufe;
  308.       size = sizeof(ufe);
  309.       break;
  310.     case 0xff:
  311.       table = uff;
  312.       size = sizeof(uff);
  313.       break;
  314.     case 0x100:
  315.       table = u100;
  316.       size = sizeof(u100);
  317.       break;
  318.     case 0x101:
  319.       table = u101;
  320.       size = sizeof(u101);
  321.       break;
  322.     case 0x102:
  323.       table = u102;
  324.       size = sizeof(u102);
  325.       break;
  326.     case 0x103:
  327.       table = u103;
  328.       size = sizeof(u103);
  329.       break;
  330.     case 0x104:
  331.       table = u104;
  332.       size = sizeof(u104);
  333.       break;
  334.     case 0x108:
  335.       table = u108;
  336.       size = sizeof(u108);
  337.       break;
  338.     case 0x109:
  339.       table = u109;
  340.       size = sizeof(u109);
  341.       break;
  342.     case 0x10a:
  343.       table = u10a;
  344.       size = sizeof(u10a);
  345.       break;
  346.     case 0x10b:
  347.       table = u10b;
  348.       size = sizeof(u10b);
  349.       break;
  350.     case 0x10c:
  351.       table = u10c;
  352.       size = sizeof(u10c);
  353.       break;
  354.     case 0x110:
  355.       table = u110;
  356.       size = sizeof(u110);
  357.       break;
  358.     case 0x123:
  359.       table = u123;
  360.       size = sizeof(u123);
  361.       break;
  362.     case 0x124:
  363.       table = u124;
  364.       size = sizeof(u124);
  365.       break;
  366.     case 0x134:
  367.       table = u134;
  368.       size = sizeof(u134);
  369.       break;
  370.     case 0x1d4:
  371.       table = u1d4;
  372.       size = sizeof(u1d4);
  373.       break;
  374.     case 0x1d5:
  375.       table = u1d5;
  376.       size = sizeof(u1d5);
  377.       break;
  378.     case 0x1d6:
  379.       table = u1d6;
  380.       size = sizeof(u1d6);
  381.       break;
  382.     case 0x1d7:
  383.       table = u1d7;
  384.       size = sizeof(u1d7);
  385.       break;
  386.     case 0x1f1:
  387.       table = u1f1;
  388.       size = sizeof(u1f1);
  389.       break;
  390.     case 0x2a6:
  391.       table = u2a6;
  392.       size = sizeof(u2a6);
  393.       break;
  394.     case 0x2b7:
  395.       table = u2b7;
  396.       size = sizeof(u2b7);
  397.       break;
  398.     case 0x2fa:
  399.       table = u2fa;
  400.       size = sizeof(u2fa);
  401.       break;
  402.     default:
  403.       return 0;
  404.     }
  405.   /* we have narrowed down to a section of 256 characters to check */
  406.   /* now check if c matches the alphabetic wide-chars within that section */
  407.   ptr = (unsigned char *)table;
  408.   ctmp = (unsigned char)c;
  409.   while (ptr < table + size)
  410.     {
  411.       if (ctmp == *ptr)
  412.         return 1;
  413.       if (ctmp < *ptr)
  414.         return 0;
  415.       /* otherwise c > *ptr */
  416.       /* look for 0x0 as next element which indicates a range */
  417.       ++ptr;
  418.       if (ptr < table + size - 1 && *ptr == 0x0)
  419.         {
  420.           /* we have a range..see if c falls within range */
  421.           ++ptr;
  422.           if (ctmp <= *ptr)
  423.             return 1;
  424.           ++ptr;
  425.         }
  426.     }
  427.   /* not in table */
  428.   return 0;
  429. #else
  430.   return (c < (wint_t)0x100 ? isalpha (c) : 0);
  431. #endif /* _MB_CAPABLE */
  432. }
  433.  
  434.