can you change the code to maybe using the standard regex library instead?…
- User
can you change the code to maybe using the standard regex library instead?
std::vector keywords = { "alignas", "alignof", "and", "and_eq", "asm", "atomic_cancel", "atomic_commit", "atomic_noexcept", "auto", "bitand", "bitor", "bool", "break", "case", "catch", "char", "char8_t", "char16_t", "char32_t", "class", "compl", "concept", "const", "consteval", "constexpr", "constinit", "const_cast", "continue", "co_await", "co_return", "co_yield", "decltype", "default", "delete", "do", "double", "dynamic_cast", "else", "enum", "explicit", "export", "extern", "false", "float", "for", "friend", "goto", "if", "inline", "int", "long", "mutable", "namespace", "new", "noexcept", "not", "not_eq", "nullptr", "operator", "or", "or_eq", "private", "protected", "public", "reflexpr", "register", "reinterpret_cast", "requires", "return", "short", "signed", "sizeof", "static", "static_assert", "static_cast", "struct", "switch", "synchronized", "template", "this", "thread_local", "throw", "true", "try", "typedef", "typeid", "typename", "union", "unsigned", "using", "virtual", "void", "volatile", "wchar_t", "while", "xor", "xor_eq", "final", "override", "transaction_safe", "transaction_safe_dynamic", "import", "module", "_Pragma", "if", "elif", "else", "endif", "ifdef", "ifndef", "elifdef", "elifndef", "define", "undef", "include", "line", "error", "warning", "pragma", "defined", "__has_include", "__has_cpp_attribute", "export", "import", "module" }; wxString codeCopy = code;
for (const auto& keyword : keywords) { wxString::size_type pos = 0; while ((pos = codeCopy.find(keyword, pos)) != wxString::npos) { richTextChatBox->WriteText(codeCopy.substr(0, pos)); richTextChatBox->BeginStyle(keywordStyle); richTextChatBox->WriteText(keyword); richTextChatBox->EndStyle(); codeCopy = codeCopy.substr(pos + keyword.Length()); } } - Assistant
- User
OK, I got some code working for the syntax highlighting, but the problem is, it doesn’t detect spaces correctly, so for example if I want to highlight “or” these words get highlighted too: “mor” or “orrly” and it should only highlight “or” when it is like this " or " and maybe " or(", to support keywords like “if” which sometimes it is written like “if(” or “if (”.
- Assistant