Adding is_utf8 call and making enum_type cast explicit
This commit is contained in:
parent
0bf2f9cfd4
commit
93a789891e
4 changed files with 21 additions and 14 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#pragma once
|
||||
#include <unordered_map>
|
||||
#include <fc/fwd.hpp>
|
||||
#include <fc/io/raw_fwd.hpp>
|
||||
#include <fc/string.hpp>
|
||||
|
||||
namespace fc
|
||||
|
|
@ -24,7 +25,7 @@ class sha224
|
|||
static sha224 hash( const T& t )
|
||||
{
|
||||
sha224::encoder e;
|
||||
e << t;
|
||||
fc::raw::pack(e,t);
|
||||
return e.result();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,7 +17,7 @@ namespace fc
|
|||
|
||||
enum_type(){}
|
||||
|
||||
operator IntType()const { return static_cast<IntType>(value); }
|
||||
explicit operator IntType()const { return static_cast<IntType>(value); }
|
||||
operator EnumType()const { return value; }
|
||||
operator std::string()const { return fc::reflector<EnumType>::to_string(value); }
|
||||
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@
|
|||
namespace fc
|
||||
{
|
||||
|
||||
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.
|
||||
|
|
|
|||
28
src/utf8.cpp
28
src/utf8.cpp
|
|
@ -6,22 +6,26 @@
|
|||
|
||||
#include <assert.h>
|
||||
|
||||
namespace fc
|
||||
{
|
||||
namespace fc {
|
||||
|
||||
void decodeUtf8(const std::string& input, std::wstring* storage)
|
||||
{
|
||||
assert(storage != nullptr);
|
||||
bool is_utf8( const std::string& str )
|
||||
{
|
||||
return utf8::is_valid( str.begin(), str.end() );
|
||||
}
|
||||
|
||||
utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
|
||||
}
|
||||
void decodeUtf8(const std::string& input, std::wstring* storage)
|
||||
{
|
||||
assert(storage != nullptr);
|
||||
|
||||
void encodeUtf8(const std::wstring& input, std::string* storage)
|
||||
{
|
||||
assert(storage != nullptr);
|
||||
utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
|
||||
}
|
||||
|
||||
utf8::utf32to8(input.begin(), input.end(), std::back_inserter(*storage));
|
||||
}
|
||||
void encodeUtf8(const std::wstring& input, std::string* storage)
|
||||
{
|
||||
assert(storage != nullptr);
|
||||
|
||||
utf8::utf32to8(input.begin(), input.end(), std::back_inserter(*storage));
|
||||
}
|
||||
|
||||
} ///namespace fc
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue