Simplified constructor template, fixed version .. sorry ;_;
downs
default_357-line at yahoo.de
Sun Sep 30 05:43:34 PDT 2007
DAMNIT!
That's what I get for making last-minute changes without properly
checking if they actually worked.
Again, my apologies.
--downs
Fixed version:
template cutOff(string what, string where) {
static if (what.length<where.length) const string cutOff=what;
else static if (what[0..where.length]==where) const string cutOff="";
else const string cutOff=what[0]~cutOff!(what[1..$], where);
}
template rmSpace(string s, bool command=false) {
static if (!s.length) const string rmSpace=""; else
static if (command) {
static if (s[0]==';') const string rmSpace=';'~rmSpace!(s[1..$]);
else const string rmSpace=s[0]~rmSpace!(s[1..$], true);
} else
static if (s[0]=='#') const string rmSpace='#'~rmSpace!(s[1..$],
true); else
static if (s[0]==' ' || s[0]=='\r' || s[0]=='\n' || s[0]=='\t') const
string rmSpace=rmSpace!(s[1..$]); else
const string rmSpace=s[0]~rmSpace!(s[1..$]);
}
template thisHeader(string s, string buffer="", bool command=false) {
static if (!s.length)
static if (!buffer.length) const string thisHeader="";
else const string thisHeader="typeof("~cutOff!(buffer, "=")~")
_"~buffer;
else static if (command)
static if (s[0]==';') const string thisHeader=thisHeader!(s[1..$]);
else const string thisHeader=thisHeader!(s[1..$], buffer~s[0], true);
else static if (s[0] == '#') const string
thisHeader=thisHeader!(s[1..$], "", true);
else static if (s[0]=='(') const string thisHeader=thisHeader!(s[1..$]);
else static if (s[0]==')' || s[0]==',') {
static if (!buffer.length) const string thisHeader=thisHeader!(s[1..$]);
else const string thisHeader="typeof("~cutOff!(buffer, "=")~")
_"~buffer~(
(s.length>1)
?(thisHeader!(s[1..$]).length?(", "~thisHeader!(s[1..$])):"")
:""
);
} else const string thisHeader=thisHeader!(s[1..$], buffer~s[0], command);
}
template assigns(string s, string buffer="", bool sup=false, bool
command=false) {
static if (!s.length) {
static if (buffer.length) const string
assigns="this."~cutOff!(buffer, "=")~" = _"~cutOff!(buffer, "=")~"; ";
else const string assigns="";
} else static if (command) {
static if (s[0]==';') const string assigns=buffer~";
"~assigns!(s[1..$]);
else const string assigns=assigns!(s[1..$], buffer~s[0], false, true);
} else static if (s[0]=='#') {
static assert(!sup, "# invalid in super");
const string assigns=assigns!(s[1..$], "", false, true);
} else static if (s[0]=='(') {
static assert(buffer=="super", "Invalid code "~buffer);
const string assigns=buffer~"("~assigns!(s[1..$], "", true);
} else static if (s[0]==')') {
static assert(sup, "Parenthesis Mismatch");
const string assigns="_"~cutOff!(buffer, "=")~"); "~assigns!(s[1..$]);
} else static if (s[0]==',') {
static if (!buffer.length) const string assigns=assigns!(s[1..$],
"", sup);
else static if (sup) const string assigns="_"~cutOff!(buffer,
"=")~", "~assigns!(s[1..$], "", true);
else const string assigns="this."~cutOff!(buffer, "=")~" =
_"~cutOff!(buffer, "=")~"; "~assigns!(s[1..$]);
} else const string assigns=assigns!(s[1..$], buffer~s[0], sup, command);
}
template This(string T) {
mixin("this("~thisHeader!(rmSpace!(T))~") { "~assigns!(rmSpace!(T))~" }");
}
More information about the Digitalmars-d
mailing list