summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaweł Redman <pawel.redman@gmail.com>2017-12-14 18:05:51 +0100
committerPaweł Redman <pawel.redman@gmail.com>2017-12-14 18:05:51 +0100
commit5835b156f57ec4778521c013f813d1223c7fd2f6 (patch)
tree1e5fe9fc7411743988790244689848bd3073a05d /src
parent0e27aac4f124efcd495469522706df8cc1ca5986 (diff)
Avoid reinventing UTF-8.
Diffstat (limited to 'src')
-rw-r--r--src/common.hpp2
-rw-r--r--src/main.cpp24
-rw-r--r--src/render.cpp4
3 files changed, 1 insertions, 29 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 38f8993..54f9804 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -14,8 +14,6 @@ extern bool debug_draw_cmodels;
extern bool debug_draw_paths;
extern bool debug_draw_tile_coords;
-void utf8_to_wchar(wchar_t *out, size_t size, std::string in);
-
namespace procgen {
class prng_t {
uint32_t state = 0;
diff --git a/src/main.cpp b/src/main.cpp
index f5e7a19..e503cad 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -14,30 +14,6 @@ uint64_t nano_clock(void)
return ts.tv_sec * 1000000000LLU + ts.tv_nsec;
}
-void utf8_to_wchar(wchar_t *out, size_t size, std::string in)
-{
- wchar_t *d = out, *end = out + size;
-
- for (size_t i = 0; i < in.size(); i++) {
- if (d + 1 >= end)
- break;
-
- if ((in[i] & 128) == 0)
- *(d++) = in[i];
- else {
- if (i + 1 >= in.size()) {
- printf("invalid UTF-8 sequence\n");
- abort();
- }
-
- *(d++) = ((in[i] & 31) << 6) | (in[i + 1] & 63);
- i++;
- }
- }
-
- *(d++) = 0;
-}
-
int main()
{
uint64_t t0 = nano_clock();
diff --git a/src/render.cpp b/src/render.cpp
index c4718bf..d852b24 100644
--- a/src/render.cpp
+++ b/src/render.cpp
@@ -185,9 +185,7 @@ void state_t::render(oriented_sprite_t *sprite, rectf_t bounds, float angle)
void state_t::render_text(v2f_t x, float height, std::string str,
text_align_t align, sf::Color color)
{
- wchar_t buffer[4096];
- utf8_to_wchar(buffer, sizeof(buffer) / sizeof(wchar_t), str);
- sf::Text text(buffer, font, 40);
+ sf::Text text(sf::String::fromUtf8(str.begin(), str.end()), font, 40);
sf::FloatRect rect;
float scale;
v2f_t offset;