[Scummvm-git-logs] scummvm master -> 4b5d2382336bb74134c1d0e27ad141d1a123ed65
sev-
sev at scummvm.org
Fri Jan 24 20:14:18 UTC 2020
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
4b5d238233 DIRECTOR: LINGO: Add numberofwords implementation.
Commit: 4b5d2382336bb74134c1d0e27ad141d1a123ed65
https://github.com/scummvm/scummvm/commit/4b5d2382336bb74134c1d0e27ad141d1a123ed65
Author: Roland van Laar (roland at rolandvanlaar.nl)
Date: 2020-01-24T21:14:14+01:00
Commit Message:
DIRECTOR: LINGO: Add numberofwords implementation.
b_numberofwords counts the number of words in a string.
We check of the current char in a string is a space,
if so check if the previous one wasn't a space, then count it as a word.
Director 4 counts everything non-space (i.e. \n, \t, etc) as a
word seperator. A word can be a single '.'.
Include better stringassignment for b_numberoflines.
Changed paths:
engines/director/lingo/lingo-builtins.cpp
diff --git a/engines/director/lingo/lingo-builtins.cpp b/engines/director/lingo/lingo-builtins.cpp
index 4ce2c18..ae6b60c 100644
--- a/engines/director/lingo/lingo-builtins.cpp
+++ b/engines/director/lingo/lingo-builtins.cpp
@@ -1807,7 +1807,7 @@ void LB::b_numberoflines(int nargs) {
d.toString();
int numberoflines = 1;
- Common::String contents = d.u.s->c_str();
+ Common::String contents = *d.u.s;
for (uint32 i = 0; i < d.u.s->size(); i++) {
if (contents[i] == '\n')
numberoflines++;
@@ -1823,9 +1823,19 @@ void LB::b_numberoflines(int nargs) {
void LB::b_numberofwords(int nargs) {
Datum d = g_lingo->pop();
- warning("STUB: b_numberofwords");
- d.toInt();
- d.u.i = 0;
+ d.toString();
+ int numberofwords = 0;
+ Common::String contents = *d.u.s;
+ for (uint32 i = 1; i < d.u.s->size(); i++) {
+ if (Common::isSpace(contents[i]) && !Common::isSpace(contents[i - 1]))
+ numberofwords++;
+ }
+ // Count the last word
+ if (!Common::isSpace(contents[d.u.s->size() - 1]))
+ numberofwords++;
+
+ d.u.i = numberofwords;
+ d.type = INT;
g_lingo->push(d);
}
More information about the Scummvm-git-logs
mailing list