Loading...
Searching...
No Matches
Utf8.h
Go to the documentation of this file.
1//
2// UTF-8 -> sf::String decoding.
3//
4
5#ifndef MALENA_UTF8_H
6#define MALENA_UTF8_H
7
9#include <string>
10
11namespace ml
12{
30 inline sf::String utf8(const std::string& s)
31 {
32 return sf::String::fromUtf8(s.begin(), s.end());
33 }
34
35 inline sf::String utf8(const char* s)
36 {
37 if (!s) return {};
38 const std::string t(s);
39 return sf::String::fromUtf8(t.begin(), t.end());
40 }
41
42 inline const sf::String& utf8(const sf::String& s) { return s; }
43
53 inline std::string toUtf8(const sf::String& s)
54 {
55 const auto bytes = s.toUtf8();
56 return std::string(bytes.begin(), bytes.end());
57 }
58}
59
60#endif //MALENA_UTF8_H
sf::U8String toUtf8() const
static String fromUtf8(T begin, T end)
Definition Animate.h:25
std::string toUtf8(const sf::String &s)
Encode an sf::String back to UTF-8 bytes.
Definition Utf8.h:53
sf::String utf8(const std::string &s)
Decode a UTF-8 byte string for display.
Definition Utf8.h:30