47 void Bytestream::ensureReadSpace(int bytes) |
47 void Bytestream::ensureReadSpace(int bytes) |
48 { |
48 { |
49 if (bytesLeft() < bytes) |
49 if (bytesLeft() < bytes) |
50 { |
50 { |
51 int bytesPast = bytes - bytesLeft(); |
51 int bytesPast = bytes - bytesLeft(); |
52 String message; |
52 std::string message; |
53 message = sprintf("attempted to read %d byte%s past the end of bytestream", bytesPast, plural(bytesPast)); |
53 message = sprintf("attempted to read %d byte%s past the end of bytestream", bytesPast, plural(bytesPast)); |
54 throw IOError (message); |
54 throw IOError (message); |
55 } |
55 } |
56 } |
56 } |
57 |
57 |
125 |
125 |
126 /*! |
126 /*! |
127 * \brief Reads in characters until a null terminator is encountered. |
127 * \brief Reads in characters until a null terminator is encountered. |
128 * \returns the read string. |
128 * \returns the read string. |
129 */ |
129 */ |
130 String Bytestream::readString() |
130 std::string Bytestream::readString() |
131 { |
131 { |
132 String result; |
132 std::string result; |
133 |
133 |
134 for (char byte; (byte = readByte()) != '\0';) |
134 for (char byte; (byte = readByte()) != '\0';) |
135 { |
135 { |
136 if (result.length() < MAX_NETWORK_STRING) |
136 if (result.length() < MAX_NETWORK_STRING) |
137 result += byte; |
137 result += byte; |
199 |
199 |
200 /*! |
200 /*! |
201 * \brief Writes the given string to the end of the data. |
201 * \brief Writes the given string to the end of the data. |
202 * \param text String to write. |
202 * \param text String to write. |
203 */ |
203 */ |
204 void Bytestream::writeString(const String& string) |
204 void Bytestream::writeString(const std::string& string) |
205 { |
205 { |
206 const int oldSize = m_data.size(); |
206 const int oldSize = m_data.size(); |
207 m_data.reserve(m_data.size() + string.length() + 1); |
207 m_data.reserve(m_data.size() + string.length() + 1); |
208 m_data.resize(m_data.size() + string.length()); |
208 m_data.resize(m_data.size() + string.length()); |
209 std::copy(string.begin(), string.end(), m_data.begin() + oldSize); |
209 std::copy(string.begin(), string.end(), m_data.begin() + oldSize); |