2014-01-09 23:01:47 +00:00
|
|
|
#include "fc/utf8.hpp"
|
|
|
|
|
|
|
|
|
|
#include "utf8/checked.h"
|
|
|
|
|
#include "utf8/core.h"
|
|
|
|
|
#include "utf8/unchecked.h"
|
|
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
2015-02-17 14:55:31 +00:00
|
|
|
namespace fc {
|
2014-01-09 23:01:47 +00:00
|
|
|
|
2015-02-17 14:55:31 +00:00
|
|
|
bool is_utf8( const std::string& str )
|
|
|
|
|
{
|
|
|
|
|
return utf8::is_valid( str.begin(), str.end() );
|
|
|
|
|
}
|
2014-01-09 23:01:47 +00:00
|
|
|
|
2015-02-17 14:55:31 +00:00
|
|
|
void decodeUtf8(const std::string& input, std::wstring* storage)
|
|
|
|
|
{
|
|
|
|
|
assert(storage != nullptr);
|
2014-01-09 23:01:47 +00:00
|
|
|
|
2015-02-17 14:55:31 +00:00
|
|
|
utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
|
|
|
|
|
}
|
2014-01-09 23:01:47 +00:00
|
|
|
|
2015-02-17 14:55:31 +00:00
|
|
|
void encodeUtf8(const std::wstring& input, std::string* storage)
|
|
|
|
|
{
|
|
|
|
|
assert(storage != nullptr);
|
|
|
|
|
|
|
|
|
|
utf8::utf32to8(input.begin(), input.end(), std::back_inserter(*storage));
|
|
|
|
|
}
|
2014-01-09 23:01:47 +00:00
|
|
|
|
|
|
|
|
} ///namespace fc
|
|
|
|
|
|
|
|
|
|
|