This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

volunteer project: srfi 14 (char-sets)


Srfi-13 is requested by multiple people.  But it builds on at least a basic
subset of srfi-14 (charsets) so we need someone to do that first.  Basic idea:

package gnu.kawa.util;

public abstract class CharacterPredicate
{
  public abstract boolean contains (int charVal);

  public static CharacterPredicate lowerCase
    = new BuiltinCharacterPredicate(LOWER_CASE_LETTER);
  ... etc ...
}

class BuiltinCharacterPredicate extends CharacterPredicate
{
  static final int LOWER_CASE_LETTER = 1;
  ...
  int kind;
  BuiltinCharacterPredicate (int kind) { this.kind = kind; }
  public boolean contains (int codePoint)
  {
    switch (kind)
      {
        case LOWER_CASE_LETTER:
          /* #ifdef JAVA5 */
          return Character.isLowerCase(codePoint);
          /* #else */
          return haracter.isLowerCase((char) codePoint);
          /* #endif */
        ....
      }
  }
}

public class CharacterSet extends CharacterPredicate
{
  int numRanges;
  /** numRanges pairs of sorted [low, high) ranges. */
  int[] ranges[];
  public boolean contains (int codePoint)
  {
    int lo = 0, hi = numRanges;
    binary search for i such that:
      codePoint >= ranges[2*i] && codePoint < ranges[2*(i+1)];
    return codePoint < ranges[2*i+1];
  }

  // Set operations would be implemented by merging ranges.
  // They're not required for SRFI-13, so can be deferred until needed.
}

The Scheme wrappers should be straight-forward for anyone experienced
with Kawa.

Note that RangeTable is a more general (int -> Object) map.  Perhaps
we should try to share implementation with CharacterSet, which can
be viewed as an (int -> Boolean) map.  In both cases the implementation
should be optimized for ranges (normally of characters) mapping to the
same value.
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]