From 2bc237537cb3890b980fae811bd21493761f430a Mon Sep 17 00:00:00 2001 From: Daniel Larimer Date: Tue, 24 May 2016 19:24:03 -0400 Subject: [PATCH] updating websocket and adding new utf8 code --- include/fc/utf8.hpp | 26 ++++++++++++++------------ src/utf8.cpp | 20 ++++++++++++++++++++ vendor/websocketpp | 2 +- 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/include/fc/utf8.hpp b/include/fc/utf8.hpp index 3af2abe..c573029 100644 --- a/include/fc/utf8.hpp +++ b/include/fc/utf8.hpp @@ -8,19 +8,21 @@ 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. - @param input - input string to be decoded and stored in 'storage' - @param storage - buffer for converted text. Cannot be nullptr. -*/ -void decodeUtf8(const std::string& input, std::wstring* storage); - -/** Encodes given wide (unicode) string into UTF-8 representation. - @param input - input string to be encoded and stored in 'storage' - @param storage - buffer for converted text. Cannot be nullptr. -*/ -void encodeUtf8(const std::wstring& input, std::string* storage); + bool is_utf8( const std::string& str ); + + /** Decodes utf 8 std::string into unicode string. + @param input - input string to be decoded and stored in 'storage' + @param storage - buffer for converted text. Cannot be nullptr. + */ + void decodeUtf8(const std::string& input, std::wstring* storage); + + /** Encodes given wide (unicode) string into UTF-8 representation. + @param input - input string to be encoded and stored in 'storage' + @param storage - buffer for converted text. Cannot be nullptr. + */ + void encodeUtf8(const std::wstring& input, std::string* storage); } /// namespace fc diff --git a/src/utf8.cpp b/src/utf8.cpp index 0bab5e0..14551c4 100644 --- a/src/utf8.cpp +++ b/src/utf8.cpp @@ -3,16 +3,36 @@ #include "utf8/checked.h" #include "utf8/core.h" #include "utf8/unchecked.h" +#include #include +#include +#include namespace fc { bool is_utf8( const std::string& str ) { + auto itr = utf8::find_invalid(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) { assert(storage != nullptr); diff --git a/vendor/websocketpp b/vendor/websocketpp index c5510d6..378437a 160000 --- a/vendor/websocketpp +++ b/vendor/websocketpp @@ -1 +1 @@ -Subproject commit c5510d6de04917812b910a8dd44735c1f17061d9 +Subproject commit 378437aecdcb1dfe62096ffd5d944bf1f640ccc3