summaryrefslogtreecommitdiffstats
path: root/crawl-ref/source/unicode.cc
diff options
context:
space:
mode:
authorAdam Borowski <kilobyte@angband.pl>2010-12-17 00:16:38 +0100
committerAdam Borowski <kilobyte@angband.pl>2010-12-17 09:59:29 +0100
commitb6d532090f7160882446e3630d3dabadfa07924d (patch)
tree53dd2e1afcd4c378945c75800abc53af7ab5974a /crawl-ref/source/unicode.cc
parente5e08161e7e4aef95c45b8604f00f5c2034c81b1 (diff)
downloadcrawl-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.cc21
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());
+}