Back to index

glibc  2.9
indigitswc.h
Go to the documentation of this file.
00001 /* Copyright (C) 2000 Free Software Foundation, Inc.
00002    This file is part of the GNU C Library.
00003    Contributed by Ulrich Drepper <drepper@gnu.org>, 2000.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <assert.h>
00021 #include <langinfo.h>
00022 
00023 /* Look up the value of the next multibyte character and return its numerical
00024    value if it is one of the digits known in the locale.  If *DECIDED is
00025    -1 this means it is not yet decided which form it is and we have to
00026    search through all available digits.  Otherwise we know which script
00027    the digits are from.  */
00028 static inline int
00029 indigitwc_value (wchar_t wc, int *decided)
00030 {
00031   int from_level;
00032   int to_level;
00033   const wchar_t *wcdigits[10];
00034   int n;
00035 
00036   if (*decided != -1)
00037     from_level = to_level = *decided;
00038   else
00039     {
00040       from_level = 0;
00041       to_level = _NL_CURRENT_WORD (LC_CTYPE, _NL_CTYPE_INDIGITS_WC_LEN) - 1;
00042       assert (from_level <= to_level);
00043     }
00044 
00045   /* In this round we get the pointer to the digit strings and also perform
00046      the first round of comparisons.  */
00047   for (n = 0; n < 10; ++n)
00048     {
00049       /* Get the string for the digits with value N.  */
00050       wcdigits[n] = _NL_CURRENT (LC_CTYPE, _NL_CTYPE_INDIGITS0_WC + n);
00051       wcdigits[n] += from_level;
00052 
00053       if (wc == *wcdigits[n])
00054        {
00055          /* Found it.  */
00056          if (*decided == -1)
00057            *decided = 0;
00058          return n;
00059        }
00060 
00061       /* Advance the pointer to the next string.  */
00062       ++wcdigits[n];
00063     }
00064 
00065   /* Now perform the remaining tests.  */
00066   while (++from_level <= to_level)
00067     {
00068       /* Search all ten digits of this level.  */
00069       for (n = 0; n < 10; ++n)
00070        {
00071          if (wc == *wcdigits[n])
00072            {
00073              /* Found it.  */
00074              if (*decided == -1)
00075               *decided = from_level;
00076              return n;
00077            }
00078 
00079          /* Advance the pointer to the next string.  */
00080          ++wcdigits[n];
00081        }
00082     }
00083 
00084   /* If we reach this point no matching digit was found.  */
00085   return -1;
00086 }