Example #1
0
static int map_range_to_class_method (Lexical_Element_Type *from,
				      Lexical_Element_Type *to, int invert,
				      SLwchar_Type in, SLwchar_Type *out)
{
   int ok = ((in >= from->e.range[0]) && (in <= from->e.range[1]));
   if (0 == (ok ^ invert))
     return 0;

   if (to->e.char_class == SLCHARCLASS_UPPER)
     *out = SLwchar_toupper (in);
   else if (to->e.char_class == SLCHARCLASS_LOWER)
     *out = SLwchar_tolower (in);
   else
     return 0;

   return 1;
}
Example #2
0
static int map_class_to_class_method (Lexical_Element_Type *from,
				      Lexical_Element_Type *to, int invert,
				      SLwchar_Type in, SLwchar_Type *out)
{
   int ok = is_of_class (from->e.char_class, in);
   if (0 == (ok ^ invert))
     return 0;

   if (to->e.char_class == SLCHARCLASS_UPPER)
     *out = SLwchar_toupper (in);
   else if (to->e.char_class == SLCHARCLASS_LOWER)
     *out = SLwchar_tolower (in);
   else
     return 0;

   return 1;
}
Example #3
0
int SLutf8_compare (SLuchar_Type *a, SLuchar_Type *amax, 
                    SLuchar_Type *b, SLuchar_Type *bmax,
                    unsigned int nchars,
                    int cs)
{
   while (nchars && (a < amax) && (b < bmax))
     {
        SLwchar_Type cha, chb;
        unsigned int na, nb;
        int aok, bok;

        if (*a < 0x80)
          {
             cha = (SLwchar_Type) *a++;
             aok = 1;
          }
        else
          {
             aok = (NULL != SLutf8_decode (a, amax, &cha, &na));
             a += na;
          }

        if (*b < 0x80)
          {
             chb = (SLwchar_Type) *b++;
             bok = 1;
          }
        else
          {
             bok = (NULL != SLutf8_decode (b, bmax, &chb, &nb));
             b += nb;
          }

        nchars--;

        if (aok && bok)
          {
             if (cs == 0)
               {
                  cha = SLwchar_toupper (cha);
                  chb = SLwchar_toupper (chb);
               }
          }
        else if (aok)
          return 1;
        else if (bok)
          return -1;
        
        if (cha == chb)
          continue;
        
        if (cha > chb)
          return 1;

        return -1;
     }

   if (nchars == 0)
     return 0;

   if ((a >= amax) && (b >= bmax))
     return 0;
   
   if (b >= bmax)
     return 1;
   
   return -1;
}