This is an automated email from the git hooks/post-receive script. odyx pushed a commit to branch debian/master in repository colobot.
commit e3c44e956fadb9322613dee777e64cff5aa3694a Author: melex750 <melex...@users.noreply.github.com> Date: Sat Jul 22 14:30:05 2017 -0400 Add syntax highlighting for escape codes --- src/script/script.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 57 insertions(+), 1 deletion(-) diff --git a/src/script/script.cpp b/src/script/script.cpp index 8253cae..f9a70e3 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -589,6 +589,56 @@ void CScript::UpdateList(Ui::CList* list) list->SetState(Ui::STATE_ENABLE); } +// Colorize a string literal with escape sequences also colored + +void HighlightString(Ui::CEdit* edit, const std::string& s, int start) +{ + edit->SetFormat(start, start + 1, Gfx::FONT_HIGHLIGHT_STRING); + + auto it = s.cbegin() + 1; + + ++start; + while (it != s.cend() && *it != '\"') + { + if (*(it++) != '\\') // not escape sequence + { + edit->SetFormat(start, start + 1, Gfx::FONT_HIGHLIGHT_STRING); + ++start; + continue; + } + + if (it == s.cend()) break; + + int end = start + 2; + + if (CBot::CharInList(*it, "01234567")) // octal escape sequence + { + for (int i = 0; ++it != s.cend() && i < 2; i++, end++) + { + if (!CBot::CharInList(*it, "01234567")) break; + } + } + else if (*it == 'x' || *it == 'u' || *it == 'U') // hex or unicode escape + { + bool isHexCode = (*it == 'x'); + int maxlen = (*it == 'u') ? 4 : 8; + + for (int i = 0; ++it != s.cend(); i++, end++) + { + if (!isHexCode && i >= maxlen) break; + if (!CBot::CharInList(*it, "0123456789ABCDEFabcdef")) break; + } + } + else // n, r, t, etc. + ++it; + + edit->SetFormat(start, end, Gfx::FONT_HIGHLIGHT_NONE); + start = end; + } + + if (it != s.cend()) + edit->SetFormat(start, start + 1, Gfx::FONT_HIGHLIGHT_STRING); +} // Colorize the text according to syntax. @@ -643,10 +693,16 @@ void CScript::ColorizeScript(Ui::CEdit* edit, int rangeStart, int rangeEnd) { color = Gfx::FONT_HIGHLIGHT_CONST; } - else if (type == CBot::TokenTypString || type == CBot::TokenTypNum) // string literals and numbers + else if (type == CBot::TokenTypNum) // numbers { color = Gfx::FONT_HIGHLIGHT_STRING; } + else if (type == CBot::TokenTypString) // string literals + { + HighlightString(edit, token, cursor1); + bt = bt->GetNext(); + continue; + } assert(cursor1 < cursor2); edit->SetFormat(cursor1, cursor2, color); -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/colobot.git _______________________________________________ Pkg-games-commits mailing list Pkg-games-commits@lists.alioth.debian.org http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-games-commits