This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
volunteer project: srfi 14 (char-sets)
- From: Per Bothner <per at bothner dot com>
- To: kawa at sources dot redhat dot com
- Date: Wed, 23 Mar 2005 21:36:08 -0800
- Subject: 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/