Wed, 27 Jan 2021 14:05:39 +0200
renamed String and StringList uses
--- a/sources/coloredline.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/coloredline.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -127,7 +127,7 @@ { if (ch == ']') { - String color = to_lowercase(m_incomingColorName); + std::string color = to_lowercase(m_incomingColorName); for (const ColorCodeInfo &colorInfo : colorCodes) { @@ -176,7 +176,7 @@ // ------------------------------------------------------------------------------------------------- // -void ColoredLine::addString(const String& text) +void ColoredLine::addString(const std::string& text) { for (char a : text) addChar(a);
--- a/sources/coloredline.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/coloredline.h Wed Jan 27 14:05:39 2021 +0200 @@ -69,7 +69,7 @@ const Vector<int>& data() const { return m_data; } int length() const { return m_length; } void addChar(char ch); - void addString(const String& msg); + void addString(const std::string& msg); void finalize(); int rows(int cols) const; @@ -83,8 +83,8 @@ Color m_activeColor; bool m_boldActive; int m_colorCodeStage; - String m_string; - String m_incomingColorName; + std::string m_string; + std::string m_incomingColorName; }; END_ZFC_NAMESPACE
--- a/sources/interface.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/interface.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -51,7 +51,7 @@ // ------------------------------------------------------------------------------------------------- // -const String& Interface::getCurrentInput() +const std::string& Interface::getCurrentInput() { return m_inputHistory[m_inputCursor]; } @@ -72,7 +72,7 @@ // ------------------------------------------------------------------------------------------------- // A version of current_input() that allows changing the contents of it. // -String& Interface::getEditableInput() +std::string& Interface::getEditableInput() { detachInput(); return m_inputHistory[m_inputCursor]; @@ -101,9 +101,9 @@ // ------------------------------------------------------------------------------------------------- // -String Interface::getPromptString() +std::string Interface::getPromptString() { - String prompt; + std::string prompt; switch (m_inputState) { @@ -220,7 +220,7 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::setTitle(const String& title) +void Interface::setTitle(const std::string& title) { m_title = title; renderTitlebar(); @@ -417,9 +417,9 @@ return; } - String prompt = getPromptString(); + std::string prompt = getPromptString(); int displayLength = COLS - prompt.length() - 2; - String displayString = getCurrentInput(); + std::string displayString = getCurrentInput(); int y = LINES - 2; // If we're inputting a password, replace it with asterisks @@ -478,7 +478,7 @@ // void Interface::updateStatusBar() { - String text; + std::string text; switch (m_session.getState()) { @@ -493,7 +493,7 @@ case RCON_CONNECTED: { - String adminText; + std::string adminText; if (m_session.getAdminCount() == 0) { @@ -558,7 +558,7 @@ // int Interface::findPreviousWord() { - const String& input = getCurrentInput(); + const std::string& input = getCurrentInput(); int pos = m_cursorPosition; // Move past whitespace @@ -576,7 +576,7 @@ // int Interface::findNextWord() { - const String& input = getCurrentInput(); + const std::string& input = getCurrentInput(); int pos = m_cursorPosition; // Move past current whitespace @@ -600,7 +600,7 @@ if (m_cursorPosition > a and m_cursorPosition <= b) m_cursorPosition = a; - String& input = getEditableInput(); + std::string& input = getEditableInput(); m_pasteBuffer = mid(input, a, b); input = remove_range(input, a, b - a); m_needInputRender = true; @@ -719,7 +719,7 @@ case '\b': if (m_cursorPosition > 0) { - String& input = getEditableInput(); + std::string& input = getEditableInput(); input.erase(input.begin() + m_cursorPosition); m_cursorPosition -= 1; m_needInputRender = true; @@ -730,7 +730,7 @@ case 'D' - 'A' + 1: // readline ^D if (m_cursorPosition < static_cast<signed>(getCurrentInput().length())) { - String& input = getEditableInput(); + std::string& input = getEditableInput(); input.erase(input.begin() + m_cursorPosition); m_needInputRender = true; } @@ -779,7 +779,7 @@ and m_cursorPosition > 0 and(space == -1 or space >= m_cursorPosition)) { - String start = mid(getCurrentInput(), 0, m_cursorPosition); + std::string start = mid(getCurrentInput(), 0, m_cursorPosition); m_session.requestTabCompletion(start); } } @@ -908,7 +908,7 @@ // void Interface::vprint(const char* fmtstr, va_list args) { - String message; + std::string message; message = vsprintf(fmtstr, args); printToConsole(message); } @@ -958,7 +958,7 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::printToConsole(String message) +void Interface::printToConsole(std::string message) { // 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. @@ -980,7 +980,7 @@ char timestamp[32]; strftime(timestamp, sizeof timestamp, "[%H:%M:%S] ", localtime(&now)); - for (char ch : String(timestamp)) + for (char ch : std::string(timestamp)) zfc::last(m_outputLines).addChar(ch); } @@ -996,7 +996,7 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::connect(String address, String password) +void Interface::connect(std::string address, std::string password) { try { @@ -1018,11 +1018,11 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::setPlayerNames(const StringList& names) +void Interface::setPlayerNames(const std::vector<std::string>& names) { m_playerNames.clear(); - for (const String& name : names) + for (const std::string& name : names) { ColoredLine coloredname; coloredname.addString(name); @@ -1035,9 +1035,9 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::tabComplete(const String& part, String complete) +void Interface::tabComplete(const std::string& part, std::string complete) { - String& input = getEditableInput(); + std::string& input = getEditableInput(); if (starts_with(input, part)) { @@ -1052,13 +1052,13 @@ // ------------------------------------------------------------------------------------------------- // -void Interface::handleCommand(const String& input) +void Interface::handleCommand(const std::string& input) { if (input[0] != '/') return; - StringList args = split(right(input, input.length() - 1), " "); - String command = to_lowercase(args[0]); + std::vector<std::string> args = split(right(input, input.length() - 1), " "); + std::string command = to_lowercase(args[0]); args.erase(args.begin()); if (command == "connect")
--- a/sources/interface.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/interface.h Wed Jan 27 14:05:39 2021 +0200 @@ -49,10 +49,10 @@ }; Interface(); - void connect(String address, String password); + void connect(std::string address, std::string password); void disconnected(); RCONSession* getSession() { return &m_session; } - void handleCommand(const String& input); + void handleCommand(const std::string& input); void handleInput(); void needRefresh(); void __cdecl print(const char* fmtstr, ...); @@ -61,14 +61,14 @@ void __cdecl printText(const char* fmtstr, ...); void render(); void renderFull(); - void setPlayerNames(const StringList& names); - void setTitle(const String& message); - void tabComplete(const String& part, String complete); + void setPlayerNames(const std::vector<std::string>& names); + void setTitle(const std::string& message); + void tabComplete(const std::string& part, std::string complete); void updateStatusBar(); void vprint(const char* fmtstr, va_list args); private: - StringList m_inputHistory; + std::vector<std::string> m_inputHistory; int m_inputCursor; int m_cursorPosition; int m_inputPanning; @@ -80,13 +80,13 @@ struct { char ch; int x; } m_cursorCharacter; Vector<ColoredLine> m_outputLines; int m_outputScroll; - String m_title; + std::string m_title; InputState m_inputState; std::function<void(bool)> m_disconnectCallback; IPAddress m_remoteAddress; - String m_statusBarText; + std::string m_statusBarText; std::vector<ColoredLine> m_playerNames; - String m_pasteBuffer; + std::string m_pasteBuffer; RCONSession m_session; void detachInput(); @@ -94,13 +94,13 @@ int findPreviousWord(); void flushInput(); chtype getColorPair(Color fg, Color bg); - const String& getCurrentInput(); - String& getEditableInput(); - String getPromptString(); + const std::string& getCurrentInput(); + std::string& getEditableInput(); + std::string getPromptString(); void moveInputCursor(int delta); int nicklistWidth(); void positionCursor(); - void printToConsole(String message); + void printToConsole(std::string message); int renderColorline(int y, int x0, int width, const ColoredLine& line, bool allowWrap); void renderInput(); void renderNicklist();
--- a/sources/mystring.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/mystring.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -39,7 +39,7 @@ */ std::string to_lowercase(const std::string& string) { - String result = string; + std::string result = string; for (char& ch : result) { @@ -55,7 +55,7 @@ * \param delimeter The delimeter to place between the element strings. * \returns the catenated string. */ -std::string join_string_list(const StringList& strings, const std::string& delimeter) +std::string join_string_list(const std::vector<std::string>& strings, const std::string& delimeter) { std::string result; @@ -173,7 +173,7 @@ * \param other Sub-string to find from the beginning of this string. * \returns whether or not this string begins with the provided sub-string. */ -bool starts_with(const std::string& str, const String& other) +bool starts_with(const std::string& str, const std::string& other) { if (str.length() < other.length()) return false; @@ -200,16 +200,16 @@ * \param delimeter Delimeter to use for splitting. * \returns a string list containing the split strings. */ -StringList split(const std::string& string, const String& delimeter) +std::vector<std::string> split(const std::string& string, const std::string& delimeter) { - StringList result; + std::vector<std::string> result; int a = 0; int b; // Find all separators and store the text left to them. while ((b = string.find(delimeter, a)) != -1) { - String sub = mid(string, a, b); + std::string sub = mid(string, a, b); if (sub.length() > 0) result.push_back(sub);
--- a/sources/mystring.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/mystring.h Wed Jan 27 14:05:39 2021 +0200 @@ -42,15 +42,15 @@ using namespace std::string_literals; std::string to_lowercase(const std::string& string); -std::string join_string_list(const StringList& strings, const String& delim); +std::string join_string_list(const std::vector<std::string>& strings, const std::string& delim); std::string mid(const std::string& str, int rangeBegin, int rangeEnd); std::string right(const std::string& str, int length); std::string vsprintf(const char* formatString, va_list args); std::string __cdecl sprintf(const char* formatString, ...); std::string remove_range(const std::string& string, int start, int end); void replace_all(std::string& str, const char* text, const char* replacement); -bool starts_with(const std::string& str, const String& other); -StringList split(const std::string& string, const String& delimeter); +bool starts_with(const std::string& str, const std::string& other); +std::vector<std::string> split(const std::string& string, const std::string& delimeter); std::optional<long> to_int(const char* str, int base = 10); void normalize(std::string& string, int (*filter)(int) = std::isspace);
--- a/sources/network/bytestream.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/bytestream.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -49,7 +49,7 @@ if (bytesLeft() < bytes) { int bytesPast = bytes - bytesLeft(); - String message; + std::string message; message = sprintf("attempted to read %d byte%s past the end of bytestream", bytesPast, plural(bytesPast)); throw IOError (message); } @@ -127,9 +127,9 @@ * \brief Reads in characters until a null terminator is encountered. * \returns the read string. */ -String Bytestream::readString() +std::string Bytestream::readString() { - String result; + std::string result; for (char byte; (byte = readByte()) != '\0';) { @@ -201,7 +201,7 @@ * \brief Writes the given string to the end of the data. * \param text String to write. */ -void Bytestream::writeString(const String& string) +void Bytestream::writeString(const std::string& string) { const int oldSize = m_data.size(); m_data.reserve(m_data.size() + string.length() + 1);
--- a/sources/network/bytestream.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/bytestream.h Wed Jan 27 14:05:39 2021 +0200 @@ -65,7 +65,7 @@ int8_t readByte(); int32_t readLong(); int16_t readShort(); - String readString(); + std::string readString(); float readFloat(); void rewind(); void seek(int position); @@ -76,7 +76,7 @@ void writeFloat(float value); void writeLong(int32_t value); void writeShort(int16_t value); - void writeString(const String& string); + void writeString(const std::string& string); private: ByteArray& m_data;
--- a/sources/network/ipaddress.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/ipaddress.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -66,9 +66,9 @@ // ----------------------------------------------------------------------------- // -String IPAddress::to_string (WithPort withport) const +std::string IPAddress::to_string (WithPort withport) const { - String val; + std::string val; if (withport == WITH_PORT) val = sprintf ("%u.%u.%u.%u:%u", octet (0), octet (1), octet (2), octet (3), port); @@ -141,11 +141,11 @@ // ----------------------------------------------------------------------------- // -IPAddress IPAddress::from_string (String input) +IPAddress IPAddress::from_string (std::string input) { unsigned int parts[4]; int colonpos = input.find (":"); - String addressString = colonpos == -1 ? input : mid(input, 0, colonpos); + std::string addressString = colonpos == -1 ? input : mid(input, 0, colonpos); IPAddress value; // Try scanf the IPv4 host first @@ -174,7 +174,7 @@ // ----------------------------------------------------------------------------- // -IPAddress IPAddress::resolve (String node) +IPAddress IPAddress::resolve (std::string node) { AddrInfo hints; AddrInfo* lookup;
--- a/sources/network/ipaddress.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/ipaddress.h Wed Jan 27 14:05:39 2021 +0200 @@ -51,10 +51,10 @@ class StringParseError : public std::exception { - String m_message; + std::string m_message; public: - StringParseError (String message) : + StringParseError (std::string message) : m_message (message) {} const char* what() const throw() @@ -73,15 +73,15 @@ bool compare (const IPAddress& other) const; unsigned char octet (int n) const; void set_octet (int n, unsigned char oct); - String to_string (WithPort withport = NO_PORT) const; + std::string to_string (WithPort withport = NO_PORT) const; sockaddr_in to_sockaddr_in() const; bool operator< (const IPAddress& other) const; bool operator== (const IPAddress& other) const { return compare (other); } bool operator!= (const IPAddress& other) const { return not compare (other); } unsigned char operator[] (int n) const { return octet (n); } - static IPAddress from_string (String input); - static IPAddress resolve (String node); + static IPAddress from_string (std::string input); + static IPAddress resolve (std::string node); }; END_ZFC_NAMESPACE
--- a/sources/network/rconsession.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/rconsession.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -157,7 +157,7 @@ case SVRC_MESSAGE: { - String message = stream.readString(); + std::string message = stream.readString(); normalize(message); m_interface->printText("%s\n", message.data()); } @@ -177,7 +177,7 @@ for (int i = stream.readByte(); i > 0; --i) { - String message = stream.readString(); + std::string message = stream.readString(); normalize(message); m_interface->printText("--- %s\n", message.data()); } @@ -199,10 +199,10 @@ case SVRC_TABCOMPLETE: { - StringList completes; + std::vector<std::string> completes; completes.resize(stream.readByte()); - for (String& completion : completes) + for (std::string& completion : completes) completion = stream.readString(); if (completes.size() == 1) @@ -216,7 +216,7 @@ for (int i : range(0, static_cast<int>(completes.size()), 8)) { const int end = min(i + 8, static_cast<int>(completes.size())); - StringList splices = splice(completes, i, end); + std::vector<std::string> splices = splice(completes, i, end); m_interface->print("- %s\n", join_string_list(splices, ", ").data()); } } @@ -241,7 +241,7 @@ { case SVRCU_PLAYERDATA: { - StringList players; + std::vector<std::string> players; for (int i = packet.readByte(); i > 0; --i) players.push_back(packet.readString()); @@ -297,7 +297,7 @@ // ------------------------------------------------------------------------------------------------- // -void RCONSession::setPassword(const String& password) +void RCONSession::setPassword(const std::string& password) { m_password = password; } @@ -321,7 +321,7 @@ // ------------------------------------------------------------------------------------------------- // Returns true if the message was successfully sent. // -bool RCONSession::sendCommand(const String& commandString) +bool RCONSession::sendCommand(const std::string& commandString) { if (m_state != RCON_CONNECTED or commandString.empty()) return false; @@ -358,14 +358,14 @@ // ------------------------------------------------------------------------------------------------- // -const String& RCONSession::getLevel() const +const std::string& RCONSession::getLevel() const { return m_level; } // ------------------------------------------------------------------------------------------------- // -void RCONSession::requestTabCompletion(const String& part) +void RCONSession::requestTabCompletion(const std::string& part) { if (m_serverProtocol >= 4) {
--- a/sources/network/rconsession.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/rconsession.h Wed Jan 27 14:05:39 2021 +0200 @@ -100,19 +100,19 @@ void connect(IPAddress address); void disconnect(); int getAdminCount() const; - const String& getLevel() const; + const std::string& getLevel() const; UDPSocket* getSocket(); RCONSessionState getState() const; void handlePacket(ByteArray& message); bool isActive() const; void processServerUpdates(Bytestream& packet); - void requestTabCompletion(const String& part); + void requestTabCompletion(const std::string& part); void send(const ByteArray& packet); - bool sendCommand(const String& commandString); + bool sendCommand(const std::string& commandString); void sendHello(); void sendPassword(); void setInterface(class Interface* interface); - void setPassword(const String& password); + void setPassword(const std::string& password); void tick(); private: @@ -120,13 +120,13 @@ IPAddress m_address; UDPSocket m_socket; time_t m_lastPing; - String m_password; - String m_salt; + std::string m_password; + std::string m_salt; int m_serverProtocol; - String m_hostname; + std::string m_hostname; int m_adminCount; - String m_level; - String m_lastTabComplete; + std::string m_level; + std::string m_lastTabComplete; class Interface* m_interface; };
--- a/sources/network/udpsocket.cpp Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/udpsocket.cpp Wed Jan 27 14:05:39 2021 +0200 @@ -124,7 +124,7 @@ if (length == -1) { if (errno != EWOULDBLOCK) - m_error = String ("recvfrom error: ") + strerror (errno); + m_error = std::string ("recvfrom error: ") + strerror (errno); return false; } @@ -151,7 +151,7 @@ if (res == -1) { - m_error = String ("Unable to launch packet: ") + strerror (errno); + m_error = std::string ("Unable to launch packet: ") + strerror (errno); return false; }
--- a/sources/network/udpsocket.h Wed Jan 27 14:04:53 2021 +0200 +++ b/sources/network/udpsocket.h Wed Jan 27 14:05:39 2021 +0200 @@ -54,14 +54,14 @@ bool read (Datagram& datagram); bool send (const IPAddress& address, const ByteArray& data); bool set_blocking (bool a); - const String& error_string() const { return m_error; } + const std::string& error_string() const { return m_error; } int file_descriptor() const { return m_socket; } private: static char HuffmanBuffer[131072]; IPAddress m_addr; - String m_error; + std::string m_error; int m_socket; };