From 54b1d9e9a3865462257944f5010abd6d42ea28bd Mon Sep 17 00:00:00 2001 From: Miguel Freitas Date: Fri, 25 Mar 2016 20:44:48 -0300 Subject: [PATCH] longer posts support (>140 utf8 characters). fix #76. --- src/clientversion.h | 2 +- src/twister.cpp | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/clientversion.h b/src/clientversion.h index c444b8f1..04eb9e9f 100644 --- a/src/clientversion.h +++ b/src/clientversion.h @@ -8,7 +8,7 @@ // These need to be macros, as version.cpp's and bitcoin-qt.rc's voodoo requires it #define CLIENT_VERSION_MAJOR 0 #define CLIENT_VERSION_MINOR 9 -#define CLIENT_VERSION_REVISION 35 +#define CLIENT_VERSION_REVISION 36 #define CLIENT_VERSION_BUILD 0 // Set to true for release, false for prerelease or test build diff --git a/src/twister.cpp b/src/twister.cpp index 3d6360a9..bf2b9000 100644 --- a/src/twister.cpp +++ b/src/twister.cpp @@ -1660,8 +1660,30 @@ bool createSignedUserpost(entry &v, std::string const &username, int k, userpost["time"] = GetAdjustedTime(); userpost["height"] = getBestHeight() - 1; // be conservative - if( msg.size() ) { + int msgUtf8Chars = utf8::num_characters(msg.begin(), msg.end()); + if(msgUtf8Chars < 0) { + return false; // invalid utf8 + } else if (msgUtf8Chars && msgUtf8Chars <= 140) { userpost["msg"] = msg; + } else { + // break into msg and msg2 fields to overcome 140ch checks + string::const_iterator it = msg.begin(); + string::const_iterator end = msg.end(); + string msgOut, msg2Out; + int count = 0; + while (it!= end) { + string::const_iterator itPrev = it; + utf8::internal::utf_error err_code = utf8::internal::validate_next(it, end); + assert(err_code == utf8::internal::UTF8_OK); // string must have been validated already + count++; + if( count <= 140 ) { + msgOut.append(itPrev,it); + } else { + msg2Out.append(itPrev,it); + } + } + userpost["msg"] = msgOut; + userpost["msg2"] = msg2Out; } switch(flag)