summaryrefslogtreecommitdiff
path: root/src/string.cpp
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-01-18 13:12:57 +0000
committerrubidium <rubidium@openttd.org>2009-01-18 13:12:57 +0000
commit1bc8e3f536276bf37a246f1e747cb7563c7e20dc (patch)
tree6d76af52262054593ff7eea5e0e4a6d516cc0935 /src/string.cpp
parent2ce42873d1c8f259f1bed70ace5d52ce66e5d852 (diff)
downloadopenttd-1bc8e3f536276bf37a246f1e747cb7563c7e20dc.tar.xz
(svn r15135) -Fix/Change: allow str_validate (part of receiving strings from the network) to pass newlines instead of replacing them with question marks, but only when asked to do so.
Diffstat (limited to 'src/string.cpp')
-rw-r--r--src/string.cpp9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/string.cpp b/src/string.cpp
index 016a4990f..f3ab41623 100644
--- a/src/string.cpp
+++ b/src/string.cpp
@@ -98,7 +98,7 @@ char *CDECL str_fmt(const char *str, ...)
}
-void str_validate(char *str)
+void str_validate(char *str, bool allow_newlines)
{
char *dst = str;
WChar c;
@@ -113,7 +113,14 @@ void str_validate(char *str)
do {
*dst++ = *str++;
} while (--len != 0);
+ } else if (allow_newlines && c == '\n') {
+ *dst++ = *str++;
} else {
+ if (allow_newlines && c == '\r' && str[1] == '\n') {
+ str += len;
+ continue;
+ }
+ assert(c != '\r');
/* Replace the undesirable character with a question mark */
str += len;
*dst++ = '?';