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
|
#pragma once
|
||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <fc/fwd.hpp>
|
#include <fc/fwd.hpp>
|
||||||
|
#include <fc/io/raw_fwd.hpp>
|
||||||
#include <fc/string.hpp>
|
#include <fc/string.hpp>
|
||||||
|
|
||||||
namespace fc
|
namespace fc
|
||||||
|
|
@ -24,7 +25,7 @@ class sha224
|
||||||
static sha224 hash( const T& t )
|
static sha224 hash( const T& t )
|
||||||
{
|
{
|
||||||
sha224::encoder e;
|
sha224::encoder e;
|
||||||
e << t;
|
fc::raw::pack(e,t);
|
||||||
return e.result();
|
return e.result();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -17,7 +17,7 @@ namespace fc
|
||||||
|
|
||||||
enum_type(){}
|
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 EnumType()const { return value; }
|
||||||
operator std::string()const { return fc::reflector<EnumType>::to_string(value); }
|
operator std::string()const { return fc::reflector<EnumType>::to_string(value); }
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,8 @@
|
||||||
namespace fc
|
namespace fc
|
||||||
{
|
{
|
||||||
|
|
||||||
|
bool is_utf8( const std::string& str );
|
||||||
|
|
||||||
/** Decodes utf 8 std::string into unicode string.
|
/** Decodes utf 8 std::string into unicode string.
|
||||||
@param input - input string to be decoded and stored in 'storage'
|
@param input - input string to be decoded and stored in 'storage'
|
||||||
@param storage - buffer for converted text. Cannot be nullptr.
|
@param storage - buffer for converted text. Cannot be nullptr.
|
||||||
|
|
|
||||||
12
src/utf8.cpp
12
src/utf8.cpp
|
|
@ -6,17 +6,21 @@
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
namespace fc
|
namespace fc {
|
||||||
{
|
|
||||||
|
|
||||||
void decodeUtf8(const std::string& input, std::wstring* storage)
|
bool is_utf8( const std::string& str )
|
||||||
|
{
|
||||||
|
return utf8::is_valid( str.begin(), str.end() );
|
||||||
|
}
|
||||||
|
|
||||||
|
void decodeUtf8(const std::string& input, std::wstring* storage)
|
||||||
{
|
{
|
||||||
assert(storage != nullptr);
|
assert(storage != nullptr);
|
||||||
|
|
||||||
utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
|
utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
|
||||||
}
|
}
|
||||||
|
|
||||||
void encodeUtf8(const std::wstring& input, std::string* storage)
|
void encodeUtf8(const std::wstring& input, std::string* storage)
|
||||||
{
|
{
|
||||||
assert(storage != nullptr);
|
assert(storage != nullptr);
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue