[Scummvm-git-logs] scummvm master -> 6b09c3de6291fb05ff9298f524484c888833b1fe

rvanlaar roland at rolandvanlaar.nl
Wed Aug 5 13:04:14 UTC 2020


This automated email contains information about 2 new commits which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .

Summary:
d7ed2e453e DIRECTOR: LINGO: Implement the last char of
6b09c3de62 DIRECTOR: LINGO: Implement the last item of


Commit: d7ed2e453e7bedf0146e7aeddb0fc9490b495fcd
    https://github.com/scummvm/scummvm/commit/d7ed2e453e7bedf0146e7aeddb0fc9490b495fcd
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-08-05T15:02:51+02:00

Commit Message:
DIRECTOR: LINGO: Implement the last char of

A zero length string results in a "", otherwise
it's the last char.

Changed paths:
    engines/director/lingo/lingo-builtins.cpp
    engines/director/lingo/tests/strings.lingo


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 6a2bdaebf0..be83b80e1f 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -2414,10 +2414,17 @@ void LB::b_numberofwords(int nargs) {
 
 void LB::b_lastcharof(int nargs) {
 	Datum d = g_lingo->pop();
+	if (d.type != STRING) {
+		warning("LB::b_lastcharof(): Called with wrong data type: %s", d.type2str());
+		g_lingo->push(Datum(""));
+		return;
+	}
 
-	warning("STUB: b_lastcharof");
-
-	g_lingo->push(Datum(0));
+	Common::String contents = d.asString();
+	Common::String res;
+	if (contents.size() != 0)
+		res = contents.lastChar();
+	g_lingo->push(Datum(res));
 }
 
 void LB::b_lastitemof(int nargs) {
diff --git a/engines/director/lingo/tests/strings.lingo b/engines/director/lingo/tests/strings.lingo
index 3af97b5aa8..33df0f926c 100644
--- a/engines/director/lingo/tests/strings.lingo
+++ b/engines/director/lingo/tests/strings.lingo
@@ -84,3 +84,7 @@ scummvmAssertEqual(res, string)
 
 set res to char 50 to 60 of string
 scummvmAssertEqual(res, "")
+
+-- LB::b_lastcharof
+scummvmAssertEqual(the last char of "", "")
+scummvmAssertEqual(the last char of "hello", "o")


Commit: 6b09c3de6291fb05ff9298f524484c888833b1fe
    https://github.com/scummvm/scummvm/commit/6b09c3de6291fb05ff9298f524484c888833b1fe
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-08-05T15:02:51+02:00

Commit Message:
DIRECTOR: LINGO: Implement the last item of

Returns the last item of a chunkexpression.
It follows the item Delimiter.

Changed paths:
    engines/director/lingo/lingo-builtins.cpp
    engines/director/lingo/tests/strings.lingo


diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index be83b80e1f..6b318faeb2 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -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) {
diff --git a/engines/director/lingo/tests/strings.lingo b/engines/director/lingo/tests/strings.lingo
index 33df0f926c..ac11603bf2 100644
--- a/engines/director/lingo/tests/strings.lingo
+++ b/engines/director/lingo/tests/strings.lingo
@@ -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")




More information about the Scummvm-git-logs mailing list