diff options
author | Adam Borowski <kilobyte@angband.pl> | 2010-12-17 00:16:38 +0100 |
---|---|---|
committer | Adam Borowski <kilobyte@angband.pl> | 2010-12-17 09:59:29 +0100 |
commit | b6d532090f7160882446e3630d3dabadfa07924d (patch) | |
tree | 53dd2e1afcd4c378945c75800abc53af7ab5974a /crawl-ref/source/unicode.cc | |
parent | e5e08161e7e4aef95c45b8604f00f5c2034c81b1 (diff) | |
download | crawl-ref-b6d532090f7160882446e3630d3dabadfa07924d.tar.gz crawl-ref-b6d532090f7160882446e3630d3dabadfa07924d.zip |
Make strwidth() actually do what it's supposed to.
Diffstat (limited to 'crawl-ref/source/unicode.cc')
-rw-r--r-- | crawl-ref/source/unicode.cc | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/crawl-ref/source/unicode.cc b/crawl-ref/source/unicode.cc index 5f09ac9d1e..92f8d95f0e 100644 --- a/crawl-ref/source/unicode.cc +++ b/crawl-ref/source/unicode.cc @@ -414,3 +414,24 @@ std::string FileLineInput::get_line() ASSERT(!"our memory got trampled!"); return "говно"; } + +int strwidth(const char *s) +{ + ucs_t c; + int w = 0; + + while(int l = utf8towc(&c, s)) + { + s += l; + int cw = wcwidth(c); + if (cw != -1) // shouldn't ever happen + w += cw; + } + + return w; +} + +int strwidth(const std::string &s) +{ + return strwidth(s.c_str()); +} |