40 lines
798 B
TypeScript
40 lines
798 B
TypeScript
import { BooleanExpression } from "./BooleanExpression";
|
|
|
|
export abstract class StringValueMatcher<T> extends BooleanExpression<T>
|
|
{
|
|
abstract getStringValue( t:T ):string;
|
|
}
|
|
|
|
export abstract class LitaralMatcher<T,L extends string> extends StringValueMatcher<T>
|
|
{
|
|
_literal:L
|
|
constructor( literal:L )
|
|
{
|
|
super();
|
|
this._literal = literal;
|
|
}
|
|
|
|
evaluate( t:T )
|
|
{
|
|
let value = this.getStringValue( t );
|
|
return this._literal === value;
|
|
}
|
|
}
|
|
|
|
export abstract class RegExpMatcher<T> extends StringValueMatcher<T>
|
|
{
|
|
private _regexp:RegExp;
|
|
|
|
constructor( regexp:RegExp )
|
|
{
|
|
super();
|
|
this._regexp = regexp;
|
|
}
|
|
|
|
evaluate( t:T )
|
|
{
|
|
let value = this.getStringValue( t );
|
|
return this._regexp.test( value );
|
|
}
|
|
|
|
} |