diff --git a/src/lib/base/String.cpp b/src/lib/base/String.cpp index b873663e..99a2bb43 100644 --- a/src/lib/base/String.cpp +++ b/src/lib/base/String.cpp @@ -208,13 +208,22 @@ removeChar(String& subject, const char c) } String -intToString(size_t integer) +sizeTypeToString(size_t n) { std::stringstream ss; - ss << integer; + ss << n; return ss.str(); } +size_t +stringToSizeType(String string) +{ + std::istringstream iss(string); + size_t value; + iss >> value; + return value; +} + // // CaselessCmp // diff --git a/src/lib/base/String.h b/src/lib/base/String.h index 81d98a9b..de34ad0a 100644 --- a/src/lib/base/String.h +++ b/src/lib/base/String.h @@ -88,11 +88,17 @@ Remove all specific \c c in \c suject */ void removeChar(String& subject, const char c); -//! Convert an integer to a string +//! Convert a size type to a string /*! -Convert an \c integer to a string +Convert an size type to a string */ -String intToString(size_t integer); +String sizeTypeToString(size_t n); + +//! Convert a string to a size type +/*! +Convert an a \c string to an size type +*/ +size_t stringToSizeType(String string); //! Case-insensitive comparisons /*! diff --git a/src/lib/synergy/StreamChunker.cpp b/src/lib/synergy/StreamChunker.cpp index e471622c..b7393d94 100644 --- a/src/lib/synergy/StreamChunker.cpp +++ b/src/lib/synergy/StreamChunker.cpp @@ -54,7 +54,7 @@ StreamChunker::sendFile( size_t size = (size_t)file.tellg(); // send first message (file size) - String fileSize = synergy::string::intToString(size); + String fileSize = synergy::string::sizeTypeToString(size); FileChunk* sizeMessage = FileChunk::start(fileSize); events->addEvent(Event(events->forIScreen().fileChunkSending(), eventTarget, sizeMessage)); @@ -109,7 +109,7 @@ StreamChunker::sendClipboard( void* eventTarget) { // send first message (data size) - String dataSize = synergy::string::intToString(size); + String dataSize = synergy::string::sizeTypeToString(size); ClipboardChunk* sizeMessage = ClipboardChunk::start(id, sequence, dataSize); events->addEvent(Event(events->forClientProxy().clipboardSending(), eventTarget, sizeMessage)); diff --git a/src/test/integtests/net/NetworkTests.cpp b/src/test/integtests/net/NetworkTests.cpp index f4f9e4c5..cd9be3c2 100644 --- a/src/test/integtests/net/NetworkTests.cpp +++ b/src/test/integtests/net/NetworkTests.cpp @@ -415,7 +415,7 @@ void NetworkTests::sendMockData(void* eventTarget) { // send first message (file size) - String size = synergy::string::intToString(kMockDataSize); + String size = synergy::string::sizeTypeToString(kMockDataSize); FileChunk* sizeMessage = FileChunk::start(size); m_events.addEvent(Event(m_events.forIScreen().fileChunkSending(), eventTarget, sizeMessage)); diff --git a/src/test/unittests/base/StringTests.cpp b/src/test/unittests/base/StringTests.cpp index 18694302..6381cac5 100644 --- a/src/test/unittests/base/StringTests.cpp +++ b/src/test/unittests/base/StringTests.cpp @@ -82,3 +82,21 @@ TEST(StringTests, removeChar) EXPECT_EQ("fbar", subject); } + +TEST(StringTests, intToString) +{ + size_t value = 123; + + String number = string::sizeTypeToString(value); + + EXPECT_EQ("123", number); +} + +TEST(StringTests, stringToUint) +{ + String number = "123"; + + size_t value = string::stringToSizeType(number); + + EXPECT_EQ(123, value); +}