cvsuser     03/11/06 12:56:06

  Modified:    chartypes unicode.c
               src      chartype.c
  Log:
  Interim (pre-ICU) implementation of isupper/lower/alpha/alnum for Unicode
  
  Revision  Changes    Path
  1.20      +112 -1    parrot/chartypes/unicode.c
  
  Index: unicode.c
  ===================================================================
  RCS file: /cvs/public/parrot/chartypes/unicode.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -w -r1.19 -r1.20
  --- unicode.c 4 Nov 2003 16:22:27 -0000       1.19
  +++ unicode.c 6 Nov 2003 20:56:03 -0000       1.20
  @@ -1,7 +1,7 @@
   /* unicode.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: unicode.c,v 1.19 2003/11/04 16:22:27 petergibbs Exp $
  + *     $Id: unicode.c,v 1.20 2003/11/06 20:56:03 petergibbs Exp $
    *  Overview:
    *     This defines the US-ASCII character type routines.
    *  Data Structure and Algorithms:
  @@ -42,10 +42,113 @@
      { 0, 0, -1 }
   };
   
  +/* Inversions lists based on Unicode 4.0 */
  +static Parrot_UInt unicode_upper[] = {
  +    65,26,101,23,1,7,33,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,2,1,1,1,1,3,2,1,1,1,2,1,3,2,4,1,2,1,3,3,2,1,2,1,1,1,
  +    1,1,2,1,1,2,1,1,2,1,3,1,1,1,2,3,1,7,1,2,1,2,1,2,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,2,1,1,
  +    3,1,1,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1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,15,8,8,6,10,8,8,8,8,6,
  +    11,1,1,1,1,1,1,1,8,8,72,4,12,4,12,4,12,5,11,4,262,1,4,1,3,3,2,
  +    3,2,1,3,5,6,1,1,1,1,1,1,4,2,2,1,1,10,2,5,1,56795,26,1221,40,5,
  +    3208,26,26,26,26,26,26,1,1,2,2,1,2,2,2,4,1,8,26,26,26,2,1,4,2,
  +    8,1,7,27,2,1,4,1,5,1,1,3,7,27,26,26,26,26,26,26,26,26,26,26,2,
  +    6,30,25,33,25,33,25,33,25,33,25,993367
  +};
  +
  +static Parrot_UInt unicode_lower[] = {
  +    97,26,47,1,10,1,4,1,36,24,1,8,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,3,2,1,1,1,2,1,3,2,4,1,2,1,3,3,2,
  +    1,2,1,1,1,1,1,2,1,1,2,1,1,2,1,3,1,1,1,2,2,2,3,6,1,2,1,2,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,2,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    2,2,1,1,1,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,4,25,96,224,1,27,35,1,2,3,3,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
  +    1,1,1,1,1,1,1,1,5,1,1,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1229,40,53194,26,26,7,1,18,26,26,26,4,1,1,
  +    1,7,1,11,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,26,2,
  +    6,30,25,1,6,26,25,1,6,26,25,1,6,26,25,1,6,26,25,1,6,993334
  +};
  +
  +static Parrot_UInt unicode_alpha[] = {
  +    65,26,6,26,47,1,10,1,4,1,5,23,1,31,1,195,1,4,4,1,1,2,1,2,1,3,
  +    8,1,68,25,96,214,1,1,3,1,1,1,20,1,44,1,38,1,5,4,130,8,69,1,38,
  +    2,2,6,16,33,38,10,39,2840,38,3130,44,54,10,148,156,4,90,6,22,
  +    2,6,2,38,2,6,2,8,1,1,1,1,1,1,1,31,2,8,8,8,8,8,8,5,1,6,2,1,3,3,
  +    1,6,4,4,2,6,4,13,5,3,1,6,117,1,13,1,130,1,4,1,2,10,1,1,3,5,6,
  +    1,1,1,1,1,1,4,1,3,1,2,4,1,3,3,5,5,55734,7,12,5,1033,26,6,26,1,
  +    189,80,53168,85,1,71,1,2,2,1,2,2,2,4,1,12,1,1,1,7,1,65,1,4,2,
  +    8,1,7,1,28,1,4,1,5,1,1,3,7,1,338,4,25,1,25,1,31,1,25,1,31,1,2,
  +    5,1,31,1,25,1,31,1,25,1,6,993334
  +};
  +
  +static Parrot_UInt unicode_alnum[] = {
  +    48,10,7,26,6,26,47,1,10,1,4,1,5,23,1,31,1,195,1,4,4,1,1,2,1,
  +    2,1,38,1,68,25,96,214,1,1,3,1,1,1,20,1,44,1,38,1,5,4,130,8,69,
  +    1,38,2,2,6,16,33,38,10,39,216,10,134,10,620,10,118,10,118,10,
  +    118,10,118,10,119,9,118,10,118,10,118,10,224,10,118,10,70,10,
  +    278,10,86,38,675,9,1134,10,38,10,300,10,944,44,54,10,148,156,
  +    4,90,6,22,2,6,2,38,2,6,2,8,1,1,1,1,1,1,1,31,2,8,8,8,8,8,8,5,1,
  +    6,2,1,3,3,1,6,4,4,2,6,4,13,5,3,1,6,117,1,13,1,130,1,4,1,2,10,
  +    1,1,3,5,6,1,1,1,1,1,1,4,1,3,1,2,4,1,3,3,5,5,55734,7,12,5,1016,
  +    10,7,26,6,26,1189,80,80,10,53078,85,1,71,1,2,2,1,2,2,2,4,1,12,
  +    1,1,1,7,1,65,1,4,2,8,1,7,1,28,1,4,1,5,1,1,3,7,1,338,4,25,1,25,
  +    1,31,1,25,1,31,1,25,1,31,1,25,1,31,1,25,1,6,4,50,993280
  +};
  +
   static struct chartype_transcoder_entry_t unicode_transcoders[] = {
       { NULL, NULL, NULL }
   };
   
  +static int
  +inversion_list(Parrot_UInt *list, const Parrot_UInt c)
  +{
  +             int i;
  +             Parrot_UInt t = 0;
  +
  +             for (i=0; c>=t; i++) {
  +                             t += list[i];
  +    }
  +             return !(i & 1);
  +}
  +
   static INTVAL
   unicode_is_charclass(const struct parrot_chartype_t *type, const Parrot_UInt c, 
                        const unsigned int class)
  @@ -53,6 +156,14 @@
       switch (class) {
           case enum_charclass_digit:
               return chartype_is_digit_mapn(type, c, class);
  +        case enum_charclass_upper:
  +            return inversion_list(unicode_upper, c);
  +        case enum_charclass_lower:
  +            return inversion_list(unicode_lower, c);
  +        case enum_charclass_alpha:
  +            return inversion_list(unicode_alpha, c);
  +        case enum_charclass_alnum:
  +            return inversion_list(unicode_alnum, c);
       }
       internal_exception(INVALID_CHARCLASS, "Unknown character class <%d>\n", 
                          class);
  
  
  
  1.20      +15 -3     parrot/src/chartype.c
  
  Index: chartype.c
  ===================================================================
  RCS file: /cvs/public/parrot/src/chartype.c,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -w -r1.19 -r1.20
  --- chartype.c        4 Nov 2003 16:22:33 -0000       1.19
  +++ chartype.c        6 Nov 2003 20:56:06 -0000       1.20
  @@ -1,7 +1,7 @@
   /* chartype.c
    *  Copyright: 2001-2003 The Perl Foundation.  All Rights Reserved.
    *  CVS Info
  - *     $Id: chartype.c,v 1.19 2003/11/04 16:22:33 petergibbs Exp $
  + *     $Id: chartype.c,v 1.20 2003/11/06 20:56:06 petergibbs Exp $
    *  Overview:
    *     This defines the string character type subsystem
    *  Data Structure and Algorithms:
  @@ -139,12 +139,21 @@
       return chartype_get_digit_mapn(&unicode_chartype, uc);
   }
   
  +static INTVAL
  +chartype_is_charclass_Unicode(const struct parrot_chartype_t *type, 
  +                              const Parrot_UInt c, const unsigned int class)
  +{
  +    UINTVAL uc = chartype_to_unicode_cparray(type, NULL, c);
  +    return unicode_chartype.is_charclass[enum_charclass_SLOW]
  +               (&unicode_chartype, uc, class);
  +}
  +
  +
   /*
    * Create chartype from mapping file
    * Still TODO:
    *   Handle more encodings (singlebyte & dbcs implemented so far)
  - *   Create proper digit mapping table (currently always ascii)
  - *   -> this is REQUIRED for DBCS!
  + *   Create custom digit mapping table
    *   Path is hardcoded to "runtime/parrot/chartypes/<name>.TXT"
    *   Does direct file system IO - should probably use Parrot IO
    *   Better parsing code - e.g. handle erroneous input!
  @@ -162,6 +171,7 @@
       INTVAL *cparray2 = NULL;
       struct chartype_unicode_map_t *map;
       int one2one = 0;
  +    int i;
   
       path = mem_sys_allocate(strlen(name) + 32);
       sprintf(path, "runtime/parrot/chartypes/%s.TXT", name);
  @@ -214,6 +224,8 @@
       }
       type->from_unicode = chartype_from_unicode_cparray;
       type->to_unicode = chartype_to_unicode_cparray;
  +    for (i=0; i<=enum_charclass_SLOW; i++)
  +        type->is_charclass[i] = chartype_is_charclass_Unicode;
       /* XXX Should generate a custom digit mapping table */
       if (enum_charclass_digit < enum_charclass_SLOW)
           type->is_charclass[enum_charclass_digit] = chartype_is_digit_Unicode;
  
  
  

Reply via email to