Cleanup in content_mapblock (#5746)
[oweals/minetest.git] / src / chat.cpp
index 958389df517eebb20625f8fc611bfe5a107be6ad..fc93e3027aae8c68892cec653c61a6f8701ad072 100644 (file)
@@ -77,11 +77,6 @@ u32 ChatBuffer::getLineCount() const
        return m_unformatted.size();
 }
 
-u32 ChatBuffer::getScrollback() const
-{
-       return m_scrollback;
-}
-
 const ChatLine& ChatBuffer::getLine(u32 index) const
 {
        assert(index < getLineCount()); // pre-condition
@@ -267,28 +262,26 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
                next_frags.push_back(temp_frag);
        }
 
-       std::wstring name_sanitized = removeEscapes(line.name);
+       std::wstring name_sanitized = line.name.c_str();
 
        // Choose an indentation level
        if (line.name.empty()) {
                // Server messages
                hanging_indentation = 0;
-       }
-       else if (name_sanitized.size() + 3 <= cols/2) {
+       } else if (name_sanitized.size() + 3 <= cols/2) {
                // Names shorter than about half the console width
                hanging_indentation = line.name.size() + 3;
-       }
-       else {
+       } else {
                // Very long names
                hanging_indentation = 2;
        }
-       ColoredString line_text(line.text);
+       //EnrichedString line_text(line.text);
 
        next_line.first = true;
        bool text_processing = false;
 
        // Produce fragments and layout them into lines
-       while (!next_frags.empty() || in_pos < line_text.size())
+       while (!next_frags.empty() || in_pos < line.text.size())
        {
                // Layout fragments into lines
                while (!next_frags.empty())
@@ -326,9 +319,9 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
                }
 
                // Produce fragment
-               if (in_pos < line_text.size())
+               if (in_pos < line.text.size())
                {
-                       u32 remaining_in_input = line_text.size() - in_pos;
+                       u32 remaining_in_input = line.text.size() - in_pos;
                        u32 remaining_in_output = cols - out_column;
 
                        // Determine a fragment length <= the minimum of
@@ -338,14 +331,14 @@ u32 ChatBuffer::formatChatLine(const ChatLine& line, u32 cols,
                        while (frag_length < remaining_in_input &&
                                        frag_length < remaining_in_output)
                        {
-                               if (isspace(line_text[in_pos + frag_length]))
+                               if (iswspace(line.text.getString()[in_pos + frag_length]))
                                        space_pos = frag_length;
                                ++frag_length;
                        }
                        if (space_pos != 0 && frag_length < remaining_in_input)
                                frag_length = space_pos + 1;
 
-                       temp_frag.text = line_text.substr(in_pos, frag_length);
+                       temp_frag.text = line.text.substr(in_pos, frag_length);
                        temp_frag.column = 0;
                        //temp_frag.bold = 0;
                        next_frags.push_back(temp_frag);
@@ -388,7 +381,7 @@ s32 ChatBuffer::getBottomScrollPos() const
 
 
 
-ChatPrompt::ChatPrompt(std::wstring prompt, u32 history_limit):
+ChatPrompt::ChatPrompt(const std::wstring &prompt, u32 history_limit):
        m_prompt(prompt),
        m_line(L""),
        m_history(),
@@ -729,19 +722,22 @@ ChatBuffer& ChatBackend::getRecentBuffer()
        return m_recent_buffer;
 }
 
-std::wstring ChatBackend::getRecentChat()
+EnrichedString ChatBackend::getRecentChat()
 {
-       std::wostringstream stream;
+       EnrichedString result;
        for (u32 i = 0; i < m_recent_buffer.getLineCount(); ++i)
        {
                const ChatLine& line = m_recent_buffer.getLine(i);
                if (i != 0)
-                       stream << L"\n";
-               if (!line.name.empty())
-                       stream << L"<" << line.name << L"> ";
-               stream << line.text;
+                       result += L"\n";
+               if (!line.name.empty()) {
+                       result += L"<";
+                       result += line.name;
+                       result += L"> ";
+               }
+               result += line.text;
        }
-       return stream.str();
+       return result;
 }
 
 ChatPrompt& ChatBackend::getPrompt()