Add String.substr

This commit is contained in:
Michal Moskal 2016-04-12 19:08:26 -07:00
parent df92a3daae
commit a0a0554633

View File

@ -42,6 +42,18 @@ namespace String_ {
{ {
return ManagedString::EmptyString.leakData(); return ManagedString::EmptyString.leakData();
} }
//%
StringData *substr(StringData *s, int start, int length)
{
if (length <= 0)
return mkEmpty();
if (start < 0)
start = max(s->len + start, 0);
length = min(length, s->len - start);
ManagedString x(s);
return x.substring(start, length).leakData();
}
} }