Skip to content

Commit

Permalink
Merge pull request steemit#67 from arhag/mingw-build-fix
Browse files Browse the repository at this point in the history
Quick but inelegant fix for UTF8 patch bugs.  You read my mind in how I was going to hack it.
  • Loading branch information
bytemaster committed May 25, 2016
2 parents 349d4bd + 88297e5 commit e8d3937
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions libraries/chain/steem_evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@

#ifndef IS_LOW_MEM
#include <diff_match_patch.h>
#include <boost/locale/encoding_utf.hpp>

using boost::locale::conv::utf_to_utf;

std::wstring utf8_to_wstring(const std::string& str)
{
return utf_to_utf<wchar_t>(str.c_str(), str.c_str() + str.size());
}

std::string wstring_to_utf8(const std::wstring& str)
{
return utf_to_utf<char>(str.c_str(), str.c_str() + str.size());
}

#endif

#include <fc/uint128.hpp>
Expand Down Expand Up @@ -271,14 +285,15 @@ void comment_evaluator::do_apply( const comment_operation& o )

if( o.body.size() ) {
try {
diff_match_patch<string> dmp;
auto patch = dmp.patch_fromText( o.body );
diff_match_patch<std::wstring> dmp;
auto patch = dmp.patch_fromText( utf8_to_wstring(o.body) );
if( patch.size() ) {
auto result = dmp.patch_apply( patch, com.body );
if( !fc::is_utf8( result.first ) ) {
idump(("invalid utf8")(result.first));
com.body = fc::prune_invalid_utf8(result.first);
} else { com.body = result.first; }
auto result = dmp.patch_apply( patch, utf8_to_wstring(com.body) );
auto patched_body = wstring_to_utf8(result.first);
if( !fc::is_utf8( patched_body ) ) {
idump(("invalid utf8")(patched_body));
com.body = fc::prune_invalid_utf8(patched_body);
} else { com.body = patched_body; }
}
else { // replace
com.body = o.body;
Expand Down

0 comments on commit e8d3937

Please sign in to comment.