--- a/sources/interface.cpp Wed Jan 27 13:17:11 2021 +0200 +++ b/sources/interface.cpp Wed Jan 27 14:04:53 2021 +0200 @@ -203,13 +203,13 @@ // void Interface::renderTitlebar() { - if (m_title.length() <= COLS) + if (static_cast<signed>(m_title.length()) <= COLS) { chtype pair = getColorPair(WHITE, BLUE); int startx =(COLS - m_title.length()) / 2; int endx = startx + m_title.length(); attron(pair); - mvprintw(0, startx, "%s", m_title.chars()); + mvprintw(0, startx, "%s", m_title.data()); mvhline(0, 0, ' ', startx); mvhline(0, endx, ' ', COLS - endx); attroff(pair); @@ -430,7 +430,7 @@ } // Ensure the cursor is within bounds - m_cursorPosition = clamp(m_cursorPosition, 0, displayString.length()); + m_cursorPosition = clamp(m_cursorPosition, 0, static_cast<signed>(displayString.length())); // Ensure that the cursor is always in view, adjust panning if this is not the case if (m_cursorPosition > m_inputPanning + displayLength) @@ -445,11 +445,11 @@ // Render the input string mvhline(LINES - 2, 0, ' ', COLS); - mvprintw(y, prompt.length() + 1, "%s", displayString.mid(start, end).chars()); + mvprintw(y, prompt.length() + 1, "%s", mid(displayString, start, end).data()); // Render the prompt attron(promptColor); - mvprintw(y, 0, "%s", prompt.chars()); + mvprintw(y, 0, "%s", prompt.data()); attroff(promptColor); // Store in memory where the cursor is now(so that we can re-draw it to position the terminal @@ -468,7 +468,7 @@ int y = LINES - 1; attron(color); mvhline(y, 0, ' ', COLS); - mvprintw(y, 0, "%s", m_statusBarText.chars()); + mvprintw(y, 0, "%s", m_statusBarText.data()); attroff(color); m_needRefresh = true; m_needStatusBarRender = false; @@ -501,19 +501,19 @@ } else { - adminText.sprintf("%d other admin%s", m_session.getAdminCount(), + adminText = zfc::sprintf("%d other admin%s", m_session.getAdminCount(), m_session.getAdminCount() != 1 ? "s" : ""); } - text.sprintf("%s | %s | %s", - m_session.address().to_string(IPAddress::WITH_PORT).chars(), - m_session.getLevel().chars(), - adminText.chars()); + text = zfc::sprintf("%s | %s | %s", + m_session.address().to_string(IPAddress::WITH_PORT).data(), + m_session.getLevel().data(), + adminText.data()); } break; } - if (not text.isEmpty()) + if (not text.empty()) text += " | "; text += "Ctrl+N to connect, Ctrl+Q to "; @@ -580,7 +580,7 @@ int pos = m_cursorPosition; // Move past current whitespace - while (pos < input.length() and isspace(input[pos])) + while (pos < static_cast<signed>(input.length()) and isspace(input[pos])) pos++; // Move past the word @@ -601,8 +601,8 @@ m_cursorPosition = a; String& input = getEditableInput(); - m_pasteBuffer = input.mid(a, b); - input.remove(a, b - a); + m_pasteBuffer = mid(input, a, b); + input = remove_range(input, a, b - a); m_needInputRender = true; } @@ -637,7 +637,9 @@ if (ch >= 0x20 and ch <= 0x7E) { - getEditableInput().insert(m_cursorPosition++, char(ch)); + std::string& input = getEditableInput(); + input.insert(input.begin() + m_cursorPosition, char(ch)); + m_cursorPosition += 1; m_needInputRender = true; } else switch (ch) @@ -683,7 +685,7 @@ case KEY_RIGHT: case 'F' - 'A' + 1: // readline ^F - if (m_cursorPosition < getCurrentInput().length()) + if (m_cursorPosition < static_cast<int>(getCurrentInput().length())) { m_cursorPosition++; m_needInputRender = true; @@ -706,7 +708,7 @@ case KEY_END: case 'E' - 'A' + 1: // readline ^E - if (m_cursorPosition != getCurrentInput().length()) + if (m_cursorPosition != static_cast<signed>(getCurrentInput().length())) { m_cursorPosition = getCurrentInput().length(); m_needInputRender = true; @@ -717,16 +719,19 @@ case '\b': if (m_cursorPosition > 0) { - getEditableInput().removeAt(--m_cursorPosition); + String& input = getEditableInput(); + input.erase(input.begin() + m_cursorPosition); + m_cursorPosition -= 1; m_needInputRender = true; } break; case KEY_DC: case 'D' - 'A' + 1: // readline ^D - if (m_cursorPosition < getCurrentInput().length()) + if (m_cursorPosition < static_cast<signed>(getCurrentInput().length())) { - getEditableInput().removeAt(m_cursorPosition); + String& input = getEditableInput(); + input.erase(input.begin() + m_cursorPosition); m_needInputRender = true; } break; @@ -758,7 +763,7 @@ break; case 'Y' - 'A' + 1: // readline ^Y - paste previously deleted text - if (not m_pasteBuffer.isEmpty()) + if (not m_pasteBuffer.empty()) { getEditableInput().insert(m_cursorPosition, m_pasteBuffer); m_cursorPosition += m_pasteBuffer.length(); @@ -774,7 +779,7 @@ and m_cursorPosition > 0 and(space == -1 or space >= m_cursorPosition)) { - String start = getCurrentInput().mid(0, m_cursorPosition); + String start = mid(getCurrentInput(), 0, m_cursorPosition); m_session.requestTabCompletion(start); } } @@ -806,7 +811,7 @@ break; case INPUTSTATE_PASSWORD: - if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().isEmpty()) + if (m_inputState == INPUTSTATE_PASSWORD and not getCurrentInput().empty()) { m_session.disconnect(); m_session.setPassword(getCurrentInput()); @@ -904,7 +909,7 @@ void Interface::vprint(const char* fmtstr, va_list args) { String message; - message.vsprintf(fmtstr, args); + message = vsprintf(fmtstr, args); printToConsole(message); } @@ -957,7 +962,7 @@ { // Zandronum sometimes sends color codes as "\\c" and sometimes as "\x1C". // Let's correct that on our end and hope this won't cause conflicts. - message.replace("\\c", "\x1C"); + replace_all(message, "\\c", "\x1C"); for (char ch : message) { @@ -1034,7 +1039,7 @@ { String& input = getEditableInput(); - if (input.startsWith(part)) + if (starts_with(input, part)) { if (input[part.length()] != ' ') complete += ' '; @@ -1052,8 +1057,8 @@ if (input[0] != '/') return; - StringList args = input.right(input.length() - 1).split(" "); - String command = args[0].toLowerCase(); + StringList args = split(right(input, input.length() - 1), " "); + String command = to_lowercase(args[0]); args.erase(args.begin()); if (command == "connect") @@ -1095,14 +1100,14 @@ throw Exitception(); } else - printError("Unknown command: %s\n", command.chars()); + printError("Unknown command: %s\n", command.data()); } // ------------------------------------------------------------------------------------------------- // void Interface::disconnected() { - print("Disconnected from %s\n", m_session.address().to_string(IPAddress::WITH_PORT).chars()); + print("Disconnected from %s\n", m_session.address().to_string(IPAddress::WITH_PORT).data()); resetTitle(); renderFull(); } @@ -1111,7 +1116,7 @@ // void Interface::resetTitle() { - m_title.sprintf("%s %s (%s)", application_name(), full_version_string(), changeset_date_string()); + m_title = sprintf("%s %s (%s)", application_name(), full_version_string(), changeset_date_string()); } // -------------------------------------------------------------------------------------------------