gpt-3.5-turbo-0125· OpenAI
WildChat-4.8M (AI2)
Reformat this C++ code to avoid code duplication: if (markerPos != wxString::npos) {…
- User
Reformat this C++ code to avoid code duplication:
if (markerPos != wxString::npos) { wxString endMarker = markers[startMarker]; wxString::size_type endMarkerPos = formattedMessage.find(endMarker, markerPos + startMarker.Length());
codeif (endMarkerPos != wxString::npos) { wxString beforeMarker = formattedMessage.Mid(pos, markerPos - pos); wxString styledText = formattedMessage.Mid(markerPos, endMarkerPos + endMarker.Length() - markerPos); richTextChatBox->WriteText(beforeMarker); wxRichTextAttr textAttr = wxRichTextAttr(style); textAttr.SetFont(richTextChatBox->GetFont()); textAttr = Markdown::FormatMarkdownStyle(styledText, textAttr); richTextChatBox->BeginStyle(textAttr); wxString cleanText = styledText.Mid(startMarker.Length(), styledText.Length() - startMarker.Length() - endMarker.Length()); richTextChatBox->WriteText(cleanText); richTextChatBox->EndStyle(); pos = endMarkerPos + endMarker.Length(); } else { richTextChatBox->BeginStyle(style); richTextChatBox->WriteText(formattedMessage.Mid(pos)); pos = wxString::npos; richTextChatBox->EndStyle(); } } else { richTextChatBox->BeginStyle(style); richTextChatBox->WriteText(formattedMessage.Mid(pos)); pos = wxString::npos; richTextChatBox->EndStyle(); } - Assistant
bool foundMarker = false;
if (markerPos != wxString::npos) { wxString endMarker = markers[startMarker]; wxString::size_type endMarkerPos = formattedMessage.find(endMarker, markerPos + startMarker.Length());
codeif (endMarkerPos != wxString::npos) { foundMarker = true; wxString beforeMarker = formattedMessage.Mid(pos, markerPos - pos); wxString styledText = formattedMessage.Mid(markerPos, endMarkerPos + endMarker.Length() - markerPos); richTextChatBox->WriteText(beforeMarker); wxRichTextAttr textAttr = wxRichTextAttr(style); textAttr.SetFont(richTextChatBox->GetFont()); textAttr = Markdown::FormatMarkdownStyle(styledText, textAttr); richTextChatBox->BeginStyle(textAttr); wxString cleanText = styledText.Mid(startMarker.Length(), styledText.Length() - startMarker.Length() - endMarker.Length()); richTextChatBox->WriteText(cleanText); richTextChatBox->EndStyle(); pos = endMarkerPos + endMarker.Length(); }