Sync develop with master #4

Merged
RoshanSyed merged 144 commits from master into develop 2019-12-16 15:20:56 +00:00
3 changed files with 35 additions and 13 deletions
Showing only changes of commit 2bc237537c - Show all commits

View file

@ -8,19 +8,21 @@
namespace fc namespace fc
{ {
bool is_utf8( const std::string& str ); std::string prune_invalid_utf8( const std::string& str );
/** Decodes utf 8 std::string into unicode string. bool is_utf8( const std::string& str );
@param input - input string to be decoded and stored in 'storage'
@param storage - buffer for converted text. Cannot be nullptr. /** Decodes utf 8 std::string into unicode string.
*/ @param input - input string to be decoded and stored in 'storage'
void decodeUtf8(const std::string& input, std::wstring* storage); @param storage - buffer for converted text. Cannot be nullptr.
*/
/** Encodes given wide (unicode) string into UTF-8 representation. void decodeUtf8(const std::string& input, std::wstring* storage);
@param input - input string to be encoded and stored in 'storage'
@param storage - buffer for converted text. Cannot be nullptr. /** Encodes given wide (unicode) string into UTF-8 representation.
*/ @param input - input string to be encoded and stored in 'storage'
void encodeUtf8(const std::wstring& input, std::string* storage); @param storage - buffer for converted text. Cannot be nullptr.
*/
void encodeUtf8(const std::wstring& input, std::string* storage);
} /// namespace fc } /// namespace fc

View file

@ -3,16 +3,36 @@
#include "utf8/checked.h" #include "utf8/checked.h"
#include "utf8/core.h" #include "utf8/core.h"
#include "utf8/unchecked.h" #include "utf8/unchecked.h"
#include <websocketpp/utf8_validator.hpp>
#include <assert.h> #include <assert.h>
#include <fc/log/logger.hpp>
#include <iostream>
namespace fc { namespace fc {
bool is_utf8( const std::string& str ) bool is_utf8( const std::string& str )
{ {
auto itr = utf8::find_invalid(str.begin(), str.end());
return utf8::is_valid( str.begin(), str.end() ); return utf8::is_valid( str.begin(), str.end() );
} }
string prune_invalid_utf8( const string& str ) {
string result;
auto itr = utf8::find_invalid(str.begin(), str.end());
if( itr == str.end() ) return str;
result = string( str.begin(), itr );
while( itr != str.end() ) {
++itr;
auto start = itr;
itr = utf8::find_invalid( start, str.end());
result += string( start, itr );
}
return result;
}
void decodeUtf8(const std::string& input, std::wstring* storage) void decodeUtf8(const std::string& input, std::wstring* storage)
{ {
assert(storage != nullptr); assert(storage != nullptr);

2
vendor/websocketpp vendored

@ -1 +1 @@
Subproject commit c5510d6de04917812b910a8dd44735c1f17061d9 Subproject commit 378437aecdcb1dfe62096ffd5d944bf1f640ccc3