aboutsummaryrefslogtreecommitdiff
path: root/engines/titanic
diff options
context:
space:
mode:
authorPaul Gilbert2016-05-14 19:49:34 -0400
committerPaul Gilbert2016-07-10 16:39:37 -0400
commit69134c66cc700fef16b202354e491b9ab6d0b8c0 (patch)
tree25cf570938e7fa52a0b820a6980ce3ff0f26c128 /engines/titanic
parent1da409ca9891a46bed2a61fc07946165c670c4e6 (diff)
downloadscummvm-rg350-69134c66cc700fef16b202354e491b9ab6d0b8c0.tar.gz
scummvm-rg350-69134c66cc700fef16b202354e491b9ab6d0b8c0.tar.bz2
scummvm-rg350-69134c66cc700fef16b202354e491b9ab6d0b8c0.zip
TITANIC: Implemented parser normalizeContraction
Diffstat (limited to 'engines/titanic')
-rw-r--r--engines/titanic/true_talk/tt_parser.cpp81
-rw-r--r--engines/titanic/true_talk/tt_string.cpp28
-rw-r--r--engines/titanic/true_talk/tt_string.h51
3 files changed, 125 insertions, 35 deletions
diff --git a/engines/titanic/true_talk/tt_parser.cpp b/engines/titanic/true_talk/tt_parser.cpp
index 0bb30a14b5..5aa3576a0f 100644
--- a/engines/titanic/true_talk/tt_parser.cpp
+++ b/engines/titanic/true_talk/tt_parser.cpp
@@ -166,6 +166,87 @@ int TTparser::isSpecialCommand(const TTstring &str, int &index) {
}
bool TTparser::normalizeContraction(const TTstring &srcLine, int srcIndex, TTstring &destLine) {
+ int startIndex = srcIndex + 1;
+ switch (srcLine[startIndex]) {
+ case 'd':
+ srcIndex += 2;
+ if (srcLine.compareAt(srcIndex, " a ") || srcLine.compareAt(srcIndex, " the ")) {
+ destLine += " had";
+ } else {
+ destLine += " would";
+ }
+
+ srcIndex = startIndex;
+ break;
+
+ case 'l':
+ if (srcLine[srcIndex + 2] == 'l') {
+ // 'll ending
+ destLine += " will";
+ srcIndex = startIndex;
+ }
+ break;
+
+ case 'm':
+ // 'm ending
+ destLine += " am";
+ srcIndex = startIndex;
+ break;
+
+ case 'r':
+ // 're ending
+ if (srcLine[srcIndex + 2] == 'e') {
+ destLine += " are";
+ srcIndex = startIndex;
+ }
+ break;
+
+ case 's':
+ destLine += "s*";
+ srcIndex = startIndex;
+ break;
+
+ case 't':
+ if (srcLine[srcIndex - 1] == 'n' && srcIndex >= 3) {
+ if (srcLine[srcIndex - 3] == 'c' && srcLine[srcIndex - 2] == 'a' &&
+ (srcIndex == 3 || srcLine[srcIndex - 4])) {
+ // can't -> can not
+ destLine += 'n';
+ } else if (srcLine[srcIndex - 3] == 'w' && srcLine[srcIndex - 2] == 'o' &&
+ (srcIndex == 3 || srcLine[srcIndex - 4])) {
+ // won't -> will not
+ destLine.deleteLastChar();
+ destLine.deleteLastChar();
+ destLine += "ill";
+ } else if (srcLine[srcIndex - 3] == 'a' && srcLine[srcIndex - 2] == 'i' &&
+ (srcIndex == 3 || srcLine[srcIndex - 4])) {
+ // ain't -> am not
+ destLine.deleteLastChar();
+ destLine.deleteLastChar();
+ destLine += "m";
+ } else if (srcLine.hasSuffix(" sha") ||
+ (srcIndex == 4 && srcLine.hasSuffix("sha"))) {
+ // shan't -> shall not
+ destLine.deleteLastChar();
+ destLine += "ll";
+ }
+
+ destLine += " not";
+ }
+ break;
+
+ case 'v':
+ // 've ending
+ if (srcLine[startIndex + 2] == 'e') {
+ destLine += " have";
+ srcIndex = startIndex;
+ }
+ break;
+
+ default:
+ break;
+ }
+
// TODO
return false;
}
diff --git a/engines/titanic/true_talk/tt_string.cpp b/engines/titanic/true_talk/tt_string.cpp
index 5574cffb48..7a0078788d 100644
--- a/engines/titanic/true_talk/tt_string.cpp
+++ b/engines/titanic/true_talk/tt_string.cpp
@@ -95,34 +95,6 @@ TTstring &TTstring::operator+=(char c) {
return *this;
}
-const char &TTstring::operator[](uint index) {
- return *(c_str() + index);
-}
-
-bool TTstring::empty() const {
- return _data->_string.empty();
-}
-
-char TTstring::firstChar() const {
- return _data->_string.firstChar();
-}
-
-char TTstring::lastChar() const {
- return _data->_string.lastChar();
-}
-
-int TTstring::size() const {
- return _data->_string.size();
-}
-
-TTstring *TTstring::copy() const {
- return new TTstring(c_str());
-}
-
-bool TTstring::isValid() const {
- return _status == SS_VALID;
-}
-
void TTstring::save(SimpleFile *file) const {
file->writeFormat("%s", c_str());
}
diff --git a/engines/titanic/true_talk/tt_string.h b/engines/titanic/true_talk/tt_string.h
index 3b2b6a2245..2009167b75 100644
--- a/engines/titanic/true_talk/tt_string.h
+++ b/engines/titanic/true_talk/tt_string.h
@@ -57,21 +57,51 @@ public:
TTstring &operator+=(const char *str);
TTstring &operator+=(const TTstring &str);
TTstring &operator+=(char c);
- const char &operator[](uint index);
- bool empty() const;
- char firstChar() const;
- char lastChar() const;
- int size() const;
+
+ const char &operator[](uint index) {
+ return *(c_str() + index);
+ }
+
+ bool empty() const {
+ return _data->_string.empty();
+ }
+
+ char firstChar() const {
+ return _data->_string.firstChar();
+ }
+
+ char lastChar() const {
+ return _data->_string.lastChar();
+ }
+
+ int size() const {
+ return _data->_string.size();
+ }
+
+ void deleteLastChar() {
+ _data->_string.deleteLastChar();
+ }
+
+ bool hasSuffix(const CString &str) const {
+ return _data->_string.hasSuffix(str);
+ }
+ bool hasSuffix(const char *str) const {
+ return _data->_string.hasSuffix(str);
+ }
/**
* Create a new copy of the string
*/
- TTstring *copy() const;
+ TTstring *copy() const {
+ return new TTstring(c_str());
+ }
/**
* Returns true if the string is valid
*/
- bool isValid() const;
+ bool isValid() const {
+ return _status == SS_VALID;
+ }
/**
* Get the status of the string
@@ -97,6 +127,13 @@ public:
* Save the sring to a passed file
*/
void save(SimpleFile *file) const;
+
+ /**
+ * Compare a substring within the string at the specified index
+ */
+ bool compareAt(int index, const char *str) const {
+ return !strncmp(c_str() + index, str, strlen(str));
+ }
};
} // End of namespace Titanic