BitShares-Core  7.0.2
BitShares blockchain node software and command-line wallet software
utf8.cpp
Go to the documentation of this file.
1 #include "fc/utf8.hpp"
2 
3 #include "utf8/checked.h"
4 #include "utf8/core.h"
5 #include "utf8/unchecked.h"
6 #include <websocketpp/utf8_validator.hpp>
7 
8 #include <assert.h>
9 #include <fc/log/logger.hpp>
10 #include <iostream>
11 
12 namespace fc {
13 
14  bool is_utf8( const std::string& str )
15  {
16  return utf8::is_valid( str.begin(), str.end() );
17  }
18 
19  string prune_invalid_utf8( const string& str ) {
20  string result;
21 
22  auto itr = utf8::find_invalid(str.begin(), str.end());
23  if( itr == str.end() ) return str;
24 
25  result = string( str.begin(), itr );
26  while( itr != str.end() ) {
27  ++itr;
28  auto start = itr;
29  itr = utf8::find_invalid( start, str.end());
30  result += string( start, itr );
31  }
32  return result;
33  }
34 
35  void decodeUtf8(const std::string& input, std::wstring* storage)
36  {
37  assert(storage != nullptr);
38 
39  utf8::utf8to32(input.begin(), input.end(), std::back_inserter(*storage));
40  }
41 
42  void encodeUtf8(const std::wstring& input, std::string* storage)
43  {
44  assert(storage != nullptr);
45 
46  utf8::utf32to8(input.begin(), input.end(), std::back_inserter(*storage));
47  }
48 
49 }
50 
51 
utf8.hpp
fc
Definition: api.hpp:15
fc::decodeUtf8
void decodeUtf8(const std::string &input, std::wstring *storage)
Definition: utf8.cpp:35
fc::prune_invalid_utf8
std::string prune_invalid_utf8(const std::string &str)
logger.hpp
fc::encodeUtf8
void encodeUtf8(const std::wstring &input, std::string *storage)
Definition: utf8.cpp:42
fc::is_utf8
bool is_utf8(const std::string &str)
Definition: utf8.cpp:14