[Simple-support] suggestion for re pattern checkers ...
Brought to you by:
niallg
|
From: -=}\\*/{=- <rui...@gm...> - 2012-07-08 13:13:36
|
hi,
it would be nice to be able configure RE pattern checkers for strings and
primitives...
// primitive
@Attribute (pattern="\d{2}")
int max99;
// string
@Attribute (pattern="\d{1,3}-\d{1,3}")
String range;
@Element (pattern="[a-zA-Z]{4,20}")
String firstName;
@Attribute (pattern="\p{Lower}{14}")
String username;
// object
@Element (pattern="[a-zA-Z]{4,20} [a-zA-Z]{4,20}")
FullName fn;
@Root
class FullName {
String firstName,
String lastName;
// ...
@FromString
public void parse(String s) {...}
@ToString // you may want to use the real toString for other stuff
public String toString() {return firstName + " " + lastName;}
}
//
// the code bellow would be nicer though... no need to write parse code or
repeat patterns :)
//
// object
@Element (pattern="([a-zA-Z]{4,20}) ([a-zA-Z]{4,20})")
FullName fn;
// object
@Element (pattern="([a-zA-Z]{4,20}) ([a-zA-Z]{4,20})")
FullName fn;
@Root (asPrimitive = true)
class FullName {
@Pattern (group = 0)
String firstName,
@Pattern (group = 1)
String lastName;
// ...
@ToString
public String toString() {return firstName + " " + lastName;}
}
... implied when reading and optional when writing...
think about it :)
[NiceSunDay]r.
|