Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | 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.         <<towlower>>---translate wide characters to lowercase
  33.  
  34. INDEX
  35.         towlower
  36.  
  37. ANSI_SYNOPSIS
  38.         #include <wctype.h>
  39.         wint_t towlower(wint_t <[c]>);
  40.  
  41. TRAD_SYNOPSIS
  42.         #include <wctype.h>
  43.         wint_t towlower(<[c]>)
  44.         wint_t <[c]>;
  45.  
  46.  
  47. DESCRIPTION
  48. <<towlower>> is a function which converts uppercase wide characters to
  49. lowercase, leaving all other characters unchanged.
  50.  
  51. RETURNS
  52. <<towlower>> returns the lowercase equivalent of <[c]> when it is a
  53. uppercase wide character; otherwise, it returns the input character.
  54.  
  55. PORTABILITY
  56. <<towlower>> is C99.
  57.  
  58. No supporting OS subroutines are required.
  59. */
  60.  
  61. #include <_ansi.h>
  62. #include <newlib.h>
  63. #include <string.h>
  64. #include <reent.h>
  65. #include <ctype.h>
  66. #include <wctype.h>
  67. #include "local.h"
  68.  
  69. wint_t
  70. _DEFUN(towlower,(c), wint_t c)
  71. {
  72. #ifdef _MB_CAPABLE
  73.   c = _jp2uc (c);
  74.   /* Based on and tested against Unicode 5.2 */
  75.  
  76.   /* Expression used to filter out the characters for the below code:
  77.  
  78.      awk -F\; '{ if ( $14 != "" ) print $1; }' UnicodeData.txt
  79.   */
  80.   if (c < 0x100)
  81.     {
  82.       if ((c >= 0x0041 && c <= 0x005a) ||
  83.           (c >= 0x00c0 && c <= 0x00d6) ||
  84.           (c >= 0x00d8 && c <= 0x00de))
  85.         return (c + 0x20);
  86.  
  87.       return c;
  88.     }
  89.   else if (c < 0x300)
  90.     {
  91.       if ((c >= 0x0100 && c <= 0x012e) ||
  92.           (c >= 0x0132 && c <= 0x0136) ||
  93.           (c >= 0x014a && c <= 0x0176) ||
  94.           (c >= 0x01de && c <= 0x01ee) ||
  95.           (c >= 0x01f8 && c <= 0x021e) ||
  96.           (c >= 0x0222 && c <= 0x0232))
  97.         {
  98.           if (!(c & 0x01))
  99.             return (c + 1);
  100.           return c;
  101.         }
  102.  
  103.       if (c == 0x0130)
  104.         return 0x0069;
  105.  
  106.       if ((c >= 0x0139 && c <= 0x0147) ||
  107.           (c >= 0x01cd && c <= 0x01db))
  108.         {
  109.           if (c & 0x01)
  110.             return (c + 1);
  111.           return c;
  112.         }
  113.      
  114.       if (c >= 0x178 && c <= 0x01f7)
  115.         {
  116.           wint_t k;
  117.           switch (c)
  118.             {
  119.             case 0x0178:
  120.               k = 0x00ff;
  121.               break;
  122.             case 0x0179:
  123.             case 0x017b:
  124.             case 0x017d:
  125.             case 0x0182:
  126.             case 0x0184:
  127.             case 0x0187:
  128.             case 0x018b:
  129.             case 0x0191:
  130.             case 0x0198:
  131.             case 0x01a0:
  132.             case 0x01a2:
  133.             case 0x01a4:
  134.             case 0x01a7:
  135.             case 0x01ac:
  136.             case 0x01af:
  137.             case 0x01b3:
  138.             case 0x01b5:
  139.             case 0x01b8:
  140.             case 0x01bc:
  141.             case 0x01c5:
  142.             case 0x01c8:
  143.             case 0x01cb:
  144.             case 0x01cd:
  145.             case 0x01cf:
  146.             case 0x01d1:
  147.             case 0x01d3:
  148.             case 0x01d5:
  149.             case 0x01d7:
  150.             case 0x01d9:
  151.             case 0x01db:
  152.             case 0x01f2:
  153.             case 0x01f4:
  154.               k = c + 1;
  155.               break;
  156.             case 0x0181:
  157.               k = 0x0253;
  158.               break;
  159.             case 0x0186:
  160.               k = 0x0254;
  161.               break;
  162.             case 0x0189:
  163.               k = 0x0256;
  164.               break;
  165.             case 0x018a:
  166.               k = 0x0257;
  167.               break;
  168.             case 0x018e:
  169.               k = 0x01dd;
  170.               break;
  171.             case 0x018f:
  172.               k = 0x0259;
  173.               break;
  174.             case 0x0190:
  175.               k = 0x025b;
  176.               break;
  177.             case 0x0193:
  178.               k = 0x0260;
  179.               break;
  180.             case 0x0194:
  181.               k = 0x0263;
  182.               break;
  183.             case 0x0196:
  184.               k = 0x0269;
  185.               break;
  186.             case 0x0197:
  187.               k = 0x0268;
  188.               break;
  189.             case 0x019c:
  190.               k = 0x026f;
  191.               break;
  192.             case 0x019d:
  193.               k = 0x0272;
  194.               break;
  195.             case 0x019f:
  196.               k = 0x0275;
  197.               break;
  198.             case 0x01a6:
  199.               k = 0x0280;
  200.               break;
  201.             case 0x01a9:
  202.               k = 0x0283;
  203.               break;
  204.             case 0x01ae:
  205.               k = 0x0288;
  206.               break;
  207.             case 0x01b1:
  208.               k = 0x028a;
  209.               break;
  210.             case 0x01b2:
  211.               k = 0x028b;
  212.               break;
  213.             case 0x01b7:
  214.               k = 0x0292;
  215.               break;
  216.             case 0x01c4:
  217.             case 0x01c7:
  218.             case 0x01ca:
  219.             case 0x01f1:
  220.               k = c + 2;
  221.               break;
  222.             case 0x01f6:
  223.               k = 0x0195;
  224.               break;
  225.             case 0x01f7:
  226.               k = 0x01bf;
  227.               break;
  228.             default:
  229.               k = 0;
  230.             }
  231.           if (k != 0)
  232.             return k;
  233.         }
  234.       else if (c == 0x0220)
  235.         return 0x019e;
  236.       else if (c >= 0x023a && c <= 0x024e)
  237.         {
  238.           wint_t k;
  239.           switch (c)
  240.             {
  241.             case 0x023a:
  242.               k = 0x2c65;
  243.               break;
  244.             case 0x023b:
  245.             case 0x0241:
  246.             case 0x0246:
  247.             case 0x0248:
  248.             case 0x024a:
  249.             case 0x024c:
  250.             case 0x024e:
  251.               k = c + 1;
  252.               break;
  253.             case 0x023d:
  254.               k = 0x019a;
  255.               break;
  256.             case 0x023e:
  257.               k = 0x2c66;
  258.               break;
  259.             case 0x0243:
  260.               k = 0x0180;
  261.               break;
  262.             case 0x0244:
  263.               k = 0x0289;
  264.               break;
  265.             case 0x0245:
  266.               k = 0x028c;
  267.               break;
  268.             default:
  269.               k = 0;
  270.             }
  271.           if (k != 0)
  272.             return k;
  273.         }
  274.     }
  275.   else if (c < 0x0400)
  276.     {
  277.       if (c == 0x0370 || c == 0x0372 || c == 0x0376)
  278.         return (c + 1);
  279.       if (c >= 0x0391 && c <= 0x03ab && c != 0x03a2)
  280.         return (c + 0x20);
  281.       if (c >= 0x03d8 && c <= 0x03ee && !(c & 0x01))
  282.         return (c + 1);
  283.       if (c >= 0x0386 && c <= 0x03ff)
  284.         {
  285.           wint_t k;
  286.           switch (c)
  287.             {
  288.             case 0x0386:
  289.               k = 0x03ac;
  290.               break;
  291.             case 0x0388:
  292.               k = 0x03ad;
  293.               break;
  294.             case 0x0389:
  295.               k = 0x03ae;
  296.               break;
  297.             case 0x038a:
  298.               k = 0x03af;
  299.               break;
  300.             case 0x038c:
  301.               k = 0x03cc;
  302.               break;
  303.             case 0x038e:
  304.               k = 0x03cd;
  305.               break;
  306.             case 0x038f:
  307.               k = 0x03ce;
  308.               break;
  309.             case 0x03cf:
  310.               k = 0x03d7;
  311.               break;
  312.             case 0x03f4:
  313.               k = 0x03b8;
  314.               break;
  315.             case 0x03f7:
  316.               k = 0x03f8;
  317.               break;
  318.             case 0x03f9:
  319.               k = 0x03f2;
  320.               break;
  321.             case 0x03fa:
  322.               k = 0x03fb;
  323.               break;
  324.             case 0x03fd:
  325.               k = 0x037b;
  326.               break;
  327.             case 0x03fe:
  328.               k = 0x037c;
  329.               break;
  330.             case 0x03ff:
  331.               k = 0x037d;
  332.               break;
  333.             default:
  334.               k = 0;
  335.             }
  336.           if (k != 0)
  337.             return k;
  338.         }
  339.     }
  340.   else if (c < 0x500)
  341.     {
  342.       if (c >= 0x0400 && c <= 0x040f)
  343.         return (c + 0x50);
  344.      
  345.       if (c >= 0x0410 && c <= 0x042f)
  346.         return (c + 0x20);
  347.      
  348.       if ((c >= 0x0460 && c <= 0x0480) ||
  349.           (c >= 0x048a && c <= 0x04be) ||
  350.           (c >= 0x04d0 && c <= 0x04fe))
  351.         {
  352.           if (!(c & 0x01))
  353.             return (c + 1);
  354.           return c;
  355.         }
  356.      
  357.       if (c == 0x04c0)
  358.         return 0x04cf;
  359.  
  360.       if (c >= 0x04c1 && c <= 0x04cd)
  361.         {
  362.           if (c & 0x01)
  363.             return (c + 1);
  364.           return c;
  365.         }
  366.     }
  367.   else if (c < 0x1f00)
  368.     {
  369.       if ((c >= 0x0500 && c <= 0x050e) ||
  370.           (c >= 0x0510 && c <= 0x0524) ||
  371.           (c >= 0x1e00 && c <= 0x1e94) ||
  372.           (c >= 0x1ea0 && c <= 0x1ef8))
  373.         {
  374.           if (!(c & 0x01))
  375.             return (c + 1);
  376.           return c;
  377.         }
  378.      
  379.       if (c >= 0x0531 && c <= 0x0556)
  380.         return (c + 0x30);
  381.  
  382.       if (c >= 0x10a0 && c <= 0x10c5)
  383.         return (c + 0x1c60);
  384.  
  385.       if (c == 0x1e9e)
  386.         return 0x00df;
  387.  
  388.       if (c >= 0x1efa && c <= 0x1efe && !(c & 0x01))
  389.         return (c + 1);
  390.     }
  391.   else if (c < 0x2000)
  392.     {
  393.       if ((c >= 0x1f08 && c <= 0x1f0f) ||
  394.           (c >= 0x1f18 && c <= 0x1f1d) ||
  395.           (c >= 0x1f28 && c <= 0x1f2f) ||
  396.           (c >= 0x1f38 && c <= 0x1f3f) ||
  397.           (c >= 0x1f48 && c <= 0x1f4d) ||
  398.           (c >= 0x1f68 && c <= 0x1f6f) ||
  399.           (c >= 0x1f88 && c <= 0x1f8f) ||
  400.           (c >= 0x1f98 && c <= 0x1f9f) ||
  401.           (c >= 0x1fa8 && c <= 0x1faf))
  402.         return (c - 0x08);
  403.  
  404.       if (c >= 0x1f59 && c <= 0x1f5f)
  405.         {
  406.           if (c & 0x01)
  407.             return (c - 0x08);
  408.           return c;
  409.         }
  410.    
  411.       if (c >= 0x1fb8 && c <= 0x1ffc)
  412.         {
  413.           wint_t k;
  414.           switch (c)
  415.             {
  416.             case 0x1fb8:
  417.             case 0x1fb9:
  418.             case 0x1fd8:
  419.             case 0x1fd9:
  420.             case 0x1fe8:
  421.             case 0x1fe9:
  422.               k = c - 0x08;
  423.               break;
  424.             case 0x1fba:
  425.             case 0x1fbb:
  426.               k = c - 0x4a;
  427.               break;
  428.             case 0x1fbc:
  429.               k = 0x1fb3;
  430.               break;
  431.             case 0x1fc8:
  432.             case 0x1fc9:
  433.             case 0x1fca:
  434.             case 0x1fcb:
  435.               k = c - 0x56;
  436.               break;
  437.             case 0x1fcc:
  438.               k = 0x1fc3;
  439.               break;
  440.             case 0x1fda:
  441.             case 0x1fdb:
  442.               k = c - 0x64;
  443.               break;
  444.             case 0x1fea:
  445.             case 0x1feb:
  446.               k = c - 0x70;
  447.               break;
  448.             case 0x1fec:
  449.               k = 0x1fe5;
  450.               break;
  451.             case 0x1ff8:
  452.             case 0x1ff9:
  453.               k = c - 0x80;
  454.               break;
  455.             case 0x1ffa:
  456.             case 0x1ffb:
  457.               k = c - 0x7e;
  458.               break;
  459.             case 0x1ffc:
  460.               k = 0x1ff3;
  461.               break;
  462.             default:
  463.               k = 0;
  464.             }
  465.           if (k != 0)
  466.             return k;
  467.         }
  468.     }
  469.   else if (c < 0x2c00)
  470.     {
  471.       if (c >= 0x2160 && c <= 0x216f)
  472.         return (c + 0x10);
  473.  
  474.       if (c >= 0x24b6 && c <= 0x24cf)
  475.         return (c + 0x1a);
  476.      
  477.       switch (c)
  478.         {
  479.         case 0x2126:
  480.           return 0x03c9;
  481.         case 0x212a:
  482.           return 0x006b;
  483.         case 0x212b:
  484.           return 0x00e5;
  485.         case 0x2132:
  486.           return 0x214e;
  487.         case 0x2183:
  488.           return 0x2184;
  489.         }
  490.     }
  491.   else if (c < 0x2d00)
  492.     {
  493.       if (c >= 0x2c00 && c <= 0x2c2e)
  494.         return (c + 0x30);
  495.  
  496.       if (c >= 0x2c80 && c <= 0x2ce2 && !(c & 0x01))
  497.         return (c + 1);
  498.  
  499.       switch (c)
  500.         {
  501.         case 0x2c60:
  502.           return 0x2c61;
  503.         case 0x2c62:
  504.           return 0x026b;
  505.         case 0x2c63:
  506.           return 0x1d7d;
  507.         case 0x2c64:
  508.           return 0x027d;
  509.         case 0x2c67:
  510.         case 0x2c69:
  511.         case 0x2c6b:
  512.         case 0x2c72:
  513.         case 0x2c75:
  514.         case 0x2ceb:
  515.         case 0x2ced:
  516.           return c + 1;
  517.         case 0x2c6d:
  518.           return 0x0251;
  519.         case 0x2c6e:
  520.           return 0x0271;
  521.         case 0x2c6f:
  522.           return 0x0250;
  523.         case 0x2c70:
  524.           return 0x0252;
  525.         case 0x2c7e:
  526.           return 0x023f;
  527.         case 0x2c7f:
  528.           return 0x0240;
  529.         }
  530.     }
  531.   else if (c >= 0xa600 && c < 0xa800)
  532.     {
  533.       if ((c >= 0xa640 && c <= 0xa65e) ||
  534.           (c >= 0xa662 && c <= 0xa66c) ||
  535.           (c >= 0xa680 && c <= 0xa696) ||
  536.           (c >= 0xa722 && c <= 0xa72e) ||
  537.           (c >= 0xa732 && c <= 0xa76e) ||
  538.           (c >= 0xa77f && c <= 0xa786))
  539.         {
  540.           if (!(c & 1))
  541.             return (c + 1);
  542.           return c;
  543.         }
  544.  
  545.       switch (c)
  546.         {
  547.         case 0xa779:
  548.         case 0xa77b:
  549.         case 0xa77e:
  550.         case 0xa78b:
  551.           return (c + 1);
  552.         case 0xa77d:
  553.           return 0x1d79;
  554.         }
  555.     }
  556.   else
  557.     {
  558.       if (c >= 0xff21 && c <= 0xff3a)
  559.         return (c + 0x20);
  560.      
  561.       if (c >= 0x10400 && c <= 0x10427)
  562.         return (c + 0x28);
  563.     }
  564.   return c;
  565. #else
  566.   return (c < 0x00ff ? (wint_t)(tolower ((int)c)) : c);
  567. #endif /* _MB_CAPABLE */
  568. }
  569.  
  570.