diff --git a/Common/font/fonts.cpp b/Common/font/fonts.cpp index 116469412d5..837c5d162e2 100644 --- a/Common/font/fonts.cpp +++ b/Common/font/fonts.cpp @@ -370,40 +370,6 @@ int get_text_lines_surf_height(size_t fontNumber, size_t numlines) namespace AGS { namespace Common { SplitLines Lines; } } -// Replaces AGS-specific linebreak tags with common '\n' -static void unescape_script_string(const char *cstr, std::string &out) -{ - out.clear(); - // Handle the special case of the first char - if (cstr[0] == '[') - { - out.push_back('\n'); - cstr++; - } - // Replace all other occurrences as they're found - // NOTE: we do not need to decode utf8 here, because - // we are only searching for low-code ascii chars. - const char *off; - for (off = cstr; *off; ++off) - { - if (*off != '[') continue; - if (*(off - 1) == '\\') - { - // convert \[ into [ - out.insert(out.end(), cstr, off - 1); - out.push_back('['); - } - else - { - // convert [ into \n - out.insert(out.end(), cstr, off); - out.push_back('\n'); - } - cstr = off + 1; - } - out.insert(out.end(), cstr, off + 1); -} - // Break up the text into lines size_t split_lines(const char *todis, SplitLines &lines, int wii, int fonnt, size_t max_lines) { // NOTE: following hack accomodates for the legacy math mistake in split_lines. @@ -417,24 +383,19 @@ size_t split_lines(const char *todis, SplitLines &lines, int wii, int fonnt, siz lines.Reset(); - std::string &line_buf = lines.LineBuf[0]; - std::string &test_buf = lines.LineBuf[1]; - - // Do all necessary preliminary conversions: unescape, etc - unescape_script_string(todis, line_buf); + std::string &test_buf = lines.LineBuf[0]; // TODO: we NEED a proper utf8 string class, and refact all this mess!! // in this case we perhaps could use custom ITERATOR types that read // and write utf8 chars in std::strings or similar containers. test_buf.clear(); - const char *end_ptr = &line_buf.back(); // buffer end ptr - const char *theline = &line_buf.front(); // sub-line ptr + const char *theline = todis; // sub-line ptr const char *scan_ptr = theline; // a moving scan pos const char *prev_ptr = scan_ptr; // previous scan pos const char *last_whitespace = nullptr; // last found whitespace while (true) { - if (scan_ptr == end_ptr) { + if (*scan_ptr == 0) { // end of the text, add the last line if necessary if (scan_ptr > theline) { lines.Add(test_buf.c_str()); diff --git a/Compiler/script/cc_compiledscript.cpp b/Compiler/script/cc_compiledscript.cpp index f59f2c92851..99aa5e413a0 100644 --- a/Compiler/script/cc_compiledscript.cpp +++ b/Compiler/script/cc_compiledscript.cpp @@ -68,10 +68,6 @@ int ccCompiledScript::add_string(const char*strr) { ch = strr[src]; if (ch == 'n') {ch = '\n';} else if (ch == 'r') {ch = '\r';} - else if (ch == '[') { // pass through as \[ - *write_ptr = '\\'; - write_ptr++; - } } *write_ptr = ch; write_ptr++; diff --git a/Compiler/script2/cs_scanner.cpp b/Compiler/script2/cs_scanner.cpp index 9b35204297f..8c3cb2bf02f 100644 --- a/Compiler/script2/cs_scanner.cpp +++ b/Compiler/script2/cs_scanner.cpp @@ -432,10 +432,6 @@ void AGS::Scanner::ReadInCharLit(std::string &symstring, CodeCell &value) if (Failed()) break; // to error processing - if ('[' == lit_char) - // "\\[" is equivalent to two characters, so can't be used as a single character - UserError("'\\[' is not allowed in single quotes, use '[' instead"); - EscapedChar2Char(lit_char, symstring, lit_char); } @@ -557,16 +553,11 @@ void AGS::Scanner::ReadInStringLit(std::string &symstring, std::string &valstrin symstring.push_back(ch); if (EOFReached() || Failed() || '\n' == ch || '\r' == ch) break; // to error msg - if ('[' == ch) - { - valstring.append("\\["); - } - else - { - int converted; - EscapedChar2Char(ch, symstring, converted); - valstring.push_back(converted); - } + + int converted; + EscapedChar2Char(ch, symstring, converted); + valstring.push_back(converted); + continue; } @@ -621,7 +612,7 @@ void AGS::Scanner::ReadInStringLit(std::string &symstring, std::string &valstrin else if (Failed()) UserError("Read error while scanning a string literal (file corrupt?)"); else - UserError("Line ended within a string literal, this isn't allowed (use '[' for newline)"); + UserError("Line ended within a string literal, this isn't allowed."); } void AGS::Scanner::ReadInIdentifier(std::string &symstring) diff --git a/Compiler/test2/cc_scanner_test.cpp b/Compiler/test2/cc_scanner_test.cpp index a1f81f70bb2..3933c55ab38 100644 --- a/Compiler/test2/cc_scanner_test.cpp +++ b/Compiler/test2/cc_scanner_test.cpp @@ -750,13 +750,13 @@ TEST_F(Scan, String1) { // Should scan advanced escape sequences within string. - std::string Input = "\"Oh, \\the \\brow\\n \\fo\\x5e jumps \\[ove\\r] the \\100\\azy dog.\""; + std::string Input = "\"Oh, \\the \\brow\\n \\fo\\x5e jumps [ove\\r] the \\100\\azy dog.\""; AGS::Scanner scanner(Input, token_list, string_collector, sym, mh); ASSERT_LE(0, scanner.GetNextSymstringT(symstring, sct, value)); ASSERT_LE(0, value); - EXPECT_STREQ("Oh, \the \brow\n \fo^ jumps \\[ove\r] the @\azy dog.", &(string_collector.strings[value])); - EXPECT_STREQ("\"Oh, \\the \\brow\\n \\fo\\x5e jumps \\[ove\\r] the \\100\\azy dog.\"", symstring.c_str()); + EXPECT_STREQ("Oh, \the \brow\n \fo^ jumps [ove\r] the @\azy dog.", &(string_collector.strings[value])); + EXPECT_STREQ("\"Oh, \\the \\brow\\n \\fo\\x5e jumps [ove\\r] the \\100\\azy dog.\"", symstring.c_str()); } TEST_F(Scan, UnknownKeywordAfterReadonly) {