mirror of
https://github.com/libretro/scummvm.git
synced 2025-03-01 07:46:11 +00:00
DIRECTOR: LINGO: Implement the last item of
Returns the last item of a chunkexpression. It follows the item Delimiter.
This commit is contained in:
parent
d7ed2e453e
commit
6b09c3de62
@ -2429,10 +2429,23 @@ void LB::b_lastcharof(int nargs) {
|
||||
|
||||
void LB::b_lastitemof(int nargs) {
|
||||
Datum d = g_lingo->pop();
|
||||
if (d.type != STRING) {
|
||||
warning("LB::b_lastitemof(): Called with wrong data type: %s", d.type2str());
|
||||
g_lingo->push(Datum(""));
|
||||
return;
|
||||
}
|
||||
|
||||
warning("STUB: b_lastitemof");
|
||||
Common::String res;
|
||||
Common::String chunkExpr = d.asString();
|
||||
uint pos = chunkExpr.findLastOf(g_lingo->_itemDelimiter);
|
||||
if (pos == Common::String::npos) {
|
||||
res = chunkExpr;
|
||||
} else {
|
||||
pos++; // skip the item delimiter
|
||||
res = chunkExpr.substr(pos , chunkExpr.size() - pos);
|
||||
}
|
||||
|
||||
g_lingo->push(Datum(0));
|
||||
g_lingo->push(Datum(res));
|
||||
}
|
||||
|
||||
void LB::b_lastlineof(int nargs) {
|
||||
|
@ -88,3 +88,13 @@ scummvmAssertEqual(res, "")
|
||||
-- LB::b_lastcharof
|
||||
scummvmAssertEqual(the last char of "", "")
|
||||
scummvmAssertEqual(the last char of "hello", "o")
|
||||
|
||||
-- LB::b_lastitemof
|
||||
scummvmAssertEqual(the last item of "", "")
|
||||
scummvmAssertEqual(the last item of "onetwo", "onetwo")
|
||||
scummvmAssertEqual(the last item of "one,two", "two")
|
||||
set save to the itemDelimiter
|
||||
set the itemDelimiter to ":"
|
||||
scummvmAssertEqual(the last item of "one:two", "two")
|
||||
set the itemDelimiter to save
|
||||
scummvmAssertEqual(the last item of "onetwo", "onetwo")
|
||||
|
Loading…
x
Reference in New Issue
Block a user