diff options
author | Adam Borowski <kilobyte@angband.pl> | 2012-07-01 20:29:54 +0200 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2012-07-01 20:42:34 +0200 |
commit | 149bde4dfba07d3d13f531ac63c69d9c6af1989b (patch) | |
tree | d06799ce2515161691968c0b8b036484b3cd9473 | |
parent | 767e31263185364de0cf201098569a8c5fb34ff0 (diff) | |
download | crawl-ref-149bde4dfba07d3d13f531ac63c69d9c6af1989b.tar.gz crawl-ref-149bde4dfba07d3d13f531ac63c69d9c6af1989b.zip |
Don't use locale-dependent %ls.
While webtiles are not supported on Windows, and no sane Unix uses encodings
other than UTF-8, we can have local webtiles some day.
-rw-r--r-- | crawl-ref/source/tileweb-text.cc | 3 | ||||
-rw-r--r-- | crawl-ref/source/unicode.cc | 17 | ||||
-rw-r--r-- | crawl-ref/source/unicode.h | 4 |
3 files changed, 23 insertions, 1 deletions
diff --git a/crawl-ref/source/tileweb-text.cc b/crawl-ref/source/tileweb-text.cc index 7c04bebc9c..c17ebac555 100644 --- a/crawl-ref/source/tileweb-text.cc +++ b/crawl-ref/source/tileweb-text.cc @@ -3,6 +3,7 @@ #include "tileweb-text.h" #include "tileweb.h" +#include "unicode.h" #include <sstream> @@ -178,7 +179,7 @@ void WebTextArea::send(bool force) sending = true; } - tiles.write_message("%u:\"%ls\",", y, html.str().c_str()); + tiles.write_message("%u:\"%s\",", y, wcstoutf8(html.str()).c_str()); } } if (sending) diff --git a/crawl-ref/source/unicode.cc b/crawl-ref/source/unicode.cc index 1d83f65edd..aa6773ba21 100644 --- a/crawl-ref/source/unicode.cc +++ b/crawl-ref/source/unicode.cc @@ -233,6 +233,23 @@ static std::string utf8_validate(const char *s) return d; } +#ifdef USE_TILE_WEB +std::string wcstoutf8(const std::wstring &s) +{ + std::string out; + + for (size_t j = 0; j < s.length(); j++) + { + char buf[4]; + int r = wctoutf8(buf, s[j]); + for (int i = 0; i < r; j++) + out.push_back(buf[i]); + } + + return out; +} +#endif + static bool _check_trail(FILE *f, const char* bytes, int len) { while (len--) diff --git a/crawl-ref/source/unicode.h b/crawl-ref/source/unicode.h index f0d8c930c7..8ac74a6894 100644 --- a/crawl-ref/source/unicode.h +++ b/crawl-ref/source/unicode.h @@ -45,6 +45,10 @@ char *next_glyph(char *s); #define OUTS(x) utf8_to_mb(x).c_str() #define OUTW(x) utf8_to_16(x).c_str() +#ifdef USE_TILE_WEB +std::string wcstoutf8(const std::wstring &s); +#endif + class LineInput { public: |