View previous topic :: View next topic |
Author |
Message |
Ligustah
Joined: 21 Oct 2007 Posts: 45 Location: Berlin, Germany
|
Posted: Sun Oct 28, 2007 11:15 am Post subject: stringlib startsWith, endsWith |
|
|
Hi!
I thought that the stringlib needed starts-/endsWith, so i made them. They are just a few lines of code: Code: | int endsWith(MDState s, uint numParams)
{
dchar[] str = s.getContext!(dchar[]);
dchar[] find = s.getParam!(dchar[])(0);
s.push(tango.core.Array.rfind(str, find) == str.length-find.length);
return 1;
}
int startsWith(MDState s, uint numParams)
{
dchar[] str = s.getContext!(dchar[]);
dchar[] find = s.getParam!(dchar[])(0);
s.push(tango.core.Array.find(str, find) == 0);
return 1;
} |
You have to append them to stringlib.d and add these two lines to the list in the init function of the stringlib: Code: | "endsWith"d, new MDClosure(namespace, &lib.endsWith, "string.endsWith"),
"startsWith"d, new MDClosure(namespace, &lib.startsWith, "string.startsWith"), |
I think they're pretty useful and i hope you can use them
Mfg Ligustah |
|
Back to top |
|
|
JarrettBillingsley
Joined: 20 Jun 2006 Posts: 457 Location: Pennsylvania!
|
Posted: Sun Oct 28, 2007 4:14 pm Post subject: |
|
|
Good idea, I'll put them in. |
|
Back to top |
|
|
Ligustah
Joined: 21 Oct 2007 Posts: 45 Location: Berlin, Germany
|
Posted: Tue Oct 30, 2007 6:49 am Post subject: |
|
|
With a few changes you could also add istarsWith and iendsWith, if you do not have them yet : Code: | int istartsWith(MDState s, uint numParams)
{
dchar[] str = toLowerD(s.getContext!(dchar[]));
dchar[] find = toLowerD(s.getParam!(dchar[])(0));
s.push(tango.core.Array.find(str, find) == 0);
return 1;
}
int iendsWith(MDState s, uint numParams)
{
dchar[] str = toLowerD(s.getContext!(dchar[]));
dchar[] find = toLowerD(s.getParam!(dchar[])(0));
s.push(tango.core.Array.rfind(str, find) == str.length-find.length);
return 1;
}
|
Mfg Ligustah |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|